setThreadsTP {TPmsm} | R Documentation |
Specifies the number of threads used by default in parallel sections.
setThreadsTP(num_threads=NULL)
num_threads |
the number of threads to use. |
If num_threads
is greater than the number of processors/cores
then the number of processors/cores is used. If package TPmsm
was compiled without OpenMP support then this function returns 1
regardless of the number of processors/cores available.
If num_threads=NULL
the number of threads is not defined.
This is useful when the current number of threads is desired
without defining a new thread number.
Invisibly returns the previous number of threads.
The given thread number is stored in a global variable. This global variable
is then passed to the num_threads clause defined on all parallel sections of
underlying C code. By specifying the number of threads in this way instead of
specifying with a call to omp_set_num_threads we are certain that there is
no interference with the R process. Every time this function is called the
RNG streams are recreated. For more details see setPackageSeedTP
.
Artur Araújo, Javier Roca-Pardiñas and Luís Meira-Machado
OpenMP Architecture Review Board, OpenMP Application Program Interface Version 3.0, May 2008, p110 (http://www.openmp.org/mp-documents/spec30.pdf)
“Runtime Library Routines”, Summary of OpenMP 3.0 C/C++ Syntax, p5 (http://www.openmp.org/mp-documents/OpenMP3.0-SummarySpec.pdf)
# Set the number of threads nth <- setThreadsTP(2) # Restore the number of threads setThreadsTP(nth)