Technical data
Advanced Features
99
This trade-off between response time and CPU usage can be adjusted with
the mp_blocktime(3f) call. mp_blocktime takes a single integer argument
that specifies the number of times to spin before blocking. By default, it is set
to 10,000,000; this takes roughly 3 seconds. If called with an argument of 0,
the slave threads will not block themselves no matter how much time has
passed. Explicit calls to mp_block, however, will still block the threads.
This automatic blocking is transparent to the user’s program; blocked
threads are automatically unblocked when a parallel region is reached.
mp_numthreads, mp_set_numthreads
Occasionally, you may want to know how many execution threads are
available. mp_numthreads(3f) is a zero-argument integer function that
returns the total number of execution threads for this job. The count includes
the master thread.
mp_set_numthreads(3f) takes a single-integer argument. It changes the
default number of threads to the specified value. A subsequent call to
mp_setup will use the specified value rather than the original defaults. If the
slave threads have already been created, this call will not change their
number. It only has an effect when mp_setup is called.
mp_my_threadnum
mp_my_threadnum(3f) is a zero-argument function that allows a thread to
differentiate itself while in a parallel region. If there are n execution threads,
the function call returns a value between zero and n – 1. The master thread
is always thread zero. This function can be useful when parallelizing certain
kinds of loops. Most of the time the loop index variable can be used for the
same purpose. Occasionally, the loop index may not be accessible, as, for
example, when an external routine is called from within the parallel loop.
This routine provides a mechanism for those rare cases.










