This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fwd: Re: [Help] Segmentation Fault


From gfortran.org help list. No segfault if I remove the omp stuff. I don't use omp and have to leave early this morning, so I have not had time to investigate this further.

-------- Original Message --------
Subject: Re: [Help] Segmentation Fault
Date: Wed, 12 Jan 2011 13:51:32 +0100
From: Daniel Carrera <dcarrera@gmail.com>
To: Juancarlo Añez <apalala@gmail.com>
CC: help@gfortran.org

I have produced a new program that also produces a segmentation fault,
and this one doesn't require more than 2MB to run. But it uses OpenMP.
The program is below. You compile it with "gfortran -fopenmp".

--------------------%<--------------------
program openMP_example
    use omp_lib

implicit none

    integer, parameter :: N = 2000
    integer :: id, nthreads, i, j = 0
    real :: A(N,N), B(N,N), C(N,N) = -1


! ! Random matrices. ! call seed_prng() call random_number(A) call random_number(B)

!$omp parallel private(id)

    id = omp_get_thread_num()
    !$omp barrier

nthreads = omp_get_num_threads()

    do while(j < N)
        j = j+1
        !print *,"id,j = ",id,j
        C(j,:) = MATMUL(A,B(j,:))
    end do


!$omp end parallel


    !
    !  Print result.
    !
    i = 1 + floor(A(1,1)*N)
    j = 1 + floor(A(2,2)*N)
    print *,C(i,j)


contains


    subroutine seed_prng()
        implicit none

        ! Internal variables
        integer :: i = 0, n, clock
        integer, dimension(:), allocatable :: seed

        ! Seed the PRNG
        call random_seed(size = n)
        allocate(seed(n))

        call system_clock(count=clock)
        seed = clock + 37 * (/ (i-1, i = 1,n) /)

        call random_seed(put = seed)
        deallocate(seed)
    end subroutine
end program
--------------------%<--------------------

Daniel.
--
Writing software to spec is like walking on water... It's easy as long
as it's frozen.
_______________________________________________
Help mailing list
Help@gfortran.org
http://gfortran.org/mailman/listinfo/help


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]