Doubt data-sharing attribute rules

General OpenMP discussion

Doubt data-sharing attribute rules

Postby María » Tue Oct 04, 2011 2:24 am

Hi,

I have a doubt about the default data-sharing attribute of the J variable in the next code:

Code: Select all
    DO J=1,4
!$OMP PARALLEL DO
          DO I=1,50
             A(I,J)=I*J
          END DO
    END DO


Is the J variable private by default (because it is a loop iteration variable of a Fortran program), or is it shared (because the J loop is external to the parallel region)?

Thanks in advance,

María
María
 
Posts: 5
Joined: Mon Feb 22, 2010 2:44 pm

Re: Doubt data-sharing attribute rules

Postby ftinetti » Tue Oct 04, 2011 3:34 am

Hi,

I use this guideline for myself: use explicit declaration/directive/clause, since it makes the code clearer (at least for me). It has the drawback I never learn how to answer questions like yours (btw, the answer should be in section 2.9 of the OpenMP 3.0 spec) but makes my code clearer (again, at least to me). So, the question becomes what should be variable J? I think it's clear J should be shared, then I would add a SHARED(J) clause to the PARALLEL DO.

(I would follow "my"/the same guideline for A, btw).

HTH.
ftinetti
 
Posts: 575
Joined: Wed Feb 10, 2010 2:44 pm

Re: Doubt data-sharing attribute rules

Postby María » Tue Oct 04, 2011 8:33 am

Thanks HTC for your reply.

I know that OMP PARALLEL DO SHARED(J) guarantees correction. Anyway, I'd like to know if OMP PARALLEL DO is also correct. It's just simple curiosity. I have read the 2.9 section of the OpenMP 3 spec but it is hard for me to apply it in this case.

Any other help?

Thanks,

María
María
 
Posts: 5
Joined: Mon Feb 22, 2010 2:44 pm

Re: Doubt data-sharing attribute rules

Postby hhj » Fri Oct 14, 2011 9:51 am

The default-private rule for Fortran loop variables applies to those loops that are inside a parallel region. Since the J loop is outside the parallel region in your example, the variable "J" is shared by default (the default shared rule).
hhj
 
Posts: 16
Joined: Thu May 01, 2008 11:59 am

Re: Doubt data-sharing attribute rules

Postby María » Mon Oct 17, 2011 3:30 am

Ok. Thank you very much.

María
María
 
Posts: 5
Joined: Mon Feb 22, 2010 2:44 pm


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 6 guests