[Users] Fortran OpenMP parallel do

Erik Schnetter schnetter at cct.lsu.edu
Wed Oct 30 08:37:17 CDT 2013


On Oct 30, 2013, at 7:24 , Ian Hinder <ian.hinder at aei.mpg.de> wrote:

> On 30 Oct 2013, at 01:53, Erik Schnetter <schnetter at cct.lsu.edu> wrote:
> 
>> I have just found several instances of "OpenMP parallel do" constructs in GRHydro that did not mark loop variables as private. This is a severe parallelization error that can lead to wrong results in ways that are very difficult to debug.
>> 
>> I wonder why the compiler does not flag this. I suggest a code review before the release.
>> 
>> While it is true that the loop index of the loop that is parallelized (usually only the outermost loop) does, in Fortran, not have to be declared as private, all other loop indices still have to be declared as private. In C, all loop indices have to be declared as private. Personally, I find it simplest to just declare all loop indices as private.
>> 
>> This is correct:
>>  !$OMP PARALLEL DO PRIVATE(i,j,k)
>>  do k=1,nz
>>     do j=1,ny
>>        do i=1,nx
>> 
>> And this would be wrong:
>>  !$OMP PARALLEL DO
>>  do k=1,nz
>>     do j=1,ny
>>        do i=1,nx
> 
> 
> Surely this would give results so wrong that they would be noticed?  Is it possible that the compiler is automatically declaring the variables as private, without emitting a warning?  Are the routines with the bugs actually used for physics yet, and have they been validated?

Without a flush statement (or a statement that implies a flush, such as e.g. a barrier), there is no guarantee that shared variables are actually communicated. In a simple loop, the compiler may decided to privatize the variables, and to communicate them only when required, e.g. by keeping them in registers. In this case, the code would happen to work correctly.

-erik

> PS: #include <usual rant about lack of a reproducible correctness-testing framework for the Einstein Toolkit>
> 
> -- 
> Ian Hinder
> http://numrel.aei.mpg.de/people/hinder
> 

-- 
Erik Schnetter <schnetter at cct.lsu.edu>
http://www.perimeterinstitute.ca/personal/eschnetter/

My email is as private as my paper mail. I therefore support encrypting
and signing email messages. Get my PGP key from http://pgp.mit.edu/.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 203 bytes
Desc: Message signed with OpenPGP using GPGMail
Url : http://lists.einsteintoolkit.org/pipermail/users/attachments/20131030/b746ff12/attachment.bin 


More information about the Users mailing list