简体   繁体   中英

How to run DEoptim in parallel?

have developed a hydrological model in R, which has 8 parameters in the function, and I wish to calibrate the model using DEoptim. Due to the length of time it takes to run each function I would like to parallel-ise the DEoptim function as it has an option to run in parallel. The documentation suggests that this is set as follows:

DEctrl <- DEoptim.control(trace=TRUE,parallelType=1,packages=c(),parVar=c())
ans <- DEoptim(Calibrate,lower,upper,DEctrl)

If I run DEoptim without parallelisation then it works fine, but if I set the parallelType to 1 it fails with the following error:

Error in checkForRemoteErrors(val) : 
8 nodes produced errors; first error: could not find function "startyear"

I guess this is because I have not set parVar and packages in DEoptim.control but I don't really understand what they are asking for. I guess packages are the library modules that I load up front but not sure what parVar are. The documentation says parVar is a list of variable names (as strings) that need to exist in the environment for use by the objective function or are used as arguments by the objective function.

My code is 1500 lines long so I'm not sure which variable names I should include. The code is a series of sub functions - here is part of it:

library(DEoptim)
library(package = "hydromad")
library(maptools)
library(compiler)
#enableJIT(3)
library(tcltk)
library(raster)

Calibrate <- function(x) {
cmax <<- x[1]
Cr <<- x[2]
Cl <<- x[3]
Crb <<- x[4]
Clb <<- x[5]
returnflowriver <<- x[6]
returnflowland <<- x[7]
kd <<- x[8]
startyear()
-RSquaredboxcox
}

initialisemodel <- function() {
S1 <<- Sys.time()
# 1 Yangtze watershed inputs
# Load librarys
Starttime <- Sys.time()

Catchmentnum <- 1
# Set global parameters
Plothourlyrunoffswitch <- 0

cmin <<- 0.01
tempmelt <<- 1.5
tempsnow <<- 0.0
temprain <<- 1.5
DDFSnow <<- 4.1
DDFIce <<- 7.1

shiftcell <<- Resolution/3600

projstring <<- "+proj=longlat +datum=WGS84 +no_defs"

and so on.

So my question is, what should I include in parVar and packages ?

As you mention in your question, you need to use parVar and packages .

The packages vector should list any packages that you use, eg you use a random number generator that is found in another package.

The parVar vector should contain in functions or variables that are called by your code. So in your case,

parVar = "startyear"

I strongly suspect, that this will raise another error about another missing variable (which you should add to parVar and repeat the process).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM