I am trying to use multiple cores to run my R script on a big dataset. I have tried packages like parallel, doMC, caret. In most cases, the mutipleCore operation should be based on loops. However, there is no loop in my script, is it still possible to run with multiple cores?
This is how my original script looks like. It works fine with one core.
inFile = "filename" # A very BIG file
myFunction <- function(File){
...
igraph(data) # A few time-consuming functions, very SLOW.
spinglass(graph1)
...
}
myFunction(inFile)
This is how I try to use multiple cores:
library(parallel)
library(doMC)
library(caret)
inFile = "filename"
myFunction <- function(File){
...
igraph()
...
}
mclapply(inFile, myFunction, mc.cores = 4)
In mclapply(x,func,..)
, X is supposed to be a list. In my script, I try to use the inFile name as the only element in the list. However, it only uses one core.
PS: I run the script in the terminal instead of GUI.