[Users] Fortran OpenMP parallel do

Roland Haas roland.haas at physics.gatech.edu
Wed Oct 30 15:49:02 CDT 2013


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello all,

> On Wed, Oct 30, 2013 at 08:54:08AM -0400, Yosef Zlochower wrote:
>> I though that for C code, the (outermost) loop index was
>> automatically private. Has this changed in the openmp standard?
Philipp and I did some more reading of the OpenMP specs
(http://www.openmp.org/mp-documents/spec30.pdf‎) and while we could
not find a helpful definition of "associated loops" (since those are
the ones whose controlling variables are automatically private in
FOTRAN) we *did* find an example in the specs that does exactly what
we do. Example A.7.1f (on page 168) has:
$OMP DO
     DO 300 I = 1,10
       DO 300 J = 1,10
         CALL WORK(I,J)
300  CONTINUE
!$OMP ENDDO
which would indicate that that *both* nested loops are seen as one and
that both i and j are private. Note that the 2.0 specs (which have no
COLLAPSE yet) also speak of do_loops and inner and outer loops so this
all points towards the standard requiring that all nested loops in
FORTRAN have private loop variables.

HOWEVER we certainly should NOT do this in C since no such guarantee
is given there and I believe we SHOULD do as Erik suggested and
explicitly declare all loop control variables as private (in FORTRAN)
since the standard is confusing and possibly misleading. Appendix A.8
of the specs give more information on this.

> Having said that, assume a construct like:
> 
> #pragma omp parallel for for (int i=0; i<N; i++) { }
> 
> Can you here actually specify private(i)? 'i' isn't even declared
> at the point of the pragma yet.
This is fine and actually the recommended method since it declares "i"
inside of the parallel region so it is automatically private. It is
(up to the lifetime of "i" after the loop ends) the same as:
#pragma omp parallel for
{
int i;
for (i=0; i<N; i++)
{
}
}

Yours,
Roland

- -- 
My email is as private as my paper mail. I therefore support encrypting
and signing email messages. Get my PGP key from http://keys.gnupg.net.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.15 (GNU/Linux)
Comment: Using GnuPG with Icedove - http://www.enigmail.net/

iEYEARECAAYFAlJxcL4ACgkQTiFSTN7SboUJQgCeOIyqXdQwgqDpjbdklLbH9oXy
HNoAniqAdDAk1xSI3tMbsv2CJETqDClT
=9VeU
-----END PGP SIGNATURE-----


More information about the Users mailing list