Is there any way to unlimit the CPU usage so my PC puts more effort in finishing a task for rapidly? At the moment the k-means algorithm is estimated to finish in about 10 days, which is something I would like to reduce.
-
1How long does it take to run the process regularly? Do you really mean 10% CPU usage? `parallel::mclapply` does not work on Windows. What did you use there? – Ralf Stubner Apr 23 '18 at 11:57
-
I did't know it does not work on windows so I used it and yes, I do mean 10% of the CPU usage (which is the percentage from the *Task Manager* or *System Monitor* – theBotelho Apr 23 '18 at 12:10
-
@RalfStubner considering what you commented, I've edited the question so it suits better – theBotelho Apr 23 '18 at 12:18
-
How large is the date you are analyzing compared to available RAM? One explanation might be that your computer is swapping a lot, i.e. using HDD to store RAM data because RAM is full. In that case adding additional processes with additional RAM requirements will be counterproductive. – Ralf Stubner Apr 23 '18 at 12:21
1 Answers
R is single-threaded by default, and runs only on a single thread on the CPU, which is a pity if you have a machine with 16 or 32 cores. By unlimiting the CPU usage, I have to assume you're asking if there's any way to have an R process (let's say part of the k-means algorithm) take advantage of your full CPU power by running the process in-parallel.
Many R packages and processes are not going to be helped by parallel processing though. So the technical solution to your particular problem goes down to the package implementation you're using. Popular packages like caret
do support parallelization when that's possible, even though you may need to add an additional allowParallel=T
parameter. They work in conjunction with a library such as doMC
to allow multi-core processes. In the following sample code, I have my machine use 8 cores through the registerDoMC(8)
function, and then set allowParallel=T
.
library(doMC)
registerDoMC(8)
system.time({
ctrl_2 <- trainControl(method="cv", number=3, allowParallel=T)
fb_forest_2 <- train(classe ~ ., data=fb_train, method="rf", trControl = ctrl_2)
})
Again, parallel processing doesn't always help - Not all process can be parallelized! The documentation for foreach
are a great read so if you can afford the time take a look at it. The specific code solution for your problem also depend on the library implementation you're using.

- 8,606
- 4
- 44
- 58