2

We are running Ubuntu 20.04 with RStudio Server Open Source. The system is using OpenBLAS for linear algebra.

What are the different ways to limit the number of threads on a per user base used for linear algebra from within RStudio Server?

I have tried setting

export OPENBLAS_NUM_THREADS=4

in .profile and .bashrc but neither works.

I haven't tried [1] yet. Are there other ways? I would like to make a low number of threads the default for everyone because users are not aware of the different types of parallelism and oversubscribe cores.

I am also not able to limit the number of threads for all users, I have tried setting them in

/etc/environment
/etc/rstudio/env-vars

and also with

systemctl edit rstudio-server.service

nothing works.

[1] https://github.com/wrathematics/openblasctl

gdkrmr
  • 674
  • 4
  • 16

1 Answers1

1

There is also package for this allowing you to set the usual OpenBLAS / MKL variables from R: https://cran.r-project.org/package=RhpcBLASctl

It also allows you to query for cores and processors and allocated for both BLAS and OpenMP:

> library(RhpcBLASctl)
> get_num_cores()
[1] 6
> get_num_procs()        # hyperthreading on
[1] 12
> blas_set_num_threads(4)
> 
> 

If you want to set this more permanently, the usual place is Renviron.site for the underlying environment variable, or Rprofile.site if you want to do it from R code via Sys.setenv() -- or to call this helper package. How the startup variable setting sequence works in explained in help(Startup).

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Thanks, that is the solution I am using now. Took me a while to get there. I am really wondering why RStudio Server is actively ignoring these variable. I can only set `LD_LIBRARY_PATH` in the service file, everything else seems to get ignored. – gdkrmr May 16 '23 at 08:03