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

Scott Ritchie sritchie73 at gmail.com
Wed Aug 13 12:08:55 CEST 2014

Hi Claudia,

The system I tested it on is running Ubuntu 12.04, so it should
theoretically work.
I'd also like a way of disabling implicit parallelism if R has been
compiled with Goto BLAS and MKL, since I assume those users will have the
same problem.



On 13 August 2014 18:21, beleites,claudia <claudia.beleites at ipht-jena.de>

> 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.
> Hth
> Claudia
> --
> Claudia Beleites, Chemist
> Spectroscopy/Imaging
> Leibniz Institute of Photonic Technology
> Albert-Einstein-Str. 9
> 07745 Jena
> Germany
> 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 +
> Armadillo.
> 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
> possible?
> Regards,
> Scott Ritchie
>         [[alternative HTML version deleted]]
> _______________________________________________
> R-sig-hpc mailing list
> R-sig-hpc at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-hpc

	[[alternative HTML version deleted]]

More information about the R-sig-hpc mailing list