如何使EpiModel在R中的多核上运行?

如何使EpiModel在R中的多核上运行?,r,multiprocessing,R,Multiprocessing,我正在用EpiModel在R中建模一个相当大的网络,代码需要很长时间才能运行,所以我想在多个核上运行它,而不是只在1个核上运行。我认为这在EpiModel本身中是可能的,但当我尝试它时,我的代码只是在不启动模拟的情况下继续运行。这是我正在使用的代码: library(EpiModel) library(parallel) nw <- network::network.initialize(n=6000, directed=FALSE) formation <- ~edges + c

我正在用EpiModel在R中建模一个相当大的网络,代码需要很长时间才能运行,所以我想在多个核上运行它,而不是只在1个核上运行。我认为这在EpiModel本身中是可能的,但当我尝试它时,我的代码只是在不启动模拟的情况下继续运行。这是我正在使用的代码:

library(EpiModel)
library(parallel)
nw <- network::network.initialize(n=6000, directed=FALSE)

formation <- ~edges + concurrent
target.stats<-c(1500, 600)
coef.diss <- dissolution_coefs(dissolution=~offset(edges), duration = 1)
est <- netest(nw, formation, target.stats, coef.diss)


dx<-netdx(est, nsims=10, nsteps=122, dynamic=FALSE, ncores=4)

init <- init.net(i.num=1, r.num=0)
param <-param.net(inf.prob=0.55, act.rate=0.6, rec.rate=0.05) 
control<-control.net(type='SIR', nsteps= 122, nsims =10, ncores=4)
mainsim <- netsim(est, param, init, control)
plot(mainsim, y='si.flow')
库(EpiModel)
图书馆(平行)

nw似乎EpiModel软件包使用了
doParallel
而不是
并行
软件包。你安装了吗?@BaltazarGonzálezChávez我没有安装它,所以我安装并加载了它,但不幸的是它仍然不能工作。坦白说,我没有看到你的代码中有任何错误。但是有一些想法可能会有所帮助:最明显的:1:你检查过你的机器有超过1个内核吗?一个函数是
doParallel::detectCores()
。2:在停止代码之前,您要等待多长时间?有时使用大数据时,在核心之间拆分数据所需的时间比预期的要长。我遇到过这样的情况,即在核心之间分配数据比分析本身慢(但数据量小,矩阵为200k左右)。