Rstudio Multicore usage

Hey folks,

i was asking myself if and how rstudio or r uses multiple cores of my cpu. researching brings up mostly topics from around ~2010,which suggest using parallel or other packages to achieve multicore usage.

If i monitor my cpu usage while running intense scripts (e.g. monte carlo simulations with "vectorized" drawing "processes" looping through different distributions) , all cores seem to be busy and increase in their usage.

so this implies multicore usage to a certain extend, my question is if this just looks like it and the process runs only on one core. I got an i7 7760U.

thanks in advance and best regards,

chris

1 Like

Hi,

Welcome to the RStudio community!

R can indeed make use of all cores available, but you need to explicitly tell it to do it because not all code can be run in parallel. There are a few great packages for implementation, but I think this blog can help you get started:

https://nceas.github.io/oss-lessons/parallel-computing-in-r/parallel-computing-in-r.html

In this blog, they also refer to the more comprehensive but slightly more complicate CRAN vignette:

Hope this helps,
PJ

5 Likes

Besides the explicit use of parallel computing there are also a few places where processing might use multiple cores implicitly:

  • R itself uses OpenMP for parallel execution in some places
  • many matrix operations are handled by a BLAS/LAPCK library, which might use multiple cores (e.g. OpenBLAS).
  • some packages use multicore processing implicitly (e.g. data.table uses OpenMP)
4 Likes

Hi PJ,

thank you so much for your quick reply!
I am allways up for a good read, so thanks for providing the literature.

kind regards,

chris

Hi rstub,

thank you for your quick reply.
as i try to focus on algebraic processes handling my data, your post might answer my question, how this "probably" multicore usage is achieved. So it seems parts of my script indeed take advantage of using more than one core.

So thanks a lot for clearing this up and kind regards,

chris

Hi Chris,
Some additional background info.
Under Windows (and probably other OS too) the OS will distribute a single thread's work across the available cores so each core does a fraction of the work; this is invisible to the user. The most reliable way to tell whether you are getting more than one core's worth of performance is to check the total CPU usage: if it is more than 100/n% (where n is the number of cores) they you are getting a boost from parallel processing (multi-threading).
Base R is still mostly single-threaded, but @rstub mentions some notable exceptions.
If you explicitly use the parallel package under Windows, you'll see tasks named "RScript" for your workers in Task Manager, while your parallel tasks are running you should see each of these getting approx 100/n% of your CPU (e.g. 25% if you assign your tasks to 4 cores).

1 Like

Hey Soco,

thanks for your reply, this supports parts of my asumptions!
So using mentioned packages could probably increase the already running multi core perfomance.

happy holidays and kind regards,

chris

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.