Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to let R use all the cores of the computer?

I have read that R uses only a single CPU. How can I let R use all the available cores to run statistical algorithms?

like image 682
Dail Avatar asked Nov 11 '11 09:11

Dail


People also ask

How do I use more cores in R?

If you are on a single host, a very effective way to make use of these extra cores is to use several R instances at the same time. The operating system will indeed always assign a different core to each new R instance. In Linux, just open several the terminal windows. Then within each terminal, type R to open R.

How many cores can I use in R?

As a default, R runs serially, it runs only one one core / thread. For example the function sum() runs will process the whole dataset in a single core.

How do I enable all cores in BIOS?

From the System Utilities screen, select System Configuration > BIOS/Platform Configuration (RBSU) > System Options > Processor Options > Processor Core Disable and press Enter. Enter the number of cores to enable per processor socket and press Enter. If you enter an incorrect value, all cores are enabled.


1 Answers

Yes, for starters, see the High Performance Computing Task View on CRAN. This lists details of packages that can be used in support of parallel computing on a single machine.

From R version 2.14.0, there is inbuilt support for parallel computing via the parallel package, which includes slightly modified versions of the existing snow and multicore packages. The parallel package has a vignette that you should read. You can view it using:

vignette(package="parallel", topic = "parallel")

There are other ways to exploit your multiple cores, for example via use of a multi-threaded BLAS for linear algebra computations.

Whether any of this will speed up the "statistics calculations" you want to do will depend on what those "statistics calculations" are. Spawning off multiple threads or workers entails an overhead cost to set them up, manage them and collect the results. Some operations see a benefit (some large, some small) of using multiple cores/threads, others are slowed down because of this extra overhead.

In short, do not expect to get an n times decrease in your compute time by using n cores instead of just 1.

like image 175
Gavin Simpson Avatar answered Nov 11 '22 19:11

Gavin Simpson