[R-sig-hpc] Disabling implicit parallelism of multithreaded BLAS from an R package

Scott Ritchie sritchie73 at gmail.com
Wed Aug 13 06:40:14 CEST 2014

Hi all,

I'm developing a package in which I explicitly handle parallelism, and in
each parallel R session, running some SVD calculations through Rcpp +

On one of my test machines, R 3.1.0 has been compiled against OpenBLAS, so
the calls to SVD are implicitly parallel.

I can disable this by exporting the appropriate environment variable before
calling R (OPENBLAS_NUM_THREADS=1), but I would ideally like to abstract
that detail away from the user (as some of my intended target audience may
be biologists without a strong computational background, but nevertheless
operating on a cluster someone else has set up).

I've tried a couple of things to disable the implicit parallelism without
any success:
 - Sys.setenv doesn't have any effect, even on the new R sessions spawned
through `foreach` with the `doMC` parallel backend (this surprises me, is
my mental model of parallelism in R correct?)
 - exporting the environment variables using `cstdlib::putenv` in the C++
code directly before the call to `svd`.
 - The solution I found through the r-sig-hpc archives:
https://stat.ethz.ch/pipermail/r-sig-hpc/2012-July/001432.html. Directly
calling openblas_set_num_threads(1); in the C++ code has no effect.

I've also tried explicitly disabling BLAS in the hope that Armadillo will
call the LAPACK routines directly (although I may have done this
incorrectly) by doing the following:
 - removing the $(BLAS_LIBS) from the PKG_LIBS variable in the
Makevars/Makevars.win files
 - Setting #define ARMA_DONT_USE_BLAS and #define ARMA_DONT_USE_WRAPPER
before including the <RcppArmadillo.h> header file in my source code.

Ideally I'm looking for a solution that allows me to set the maximum number
of threads to 1 for all the multithreaded BLAS libraries in my package to
prevent conflicts between the implicit and explicit parallelism. Is this


Scott Ritchie

	[[alternative HTML version deleted]]

More information about the R-sig-hpc mailing list