OpenMP® Forum

Discussion on the OpenMP specification run by the OpenMP ARB. OpenMP and the OpenMP logo are registered trademarks of the OpenMP Architecture Review Board in the United States and other countries. All rights reserved.

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.

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?

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.