Commit 17a22ea8 authored by Marco De Lucia's avatar Marco De Lucia
Browse files

parallelization in ReactTrans* should now be platform-independent

parent 7410300f
Package: RedModRphree
Title: R infrastructure for training and applying geochemical surrogate models to reactive transport
Version: 0.0.2
Title: R infrastructure for training and applying geochemical surrogate models to reactive transport.
Version: 0.0.3
Authors@R: c(person("Marco", "De Lucia", email = "delucia@gfz-potsdam.de", role = c("aut", "cre")),
person("Janis", "Jatnieks", email = "deltaxzz@gmail.com", role = c("ctb")))
Description: In the framework of RedMod project, we develop an R infrastructure for training and applying geochemical surrogate models to reactive transport.
......
## Functions for dealing with surrogate simulations
### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2018
### Time-stamp: "Last modified 2018-05-17 16:11:49 delucia"
### Time-stamp: "Last modified 2018-05-18 16:19:39 delucia"
##' Todo
......@@ -303,6 +303,10 @@ ReactTranspBalanceEq <- function(setup, init, maxtime, step=c("time","iter","fix
if (procs > 1) {
parallel::clusterCall(cl=ThisRunCluster, phreeqc::phrLoadDatabaseString, db)
msg("Database loaded on each worker.")
if (surrogate) {
parallel::clusterExport(cl=ThisRunCluster, varlist=c("model","surrogate.FUN"), envir = environment())
msg("All workers are setup with the surrogate model.")
}
}
if (missing(init)) {
......@@ -605,6 +609,11 @@ ReactTranspBalanceKin <- function(setup, init, maxtime, step=c("time","iter","fi
msg("database loaded.")
if (procs > 1) {
parallel::clusterCall(cl=ThisRunCluster, phreeqc::phrLoadDatabaseString, db)
if (surrogate) {
parallel::clusterExport(cl=ThisRunCluster, varlist=c("model","surrogate.FUN"), envir = environment())
msg("All workers are setup with the surrogate model.")
}
}
if (missing(init)) {
msg("missing initial chemical state")
......
......@@ -74,7 +74,7 @@ sam <- ExtractSamples(list(sim50, sim100, sim200),
## this is how you can import those data without running the whole thing
## sam <- list(
## design = data.matrix(data.table::fread(file = system.file("extdata", "demo_equilibrium_design.csv", package="RedModRphree")))
## design = data.matrix(data.table::fread(file = system.file("extdata", "demo_equilibrium_design.csv", package="RedModRphree"))),
## result = data.matrix(data.table::fread(file = system.file("extdata", "demo_equilibrium_result.csv", package="RedModRphree")))
## )
......@@ -84,7 +84,7 @@ baleq <- list(Calcite=c(C=1, Ca=1), Dolomite=c(C=2, Ca=1, Mg=1))
balance <- CheckBalance(baleq, sam$design, sam$result)
set.seed(95014)
fitControl <- trainControl(method = "cv", number=5,
fitControl <- trainControl(method = "none",
allowParallel = TRUE,
returnData = FALSE,
returnResamp="none",
......@@ -96,7 +96,7 @@ fitControl <- trainControl(method = "cv", number=5,
traintime <- system.time({
mods <- parallel::mclapply(colnames(sam$result), function (x)
return(train(x=sam$design, y=sam$result[,x],trControl = fitControl,
method="parRF")), mc.cores=4)
method="parRF")), mc.cores=7)
names(mods) <- colnames(sam$result)
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment