[Omp] Clarification of the Fortran OpenMP 2.0 specs about FLUSH directive is needed

Marina Kraeva kraeva at iastate.edu
Tue Aug 1 11:27:38 PDT 2006


Larry,

Thanks for your answer. I still have (same) questions though. Reading 
specs 2.5 didn't clarify this "thread-visibility by taking address" 
issue - I actually didn't find any such discussion in the latest specs.

Please take a look at the example below. The local variable 'a' declared 
in the subroutine 'sub1' is private by default. I pass it to the 
function 'func'. Did I "hand around a pointer to it" by doing this? The 
dummy argument 'tmp' in function 'func' is now argument associated with 
the variable 'a'. According to your words the variable 'a' should be 
thread-visible now? In other words it should be shared and not private?

I ran this code on two different platforms, and on both platforms 'a' is 
still private. Either those implementations are wrong (that I doubt) or 
the example below doesn't demonstrate the words about "Local variables 
that have had their address taken and saved or have had their address 
passed to another subprogram" being thread-visible? Could someone please 
'fix' the example below or provide a new example that really 
demonstrates these words. Thanks in advance!

Marina.

P.S. Here is the example:

       use omp_lib
       implicit none
       integer, parameter :: NT = 4        !default number of threads
       integer :: rct1,rct2, ant

!$    call omp_set_dynamic(.false.)
!$    call omp_set_num_threads(NT)

       rct1=-1
       rct2=-1
!$omp parallel
       call sub1(rct1,rct2)
       ant=omp_get_num_threads()
!$omp end parallel

       print *,'the actual number of threads=',ant,'should be',NT
       print *,'rct1 = ',rct1,' expect -1'
       print *,'rct2 = ',rct2,' expect 6'
       if(rct1 /= -1) then
          print*, 'FAIL: variable a that has had its address passed to 
func is not thread-visible.'
       endif

       END

       SUBROUTINE sub1(rct1,rct2)
       use omp_lib
       implicit none
           integer :: a,b
           integer rct1,rct2
           integer func

           b=0
           if(omp_get_thread_num() == 0) then
               a = 5
               b = func(a)
               a = a + 1
           endif

!$omp barrier

           if(a /= 6) then
!$omp atomic
               rct1 = rct1 + 1
           endif

!$omp atomic
           rct2 = rct2 + b

       END SUBROUTINE sub1

       FUNCTION func(tmp)
           integer :: func
           integer :: tmp
           func = tmp + 2
       END FUNCTION func


Meadows, Lawrence F wrote:

> Marina:
> 
> The intent of all of this is clear, if you hand around a pointer
> to something then it is visible to other threads. In standard
> Fortran this can happen through argument association or using
> the POINTER attribute. In extended Fortran and in Fortran 2004
> there are other ways to do this. If you think of it as C, then
> you'll understand the intent.
> 
> However, I suggest that you read the 2.5 specification. The intent
> of 2.5 was not to change semantics, but to clarify, and I believe
> that most of your questions are answered in 2.5.
> 
> Of course, I could be wrong, in which case please ask again.
> 
> Regards,
> 
> Larry Meadows 
> 
> 
>>-----Original Message-----
>>From: omp-bounces at openmp.org [mailto:omp-bounces at openmp.org] 
>>On Behalf Of Marina Kraeva
>>Sent: Monday, July 31, 2006 1:39 PM
>>To: Omp at openmp.org
>>Subject: [Omp] Clarification of the Fortran OpenMP 2.0 specs 
>>about FLUSH directive is needed
>>
>>Hello,
>>
>>I have several questions about thread-visible variables and FLUSH 
>>directive. In the Fortran OpenMP API 2.0 specs it's said that "Local 
>>variables that have had their address taken and saved or have 
>>had their 
>>address passed to another subprogram" are thread-visible.
>>
>>The first question is how one can take and save the address of 
>>a variable.
>>
>>The second question is whether I understand it right that the 
>>thread-visible variables are shared variables and "global-lifetime 
>>memory locations". I did not find any mention of thread-visible 
>>variables in the OpenMP API 2.5 specs other than in the following 
>>sentence: "A flush construct without a list, executed on a 
>>given thread, 
>>operates as if the whole thread-visible data state of the program, as 
>>defined by the base language, is flushed."
>>
>>The last question is about passing address of a local variable to 
>>another subprogram (see the quote from the specs 2.0 above). Does it 
>>mean that in case a local variable was passed into another subprogram 
>>(and in Fortran all variables are passed by address), this variable is 
>>considered thread-visible? Can anyone provide an example for 
>>that quote?
>>
>>Or should I disregard everything in the specs 2.0 as there is 
>>new specs?
>>
>>Thank you in advance,
>>Marina Kraeva.
>>
>>
>>_______________________________________________
>>Omp mailing list
>>Omp at openmp.org
>>http://openmp.org/mailman/listinfo/omp
>>
> 
> 
> 


More information about the Omp mailing list