reduction clause - intermediate values

General OpenMP discussion

reduction clause - intermediate values

Postby María » Thu Jun 27, 2013 9:31 am

Hello,

I am trying to checkpoint an OpenMP program and I have a doubt with the reduction clause.

For example, the next code:

!$OMP PARALLEL DO REDUCTION(+:sum)
do I=1,N
sum=sum+a[i]
print* sum
enddo

Does it print all the partial sums in each thread or is the variable sum undefined in that point?

I have executed that code in my machine and it prints the partial sums but I am not sure if this is the behaviour for any OpenMP implementation.

Thanks in advance for your help.

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

Re: reduction clause - intermediate values

Postby ftinetti » Thu Jun 27, 2013 10:22 am

Hi María,

Reduction variables are defined because they are initialized at loop start, according to the OpenMP spec., i.e. I think you have seen the correct behavior independently of the implementation.

HTH,

Fernando.
ftinetti
 
Posts: 582
Joined: Wed Feb 10, 2010 2:44 pm

Re: reduction clause - intermediate values

Postby MarkB » Thu Jun 27, 2013 10:46 am

Fernando is right, that is the correct behaviour. All references to sum inside the parallel construct are to the private copies on each thread. The global sum is not formed until the end of the parallel region - i.e. it is not continuously updated.
MarkB
 
Posts: 487
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: reduction clause - intermediate values

Postby María » Fri Jun 28, 2013 3:19 pm

Ok. Thank you very much to both of you!

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: Yahoo [Bot] and 7 guests

cron