PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

Common blocks in OpenMP
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming
View previous topic :: View next topic  
Author Message
dcwarren



Joined: 18 Jun 2012
Posts: 29

PostPosted: Tue Mar 05, 2013 4:21 pm    Post subject: Common blocks in OpenMP Reply with quote

Hello,

In my last thread (here), I mentioned a problem I was seeing with common blocks in the OpenMP paradigm. After some testing, I'm out of ideas, so I'd appreciate some advice.

The code I'm using makes use of common blocks. What I think is happening is that when subroutines inside the parallel region use these common blocks, they refer back to the global values -- even if the individual variables have been declared as "private". If, on the other hand, I make the common blocks "threadprivate", the code outside of the parallel region cannot use those variables to initialize them; subroutines (outside the parallel region) that should be seeing values for those variables are getting 0's instead.

Is there a way in OpenMP to (1) get the compiler to create local copies of common blocks for use in a parallel region, (2) initialize those variables according to any pre-existing values in the global common blocks, and (3) distinguish based on location which version of the common block to be using?
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 4996
Location: The Portland Group Inc.

PostPosted: Fri Mar 08, 2013 2:36 pm    Post subject: Reply with quote

Hi dcwarren,
Quote:
If, on the other hand, I make the common blocks "threadprivate", the code outside of the parallel region cannot use those variables to initialize them; subroutines (outside the parallel region) that should be seeing values for those variables are getting 0's instead.
The serial portions of the code's common block should have the same value as the master thread. I'm not sure why you're only seeing zeros. Are you initializing the common block before entering the first parallel region?

- Mat
Back to top
View user's profile
dcwarren



Joined: 18 Jun 2012
Posts: 29

PostPosted: Mon Mar 11, 2013 7:59 am    Post subject: Reply with quote

I ended up writing this issue off to bad memory management by the person who wrote the code. The common blocks were added any time they were needed with whatever variables were needed at the time, so there was a hideous mix of variables that needed to be private/shared/constant scattered through all of the common blocks.


I spent the weekend rewriting the code to restore some sanity to the way this code manages its variables, and now I have a bizarre new problem. The code now loses the value of arguments to one of its subroutines. Here's how the code looks (ignoring lots of structure around these lines, such as declarations, etc.):
Code:
...

!$omp parallel do default(shared)
     (omp region)
!$omp end

  call foo(bar1, bar2, ...)

...

Code:
subroutine foo(bar1, bar2, ...)

do i = 1, bar2
  do ii = 1, bar1
    ...

What I'm seeing is that the variables bar1 and bar2 have values of 61 and 4 (respectively) throughout the OpenMP region and up to the call to subroutine foo. However, immediately upon entry into foo, both have a value of 0, making them quite useless as an upper bound to that do loop.

This only happens if the -mp flag is used at compilation. If I leave off that flag the code runs as expected. Any ideas?


Edit: Just stumbled across a comment that shared variables become undefined upon exit from an OpenMP region. If this is true, I guess my question is now the much easier, "How can I prevent this?"
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 4996
Location: The Portland Group Inc.

PostPosted: Mon Mar 11, 2013 9:55 am    Post subject: Reply with quote

Quote:
Just stumbled across a comment that shared variables become undefined upon exit from an OpenMP region. If this is true, I guess my question is now the much easier, "How can I prevent this?"
This is only true when the shared variable is a pointer and associated with a private variable (See 2.9.3.2 of http://www.openmp.org/mp-documents/OpenMP3.1.pdf), so I doubt this is the problem.

As to why this is occurring, I'm not sure and it doesn't really make much sense. How are you determining the values of bar1 and bar2? If you're looking at them in the debugger, at optimization, they may be stored in a register so printing out the variable may not be the actual value being used.

If that's not it, I'd start using print statements to see where the values change to zero.

Sorry I can't be more helpful,
Mat
Back to top
View user's profile
dcwarren



Joined: 18 Jun 2012
Posts: 29

PostPosted: Mon Mar 11, 2013 9:59 am    Post subject: Reply with quote

I am using the debugger, but I've turned off optimization. One of the greybeards in my department suggested it might be an array overstepping its bounds somehow, so I'll try that and print/flush statements to figure it out. Thanks for the speedy response.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Accelerator Programming All times are GMT - 7 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group