入れ子のループをforeachで並列コードに変換しようとしています。私はこれを行う方法を理解していません。 私のコードに従ってください: あらかじめ全員に感謝!R:foreachと並行して変更のためにネストされたループ
ここsetwd("simul")
IntervalTime <- c(10,15,20)
ThinIntesity <- c(10,15,20,25)
MINSTOCKGROW <- c(200,250,300)
meteoScen <- c("rcp4p5", "rcp8p5")
Co2mod <- c("CO2_rcp4p5", "CO2_rcp8p5")
fileSettings <- c("set_co2_on_man_off.txt", "set_co2_on_man_on.txt")
mapUnc <- data.frame()
uncerOut <- data.frame()
mapUncNoMan <- data.frame()
validation <- list()
Sample <- getSample(resDE,thin=700,start=0.3*niter,coda=F)
nSample <- nrow(Sample)
ValidationOutput <- "./output/"
#FOR MANAGEMENT CASES
全てのランモデル
ための並列のコードが、私は異なる方法を試みたが、唯一のコア作業for (i in 1:length(IntervalTime)){
for(p in 1:length(MINSTOCKGROW)){
for (j in 1:length(ThinIntesity)){
for(z in 1:length(meteoScen)){
for (k in 1:nSample){
# MAP BAYESIAN REFERENCE
ps <- createMixWithDefaults(pars = Sample[k, ],defaults = paramDefault, parind)
if (meteoScen[z]=="M45"){
#running the model
unlink(list.files("./output/Validation",full.names = TRUE),recursive=TRUE)
validation <- run3DCMCC(modelrun)
validation$annual$MINSTOCKGROW <- MINSTOCKGROW[p]
validation$annual$Management <- paste0(meteoScen[z],"_","IV_",IntervalTime[i],"_","IT_",ThinIntesity[j])
validation$annual$CODE <- paste0(meteoScen[z],"_","IV_",IntervalTime[i],"_","IT_",ThinIntesity[j],"_",MINSTOCKGROW[p],"_",validation$annual$YEAR)
validation$annual$Thinintensity <- ThinIntesity[j]
validation$annual$intervTime <- IntervalTime[i]
validation$annual$Meteo <- meteoScen[z]
validation$annual$Manage <- "MANAGEMENT"
validation$annual$Harv_Wood <- cumsum(validation$annual$C_HW)
validation$annual$StockCarbon <- validation$annual$Harv_Wood+validation$annual$STANDING_WOOD
# validation$monthly$Date <- as.yearmon(paste0(validation$monthly$YEAR, "-", validation$monthly$MONTH))
# validation$monthly$Management <- paste0("METEO_",meteoScenario[z],"INTERVAL_",IntervalTime[i],"INTENSITY_",ThinIntesity[j])
validationDF <- data.frame(validation$annual)
write.table(validationDF, paste0("./dataOut/",meteoScen[z],"_IV_",IntervalTime[i],"_IT_",ThinIntesity[j],"_MINSTCK_",MINSTOCKGROW[p],"_MAN_ON",".txt"),quote = F, sep = "\t",row.names = F,col.names = T)
mapUnc <- rbind(mapUnc, validation$annual)
} else {
条件ネストされたループの内側
ps <- createMixWithDefaults(pars = Sample[k, ],defaults = paramDefault,parind)
#running the model
unlink(list.files("./output/",full.names = TRUE),recursive=TRUE)
validation <- run3DCMCC(modelrun)
validation$annual$MINSTOCKGROW <- MINSTOCKGROW[p]
validation$annual$Management <- paste0(meteoScen[z],"_","IV_",IntervalTime[i],"_","IT_",ThinIntesity[j])
validation$annual$CODE <- paste0(meteoScen[z],"_","IV_",IntervalTime[i],"_","IT_",ThinIntesity[j],"_",validation$annual$YEAR)
validation$annual$Thinintensity <- ThinIntesity[j]
validation$annual$intervTime <- IntervalTime[i]
validation$annual$Meteo <- meteoScen[z]
validation$annual$Manage <- "MANAGEMENT"
validation$annual$Harv_Wood <- cumsum(validation$annual$C_HW)
validation$annual$StockCarbon <- validation$annual$Harv_Wood+validation$annual$STANDING_WOOD
validationDF <- data.frame(validation$annual)
write.table(validationDF, paste0("./dataOut/",meteoScen[z],"_","IV_",IntervalTime[i],"_","IT_",ThinIntesity[j],"_MAN_ON",".txt"),quote = F, sep = "\t",row.names = F,col.names = T)
rbind
mapUnc <- rbind(mapUnc, validation$annual)
}
}
}
}
}
}