What is the correct way to globally configure R to default to single (or
at least, << NUM_CPUS) threaded operation?


Using R 3.3.1 (both in debian unstable or using the CRAN repository for
xenial) with OpenBLAS (0.2.18) defaults to using one thread per
available CPU, which isn't ideal for machines more than a couple of CPUs.

Setting the environment (OMP_NUM_THREADS or OPENBLAS_NUM_THREADS) in the
shell works:

$ OMP_NUM_THREADS=1 R
> Sys.getenv("OMP_NUM_THREADS")
[1] "1"
> system.time({x <- replicate(5e3, rnorm(5e3)); tcrossprod(x) })
[runs in one thread]

but adding it to /etc/R/Renviron.site doesn't:

$ R
> Sys.getenv("OMP_NUM_THREADS")
[1] "1"
> system.time({x <- replicate(5e3, rnorm(5e3)); tcrossprod(x) })
[runs multi-threaded]

(nor does setting the variable at runtime with `Sys.setenv`)

Presumably Renviron is read after the library is already loaded and so
the environment variable is set too late to matter.




I can think of these solutions, but none of them are ideal:

 * remove OpenBLAS (but even single threaded it performs quite a lot
better than the basic libblas)

 * set OMP_NUM_THREADS globally in people's shells with the system
bashrc (but this doesn't work for non-shell, RStudio server sessions)

 * use a library like RhpcBLASctl to set the number of threads in the
global Rprofile

 * compile a custom openblas with threading disabled, or at least a
small default number of threads


Any better ideas?


Thanks

Gordon

_______________________________________________
R-SIG-Debian mailing list
R-SIG-Debian@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-debian

Reply via email to