[Omp] dynamically change the number of threads for OpenMP
DING, Yang
dingyang at gmail.com
Sun May 20 18:13:29 PDT 2007
Hi,
Thanks a lot for the reply. I understand that I can insert the special
code to the source program to change the number of threads for
different parallel regions.
However, what I am interested is to change it at RUNTIME. In other
word, I do not want to change the source code before compilation and
execution. Is there still a way? If not, I guess dynamic compilation
might be the only choice.
Many thanks,
Yang
On 5/20/07, Hoeflinger, Jay P <jay.p.hoeflinger at intel.com> wrote:
> There are two ways: the function
> omp_set_num_threads(<integer-expression>) and the num_threads(<integer
> expression>) clause on a parallel directive. Omp_set_num_threads() sets
> the number of threads to be used for the next encountered parallel
> region. The num_threads() clause sets the number of threads for that
> parallel region.
>
> Examples:
>
> omp_set_num_threads(n+1);
>
> OR
>
> #pragma omp parallel num_threads(n+1)
>
> The num_threads() clause would over-ride any previously set value set by
> omp_set_num_threads(). The value set by the num_threads() clause ONLY
> applies to the current parallel region, however. It does not persist to
> later parallel regions. The omp_set_num_threads() value persists to
> later parallel regions unless over-ridden by num_threads() or a later
> call to omp_set_num_threads().
>
> The OMP_NUM_THREADS environment variable sets only the initial value of
> the number of threads. Changing it during the execution of the program
> has no effect.
>
> Jay
More information about the Omp
mailing list