<div dir="ltr">Setting the environment variables within my Rcpp function using `putenv` also doesn't seem to have an effect.</div><div class="gmail_extra"><br><br><div class="gmail_quote">On 12 August 2014 10:04, Scott Ritchie <span dir="ltr"><<a href="mailto:sritchie73@gmail.com" target="_blank">sritchie73@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks Dirk and Yixuan,<div><br></div><div>I think I'm misstating the question.<div><br></div><div>I'm developing a package which makes use of LAPACK routines through RcppArmadillo, and I'm handling the parallelism from within R.</div>

<div><br>At the moment it looks like I have to write a vignette, telling the user to monitor their CPU usage with a tool like `top`, and if each thread is using more than 100%:</div><div><ol><li>try setting the appropriate environment variables (OPENBLAS_NUM_THREADS=1, GOTO_NUM_THREADS=1,  OMP_NUM_THREADS=1) depending on their BLAS library<br>

</li><li>Switch to a single-threaded BLAS library.</li></ol><div>Ideally, I'd like to be able to abstract away these details from the user, so they don't need to know whether they have a multithreaded or single-threaded version of BLAS installed. </div>

<div><br></div><div>My first thought was to look up the multithreaded BLAS libraries, and set the environment variables accordingly from my main R routine. However, it seems like the changes made in Sys.setenv are not reflected in the RcppArmadillo code.</div>

<div><br></div><div>I hope this makes things clearer,</div><div><br></div><div>Scott </div></div><div><br></div></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On 12 August 2014 09:23, Yixuan Qiu <span dir="ltr"><<a href="mailto:yixuan.qiu@cos.name" target="_blank">yixuan.qiu@cos.name</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Good point by Dirk.<br><div class="gmail_extra"><br></div><div class="gmail_extra">And why not just adding a line "export OPENBLAS_NUM_THREADS=1" to your .bashrc file, or compiling OpenBlas again by setting NUM_THREADS = 1 in the Makefile.rule?<br>


<br><br></div><div class="gmail_extra">Best,<br></div><div class="gmail_extra">Yixuan<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-08-11 18:55 GMT-04:00 Dirk Eddelbuettel <span dir="ltr"><<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>></span>:<div>

<div><br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Hi Scott,<br>
<div><div><br>
<br>
On 12 August 2014 at 08:43, Scott Ritchie wrote:<br>
| Hi Everyone,<br>
|<br>
| I'm having trouble with restricting the Armadillo function "svd_econ" to run on<br>
| a single thread.<br>
|<br>
| I am able to restrict it if I `export OPENBLAS_NUM_THREADS=1` before opening an<br>
| R session, but not from within R (`Sys.setenv(OPENBLAS_NUM_THREADS=1)` has no<br>
| effect).<br>
|<br>
| I'm wondering if theirs an option native to armadillo/RcppArmadillo that I'm<br>
| missing to enable me to:<br>
|<br>
|   • Restrict the number of threads used to 1<br>
|   • In a library agnostic manner (i.e. if the user has a different LAPACK or<br>
|     BLAS library installed).<br>
|<br>
| or if I can "trick" Rcpp into thinking the machine only has 1 core?<br>
<br>
</div></div>I fear you may be misstating / misdiagnosing the problem.<br>
<br>
I am fairly certain that there is not a single line in Rcpp or<br>
(Rcpp)Armadillo which sets thread counts for your LAPACK / BLAS.<br>
<br>
Rather, and this is a point that I tried to make in the 'Benchmarking GPUs<br>
and CPUs on Debian-based systems' package (gcbd on CRAN etc) and its vignette<br>
is that __BLAS and LAPACK sit behind a standardized interface__ and can be<br>
installed / swapped via plug and play. (Which in turn enables the<br>
benchmarking ...)<br>
<br>
If you're on a Debian-based system, just remove openblas and use atlas. Case<br>
closed.  Atlas will not multithread (unless something changed recently).<br>
<br>
There is also a helper function or package somewhere, and a post by Claudia<br>
Beleites on StackOverflow, which show the explicit function call to reset<br>
OpenBLAS in its count.  But if everything else fails -- just use a different<br>
BLAS.  I sometimes do that too when I use multicore / parallel to launch<br>
multiple R jobs and each one of those should not spawn additional linear<br>
algebra threads.<br>
<br>
Hope this helps,  Dirk<br>
<br>
<br>
<br>
| Regards,<br>
|<br>
| Scott Ritchie<br>
| _______________________________________________<br>
| Rcpp-devel mailing list<br>
| <a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
| <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a><br>
<span><font color="#888888"><br>
--<br>
<a href="http://dirk.eddelbuettel.com" target="_blank">http://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a><br>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></font></span></blockquote></div></div></div><span><font color="#888888"><br>

<br clear="all">
<br>-- <br>Yixuan Qiu <<a href="mailto:yixuan.qiu@cos.name" target="_blank">yixuan.qiu@cos.name</a>><br>Department of Statistics,<br>Purdue University<br>
</font></span></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>