Joh*_*son 6 parallel-processing multicore r mathematical-optimization integer-programming
我注意到 R 并没有使用我所有的 CPU,我想极大地增加它(向上到 100%)。我不希望它只是并行化几个函数;我希望 R 使用更多的 CPU 资源。我正在尝试使用 lp() 函数运行纯 IP 集打包程序。目前,我运行 Windows,并且我的计算机上有 4 个内核。
我曾尝试用雪、doParallel 和 foreach 进行试验(虽然我不知道我真的在用它们做什么)。
在我的代码中,我有这个......
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()
Run Code Online (Sandbox Code Playgroud)
R 卡住并运行 lp() 很长时间。我的 CPU 大约是 25%,但我怎样才能增加它?
如果您尝试并行运行 4 个不同的 LP,以下是在 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
Run Code Online (Sandbox Code Playgroud)
例如,sfClusterApply 中的函数可以包含您的 LP。
否则请参阅有关您的问题的评论