Glad I found you, and hope my questions won't be too trivial.
I'm in the process of rewriting a highly specialized raytracer from F77 into F95 (GNU-Fortran). The first bits of code are working nicely serially, and I thought it might be a good idea to start implementing parallelization "quickly". That was 2 weeks ago, and by now I've run out of ideas of what else to check.
Quick description of the program's structure:
So far, there are 3 modules. One contains the main program, one contains globally defined veriables, and the 3rd one some subroutines. Both main program and subroutines have access to the global veriables, and the subroutines are called from the main program.
Problem:
Arrays defined as "global" apparently can't be accessed from the subroutines (in the seperate module file). Whenever the array is referenced in one of these subroutines, the value returned equals the last one active in the preceeding serial section.
Also, the globally defined thread ID always returns nul when referenced in one of the subroutines.
I give a highly condensed (but executable) version of the program and all it's bits in the following.
The main program:
- Code: Select all
program ex_tcomf
use omp_lib
use global_def
use ex_raytrace
implicit none
integer :: ibeam
call define_beams
!$omp parallel default(firstprivate) shared(beam_array)
!$ thread_id=omp_get_thread_num()
!$omp do
do ibeam=1,nbeams,1
!$omp critical
beam=beam_array(ibeam,:)
write(*,*) 'thread',thread_id,' main: ',beam
call check_beams
!$omp end critical
end do
!$omp end do
!$omp end parallel
end program ex_tcomf
The module with global definitions:
- Code: Select all
module global_def
implicit none
integer :: nbeams,thread_id=0
real,dimension(:,:),allocatable :: beam_array
real,dimension(1) :: beam
end module global_def
The module with some subroutines:
- Code: Select all
module ex_raytrace
use global_def
implicit none
contains
! ##################################################################
subroutine define_beams
implicit none
integer :: ibeam
nbeams=12
allocate(beam_array(nbeams,1))
beam_array=0.0
do ibeam=1,nbeams,1
beam(1)=real(ibeam)
beam_array(ibeam,:)=beam
end do
end subroutine define_beams
! ##################################################################
subroutine check_beams
implicit none
write(*,*) 'thread',thread_id,' subr: ',beam
write(*,*)
end subroutine check_beams
end module ex_raytrace
And here the output withg nbeams=12
- Code: Select all
thread 1 main: 4.0000000000000000
thread 0 subr: 12.000000000000000
thread 1 main: 5.0000000000000000
thread 0 subr: 12.000000000000000
thread 1 main: 6.0000000000000000
thread 0 subr: 12.000000000000000
thread 3 main: 10.000000000000000
thread 0 subr: 12.000000000000000
thread 3 main: 11.000000000000000
thread 0 subr: 12.000000000000000
thread 3 main: 12.000000000000000
thread 0 subr: 12.000000000000000
thread 0 main: 1.0000000000000000
thread 0 subr: 12.000000000000000
thread 0 main: 2.0000000000000000
thread 0 subr: 12.000000000000000
thread 0 main: 3.0000000000000000
thread 0 subr: 12.000000000000000
thread 2 main: 7.0000000000000000
thread 0 subr: 12.000000000000000
thread 2 main: 8.0000000000000000
thread 0 subr: 12.000000000000000
thread 2 main: 9.0000000000000000
thread 0 subr: 12.000000000000000
again, I do hope this is nott a question too silly. If it is, well, here I go.
Thanks for any hits,
Hein61
