Должно быть несколько вариантов. Вот соответствующий раздел из Writing R Extensions, Section 1.2.1.1
Packages are not standard-alone programs, and an R process could
contain more than one OpenMP-enabled package as well as other components
(for example, an optimized BLAS) making use of OpenMP. So careful
consideration needs to be given to resource usage. OpenMP works with
parallel regions, and for most implementations the default is to use as
many threads as 'CPUs' for such regions. Parallel regions can be
nested, although it is common to use only a single thread below the
first level. The correctness of the detected number of 'CPUs' and the
assumption that the R process is entitled to use them all are both
dubious assumptions. The best way to limit resources is to limit the
overall number of threads available to OpenMP in the R process: this can
be done via environment variable 'OMP_THREAD_LIMIT', where
implemented.(4) Alternatively, the number of threads per region can be
limited by the environment variable 'OMP_NUM_THREADS' or API call
'omp_set_num_threads', or, better, for the regions in your code as part
of their specification. E.g. R uses
#pragma omp parallel for num_threads(nthreads) ...
That way you only control your own code and not that of other OpenMP
users.
Один из моих любимых инструментов является пакет управления следующим образом: RhpcBLASctl. Вот его описание:
управления числом нитей на 'BLAS' ('GotoBLAS' AKA 'ACML' и 'МКЛ'). и можно контролировать количество потоков в «OpenMP». получите ряд логических ядер и физических ядер, если это возможно.
В конце концов вам необходимо управлять количеством параллельных сеансов, а также количеством ядер BLAS, выделенных для каждого из параллельных потоков. Существует причина, по которой параллельный пакет имеет по умолчанию 2 потока за сеанс ...
Все это должно быть в значительной степени независимым от вкуса Linux или Unix, который вы используете. Ну, кроме того, что OS X, конечно (еще !!), не дает вам OpenMP.
И самый внешний уровень, который вы можете контролировать от doMC
и друзей.
Какая ОС вы используете? Я полагаю, что Linux использует 'doMC'. – cdeterman