PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

Naive OpenMP configuration question
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
Eos Pengwern



Joined: 18 Aug 2010
Posts: 16

PostPosted: Thu Sep 09, 2010 3:59 pm    Post subject: Naive OpenMP configuration question Reply with quote

My code is parallelised using OpenMP. Even if I make sure I have enabled OpenMP in the compiler options, and the compile-time diagnostics show me that the code is parallelised, and I ensure that there is more than one core available at run-time, my run-time diagnostics reveal that the code is still only running on one core.

Is there anything else I need to do to make sure that OpenMP is fully enabled?
Back to top
View user's profile
mkcolg



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

PostPosted: Thu Sep 09, 2010 4:36 pm    Post subject: Reply with quote

Hi Eos Pengwern,

How are you setting the number of OpenMP threads?

This can be done either via the shell's environment variable OMP_NUM_THREADS or in your program via a call to "omp_set_num_threads".

By default, if you do not set the number of threads, only one will be used. Though, if you the flag "-mp=allcores", the default is to use all available cores.

Hope this helps,
Mat
Back to top
View user's profile
Eos Pengwern



Joined: 18 Aug 2010
Posts: 16

PostPosted: Thu Sep 09, 2010 4:47 pm    Post subject: Reply with quote

Thanks Mat!

I think I see the problem; I haven't explicitly set the number of threads, since I'm used to Intel Fortran where the default is to have as many threads as there are cores available. Hence the PGI compiler has been defaulting to one core, it seems. That's easy to fix!

Regards,
Stephen.
Back to top
View user's profile
Eos Pengwern



Joined: 18 Aug 2010
Posts: 16

PostPosted: Fri Oct 01, 2010 3:55 pm    Post subject: Reply with quote

As expected, setting:

nthreads = omp_get_num_procs()
call omp_set_num_threads(nthreads)

... before the first of my OpenMP regions solves the issue and gives me full parallelism on all cores.

I run into problems, though, when I try to parallelise other sections in other modules of my application. In another module, if I put the above two lines before the first OpenMP region, then it runs very well the first time the code is executed but there is always a hard crash (i.e. GUI suddenly disappears) the second time that same section of code is run.

If, on the other hand, I try to put the above two lines right at the beginning of the program, in the separate 'initialisation' module, then the hard crash occurs just before the section of code that had previously been running well when the two lines had been in its own module.

So, where is the correct place to set the number of cores for OpenMP to use, and once it has been set how wide is its scope?
Back to top
View user's profile
hongyon



Joined: 19 Jul 2004
Posts: 551

PostPosted: Mon Oct 04, 2010 11:00 am    Post subject: Reply with quote

You can put in at the beginning of a program before parallel section. Once set, the scope is throughout the program. I am not sure why it crashes as we don't have enough information to determine the cause, please check that nthreads is more than 1. If you don't use omp_lib module, please make sure omp_get_num_procs() is of integer type.


Hongyon
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling 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 © phpBB Group