How to propagate threadprivate-ness?

General OpenMP discussion

How to propagate threadprivate-ness?

Postby bjam » Mon Aug 18, 2008 11:01 am

I define a threadprivate variable in a module.
But its threadprivate nature does not get propagated through the chain
of subroutines (all inside a parallel region).
What did I do wrong?

Compiled with : ifort -openmp -g
I have the same problem with gfortran

Thanks

!**********************************************************************!
module th
integer thread
!OMP THREADPRIVATE( thread)
end module th
!**********************************************************************!
!**********************************************************************!
module mod_B
use th
contains

subroutine sub_B( line )
implicit none
integer line
!$ integer, external :: OMP_GET_THREAD_NUM
!----------------------------------------------------------------------!
!$ print *, " sub_B end", line, thread, OMP_GET_THREAD_NUM()

end subroutine sub_B

end module mod_B
!**********************************************************************!
!**********************************************************************!
module mod_A
use th
use mod_B
contains

subroutine sub_A( line)
implicit none
integer line
!$ integer, external :: OMP_GET_THREAD_NUM
!----------------------------------------------------------------------!
!$ print *, " sub_A beg", line, thread, OMP_GET_THREAD_NUM()
call sub_B( line)
!$ print *, " sub_A end", line, thread, OMP_GET_THREAD_NUM()
end subroutine sub_A

end module mod_A
!**********************************************************************!
!**********************************************************************!
program vars_in_module

use th
use mod_A
implicit none
integer nb_threads, i
! !& lastprivate ( nb_threads)
integer, parameter :: line_size = 3, nb_lines = 5
!$ 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

thread = 7
print *, ' nb threads ', nb_threads, thread
!$OMP PARALLEL DO DEFAULT( SHARED), &
!$OMP PRIVATE( i, thread)
do i = 1, nb_lines
!$ thread = OMP_GET_THREAD_NUM()
print *, " MAIN beg ", i, thread, OMP_GET_THREAD_NUM()
call sub_A( i)
print *, " MAIN end ", i, thread, OMP_GET_THREAD_NUM()
end do
!$OMP END PARALLEL DO

end program vars_in_module
bjam
 
Posts: 2
Joined: Fri Aug 15, 2008 8:36 am

Re: How to propagate threadprivate-ness?

Postby ejd » Tue Aug 19, 2008 7:38 am

Your question is about threadprivate. However, your source program doesn't have a threadprivate in it. If you look at module th, you have specified "!OMP" rather than "!$OMP", so there is no threadprivate directive. Instead, you have a "private(thread)" on your parallel do directive. Try removing the "private(thread)" and fixing the threadprivate directive and see if it works. If you are still having problems after that, post again. I will be gone for the next couple of weeks, but hopefully someone else can help you.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: How to propagate threadprivate-ness?

Postby bjam » Thu Aug 21, 2008 1:12 am

I knew $ were important!
You know how it is : you have a nasty bug, you try to put together a reproducer, and you put in it another bug, that looks pretty much like the original one, so you don't know who is who.
Thanks for pointing me this missing $. I have already narrowed the original bug, which was with threadprivate pointers pointing to shared arrays.

BJ
bjam
 
Posts: 2
Joined: Fri Aug 15, 2008 8:36 am


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 8 guests