[Omp] Private variables in F90 modules
Bertrand MELTZ
meltz at ocre.cea.fr
Mon Dec 18 13:24:24 PST 2006
Hi everybody,
I have a bug in a large, and classified, program.
This bug is resisting all my attempts to solve it, even with the
help of all 3 debuggers I tried ( TotalView, DDT, and "print *").
I tried to make a reproducer. Sure enough, the reproducer works
just fine.
The problem is this : I have a parallel loop, in which I call a
subroutine, which calls another subroutine, and so on. Of course,
I Have to be very careful with shared and private arrays.
But the problem seems to lie with the thread number, which I
want to put in a Fortran module, essentially to avoid carrying
a long list of arguments.
It seems the value of this "thread" variable gets lost along
the chain of routine calls. Deep down, it ends up being 0.
I wonder whether it is even OK ("legal") to put a private variable
in a module?
I am using ifort 9.1 on a variety of Intel boxes (both IA32 and
IA64).
Here is my "reproducer", which actually reproduces nothing.
If anybody could point to something wrong, it would be of great help.
Bertrand
-----------------------------
module mod_B
integer, pointer :: thread
end module mod_B
module mod_A
use mod_B
integer, pointer, dimension( :) :: pointer_to_dummy, pointer_to_autom
contains
subroutine sub_A( line, dummy_A)
integer line
integer, target, dimension( :) :: dummy_A
integer, target, dimension( size( dummy_A) ) :: autom_B
!----------------------------------------------------------------------!
pointer_to_dummy => dummy_A
pointer_to_autom => autom_B
call sub_B( line)
end subroutine sub_A
subroutine sub_B( line)
integer line, j
!----------------------------------------------------------------------!
do j=1, size( pointer_to_autom)
pointer_to_autom( j) = j * line + thread
end do
pointer_to_dummy = pointer_to_dummy + pointer_to_autom
end subroutine sub_B
end module mod_A
program vars_in_module
use mod_A
use mod_B
implicit none
integer, target :: thr
integer :: nb_threads, i, j, nfois = 200
!& lastprivate ( nb_threads)
integer, parameter :: line_size = 3, nb_lines = 5
integer, allocatable, dimension( :, :, :) :: Array
!$ integer, external :: OMP_GET_NUM_THREADS
!$ integer, external :: OMP_GET_THREAD_NUM
!----------------------------------------------------------------------!
nb_threads = 1
!$ nb_threads = 2
!$ call OMP_SET_NUM_THREADS( nb_threads)
!$OMP PARALLEL SHARED( nb_threads)
!$ nb_threads = OMP_GET_NUM_THREADS()
!$OMP END PARALLEL
print *, ' nb threads ', nb_threads
ALLOCATE( Array( line_size, 0:nb_threads-1, nb_lines) )
Array = 0
!$ Array( :, nb_threads-1, :) = 1
thr = 0
thread => thr
do j = 1, nfois
!$OMP PARALLEL DO DEFAULT( SHARED), &
!$OMP PRIVATE( i, thr)
do i = 1, nb_lines
!$ thr = OMP_GET_THREAD_NUM()
thread => thr
call sub_A( i, Array( :, thread, i) )
end do
!$OMP END PARALLEL DO
end do
print *, Array
end program vars_in_module
--------------------------
Bertrand Meltz
Commissariat a l'Energie Atomique | e-mail : bertrand.meltz at cea.fr
CEA / DIF , BP 12 | Tel : (33) [0] 1 69 26 57 83
91680 Bruyeres-le-Chatel , FRANCE | Fax : (33) [0] 1 69 26 70 93
More information about the Omp
mailing list