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

beleites,claudia claudia.beleites at ipht-jena.de
Wed Aug 13 10:21:42 CEST 2014

Hi Scott

You may need to contact the developers of openblas about openblas_set_num_threads. 2yrs ago when Simon was writing that wrapper it was only implemented for Linux. All other is just had a non- working dummy.


Claudia Beleites, Chemist
Leibniz Institute of Photonic Technology
Albert-Einstein-Str. 9
07745 Jena

email: claudia.beleites at ipht-jena.de
phone: +49 3641 206-133
fax:   +49 2641 206-399

Von: r-sig-hpc-bounces at r-project.org [r-sig-hpc-bounces at r-project.org]" im Auftrag von "Scott Ritchie [sritchie73 at gmail.com]
Gesendet: Mittwoch, 13. August 2014 06:40
An: r-sig-hpc at r-project.org
Betreff: [R-sig-hpc] Disabling implicit parallelism of multithreaded BLAS       from an R package

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]]

R-sig-hpc mailing list
R-sig-hpc at r-project.org

More information about the R-sig-hpc mailing list