1

ラップトップで並列処理を使用して、R で NetLogo シミュレーション (RNetLogo パッケージを使用) を実行しようとしています。私は、3 つ (つまり、0、25、および 50) の異なる「最小分離」値を使用して、「雌の t 給餌」を評価しようとしています。「最小分離」値ごとに、シミュレーションを 10 回繰り返したいと思います。を使用するだけですべてを正しく実行できますlapplyが、問題が発生していparLapplyます。パッケージ「parallel」を使い始めたばかりなので、構文に何かあると確信しています。

#Set up clusters for parallel
processors <- detectCores()
cl <- makeCluster(processors)

#Simulation
sim3 <- function(min_sep) {
 NLCommand("set minimum-separation ", min_sep, "setup")
 ret <- NLDoReport(720, "go", "[t-feeding] of females", as.data.frame=TRUE)
 tot <- sum(ret[,1])
 return(tot)
}  

#Replicate simulations 10 times using lapply and create boxplots.  This one works.
rep.sim3 <- function(min_sep, rep) {
 return(
 lapply(min_sep, function(min_sep) {
 replicate(rep, sim3(min_sep))
 })
 )
}
d <- seq(0,50,25)
res <- rep.sim3(d,10)
boxplot(res,names=d, xlab="Minimum Separation", ylab="Time spent feeding")

#Replicate simulations 10 times using parLapply.  This one does not work.
rep.sim3 <- function(min_sep, rep) {
 return(
 parLapply(cl, min_sep, function(min_sep) {
 replicate(rep, sim3(min_sep))
 })
 )
}
d <- seq(0,50,25)
res <- rep.sim3(d,10)

# Error in checkForRemoteErrors(val) : 3 nodes produced errors; first error: could not find function "sim3"

#Replicate simulations 10 times using parLapply.  This one does work but creates a list of the wrong length and therefore the boxplot cannot be plotted correctly.
rep.sim3 <- function(min_sep, rep) {
 return(
 parLapply(cl, replicate(rep, d), sim3))
}
d <- seq(0,50,25)
res <- rep.sim3(d,10)

parLapply理想的には、最初の作品を作りたいと思っています。または、リストの長さが 30 ではなく になるように、動作するresものから変更できると思います。ただし、それはできないようです。どんな助けでも大歓迎です!parLapplymax_sep

前もって感謝します。

4

1 に答える 1