[英]Parallel computing using `mclapply` in R, Linux
How to convert the code below to perform parallel jobs on 5 cores?如何转换下面的代码以在 5 个内核上执行并行作业?
From serial processing从串行处理
nfac=length(values)
n=10
for (i in 1:5){
system(sprintf('./tools/siteLevelFLUXNET/morris/%s/prep_model_params.sh %s %s %s',i,nfac,n))
}
to Parallel processing并行处理
system(sprintf('./tools/siteLevelFLUXNET/morris/1/prep_model_params.sh %s %s %s',nfac,n)) on core 1
.
.
.
system(sprintf('./tools/siteLevelFLUXNET/morris/5/prep_model_params.sh %s %s %s',nfac,n)) on core 5
On the command terminal this can be performed using &
between 2 codes, but I require nfac
and n
to be read from R在命令终端上,这可以使用两个代码之间的
&
来执行,但我需要从 R 读取nfac
和n
Are you looking for something like this,您是否正在寻找这样的东西,
library(parallel)
nfac=length(values)
n=10
# define a function
fun_i<-function(i)
{
return(system(sprintf('./tools/siteLevelFLUXNET/morris/%s/prep_model_params.sh %s %s %s',i,nfac,n)))
}
do.call("cbind", mclapply(X=1:5,FUN = function(X)fun_i(X),mc.cores=5))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.