1

I have set up R/RStudio in WSL following the instructions I wrote up a while back outlined here: https://killianmelsen.github.io/guide/2023/06/20/Accelerating-R-using-oneMKL-and-Windows-Subsystem-for-Linux.html

However, setting the number of threads in the /etc/environment file no longer does anything. It used to work perfectly.

Here's the environment file for 1 thread, and here's the same file for the multi-threaded setting. I shut down and restarted WSL after making any changes.

Here are the results:

single-threaded

multi-threaded

default BLAS/LAPACK, i.e. not MKL

same 5000x5000 matrix using MKL/16 threads

Any ideas this seems to no longer work?

Changing these settings in /etc/environment always had an effect on the CPU utilization and runtimes. For some reason that is not the case anymore. This is an imported Ubuntu distribution that is based on the original WSL Ubuntu installation (I wanted to set up multiple distributions), could that have anything to do with it?

Solution: seems like editing /etc/environment does not work with WSL (I am 100% sure it did when I was using a VM). As an alternative export MKL_NUM_THREADS=x can be added to ~/.profile as per the instructions here.

KMlsn
  • 21
  • 3
  • What is the output of R commands `Sys.getenv("MKL_NUM_THREADS")` and `parallel::detectCores()`? What about running `echo $MKL_NUM_THREADS` in a terminal? I don't see any information in your screenshots confirming that the environment variable was set as intended. – Matt Summersgill Jul 24 '23 at 18:05
  • `echo $MKL_NUM_THREADS` does not return anything. Neither does `Sys.getenv("MKL_NUM_THREADS)`. `parallel::detectCores` returns 20 threads as it should. I should have maybe added that this is an exported and re-imported distribution that was based on the distribution that is installed when running `wsl --install` for the first time. Perhaps that could have something to do with it? – KMlsn Jul 24 '23 at 19:53
  • Some extra screenshots that might be of use: [echo output](https://i.imgur.com/jeeIPxY.png) and some [Sys.setenv()/Sys.getenv() results](https://i.imgur.com/Z03umAC.png). Neither do anything. I also tried unregistering and reinstalling the default Ubuntu distribution using `wsl --unregister Ubuntu` and `wsl --install`, then reinstalling R, RStudio, and MKL but setting MKL_NUM_THREADS in /etc/environment still does not have any effect on CPU utilization... – KMlsn Jul 24 '23 at 20:35
  • I completely reinstalled WSL and Ubuntu and it still didn't work. I tried a couple of things but eventually found that using `export MKL_NUM_THREADS=1` in the terminal as per [these](https://www.intel.com/content/www/us/en/docs/onemkl/developer-guide-linux/2023-0/set-the-env-variables-for-threading-control.html) instructions works perfectly. Doesn't seem to be permanent though. Changing /etc/environment was something I did when I was running on a VM, perhaps it simply does not work with WSL and I just haven't noticed... – KMlsn Jul 24 '23 at 23:28

1 Answers1

1

Solution: seems like editing /etc/environment does not work with WSL (I am 100% sure it did when I was using a VM). As an alternative export MKL_NUM_THREADS=x can be added to ~/.profile as per the instructions here.

KMlsn
  • 21
  • 3