number of threads in openmp

General OpenMP discussion

number of threads in openmp

Postby nivaldo » Tue May 21, 2013 2:15 pm

hello, as knowing the limit of number of threads that can parallelize a code given, for example if I have a loop:
#pragma omp parallel for num_threads(N)
for(int i=0; i<N; i++)

whenever the number of threads will be equal to N?
There is a limit of number of threads?
nivaldo
 
Posts: 5
Joined: Fri May 10, 2013 1:20 am

Re: number of threads in openmp

Postby ftinetti » Tue May 21, 2013 2:50 pm

Hi,

I don't know if I understand your questions, but anyway...
#pragma omp parallel for num_threads(N)
for(int i=0; i<N; i++)

whenever the number of threads will be equal to N?


There is a rather complex (from my point of view, of course) algorithm given in section 2.4.1 of the Spec. (3.1) for "Determining the Number of Threads for a parallel Region" but in every compiler I've used I've seen that code as you post will generate N threads. If in doubt, you can use omp_get_num_threads() to get the actual number of threads in the current team.

There is a limit of number of threads?

Yes, it is given by the icv (internal control variable) thread-limit-var that can be modified by OMP_THREAD_LIMIT and (its value) retrieved by omp_get_thread_limit(), as described in section 2.3.2.

HTH,

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

Re: number of threads in openmp

Postby nivaldo » Tue May 21, 2013 5:32 pm

Thanks for the help, let me ask another question, I'm learning openmp on my own and I is diffi cult.

Whenever the number of iterations can be declared as number of threads to parallelize?
It is best to parallelize the code with N threads (N = number of iterations)?
Is there any book or document I explain how to choose the number of threads to parallelize?
nivaldo
 
Posts: 5
Joined: Fri May 10, 2013 1:20 am

Re: number of threads in openmp

Postby MarkB » Wed May 22, 2013 2:10 am

I'm not sure I completely understand you either, but:

The best number of threads to use is usually related to the hardware you have available, rather than to the number of iterations in parallel loops.
Using more OpenMP threads than you have cores (or hardware threads) very rarely gives the best performance, so it is quite normal for the number of OpenMP threads to be
much smaller than the number of iterations in your parallel loops. It is hard to predict what the best number of threads will be: you will probably need to determine
this by experiment for your particular application.

Hope that helps,
Mark.
MarkB
 
Posts: 450
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 7 guests

cron