How can I get R to use more CPU usage?

I noticed that R does not use my entire processor, and I want to increase it tremendously (up to 100%). I do not want it to simply parallelize several functions; I want R to use more resources of my processor. I am trying to run a clean IP packet packing program using the lp () function. I am currently running windows and I have 4 cores on my computer.

I tried to experiment with snow, doParallel and foreach (although I don’t know what I do with them).

In my code, I have this ...

library(foreach) library(doParallel) library(snowfall) cl <- makeCluster(4) registerDoParallel(cl) sfInit(parallel = TRUE, cpus = 4) #code that is taking a while to run but does not involve simulations/iterations lp (......, all.int = TRUE) sfStop() 

R is stuck and running lp () for a very long time. My processor is about 25%, but how can I increase it?

+4
source share
2 answers

If you are trying to run 4 different LPs in parallel, here is how to do it in snowfall .

 sfInit(parallel=TRUE, cpus=4) sfSource(code.R) #if you have your function in a separate file sfExport(list=c("variable1","variable2", "functionname1")) #export your variables and function to cluster results<-sfClusterApplyLB(parameters, functionname) #this starts the function on the clusters 

eg. A function in sfClusterApply may contain your LP.

Otherwise, see the comments on your question.

0
source

Conducting this as an answer because there is not enough space in the comment. This is not the answer directly to your question, but more on performance.


R by default uses slow statistics libraries, which by default can use only one core. Improved libraries - OPENBLAS / ATLAS. However, it can be a pain to install.
Personally, I eventually got it using this guide .

In the end, I used Revolution R open (RRO) + MKL, which has both improved BLAS libraries and multi-cpu support. This is an alternative R-distribution, which should have up to 20 times the speed of a regular R (I can not confirm this, but it is much faster).

In addition, you can check the CRAN HPC packages to see if there are advanced packages that support the lp function.

There is also a package for exploring the use of multiple processors.
This answer is from Gavin, as well as the @ user3293236 answer above shows several features for packages that allow multiple processors to be used.

0
source

Source: https://habr.com/ru/post/1247716/


All Articles