Skip to content
Snippets Groups Projects
Commit 56aa5737 authored by Marco De Lucia's avatar Marco De Lucia
Browse files

fixed merging

parents f9b05033 0c1c6389
No related branches found
No related tags found
No related merge requests found
Package: RedModRphree Package: RedModRphree
Title: R infrastructure for training and applying geochemical surrogate models to reactive transport Title: R infrastructure for training and applying geochemical surrogate models to reactive transport
Version: 0.0.1 Version: 0.0.2
Authors@R: c(person("Marco", "De Lucia", email = "delucia@gfz-potsdam.de", role = c("aut", "cre")), 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"))) 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. Description: In the framework of RedMod project, we develop an R infrastructure for training and applying geochemical surrogate models to reactive transport.
Depends: R (>= 3.2.0), parallel, plyr, data.table, phreeqc, caret, mgcv, randomForest, graphics, methods Depends: R (>= 3.2.0), doParallel, plyr, data.table, phreeqc, caret, mgcv, randomForest, graphics, methods
License: LGPL-2.1 License: LGPL-2.1
Encoding: UTF-8 Encoding: UTF-8
LLazyData: true LLazyData: true
......
## Functions for dealing with simulations with kinetics ## Functions for dealing with simulations with kinetics
### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2018 ### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2018
### Time-stamp: "Last modified 2018-05-04 20:47:46 delucia" ### Time-stamp: "Last modified 2018-05-16 16:45:40 delucia"
##' This function just runs the generated input buffer - or a list ##' This function just runs the generated input buffer - or a list
##' thereof - through \code{phreeqc}. Obviously it requires the ##' thereof - through \code{phreeqc}. Obviously it requires the
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
##' RPhreeFile("phreeqc.dat", is.db=TRUE ))} ##' RPhreeFile("phreeqc.dat", is.db=TRUE ))}
##' ##'
##' Currently parallelization is achieved using ##' Currently parallelization is achieved using
##' \code{parallel::mclapply}, this can change in the future. At the ##' \code{parallel::parLapply}, this can change in the future. At the
##' moment the function doesn't check that the SELCTED_OUTPUT block is ##' moment the function doesn't check that the SELCTED_OUTPUT block is
##' well-formed, so this is responsibility of the user. ##' well-formed, so this is responsibility of the user.
##' @title Run the generated input buffer using phreeqc ##' @title Run the generated input buffer using phreeqc
...@@ -47,8 +47,10 @@ RunPQC <- function(input, procs=1) { ...@@ -47,8 +47,10 @@ RunPQC <- function(input, procs=1) {
} }
} else { } else {
## go parallel! ## go parallel!
## call to parallel::mclapply
res <- parallel::mclapply(input, .runPQC, mc.silent=TRUE, mc.cores=procs) ## old one
## res <- parallel::mclapply(input, .runPQC, mc.silent=TRUE, mc.cores=procs)
res <- parallel::parLapply(input, .runPQC)
## a is the string containing the rbind of each element of the list ## a is the string containing the rbind of each element of the list
a <- paste("rbind(",paste("res[[",1:procs,"]]",sep="", collapse = ", "),")") a <- paste("rbind(",paste("res[[",1:procs,"]]",sep="", collapse = ", "),")")
......
## Functions for dealing with surrogate simulations ## Functions for dealing with surrogate simulations
### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2018 ### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2018
### Time-stamp: "Last modified 2018-05-04 20:35:35 delucia" ### Time-stamp: "Last modified 2018-05-16 16:56:49 delucia"
##' Todo ##' Todo
...@@ -223,7 +223,7 @@ ReactTranspBalanceEq <- function(setup, init, maxtime, step=c("time","iter","fix ...@@ -223,7 +223,7 @@ ReactTranspBalanceEq <- function(setup, init, maxtime, step=c("time","iter","fix
surrogate.FUN, model, baleq, tol=1E-9, call_pqc=TRUE) surrogate.FUN, model, baleq, tol=1E-9, call_pqc=TRUE)
{ {
require(doParallel)
if (surrogate) { if (surrogate) {
if (missing(surrogate.FUN)) if (missing(surrogate.FUN))
stopmsg("Need a valid function to apply surrogate instead of chemistry") stopmsg("Need a valid function to apply surrogate instead of chemistry")
...@@ -243,6 +243,12 @@ ReactTranspBalanceEq <- function(setup, init, maxtime, step=c("time","iter","fix ...@@ -243,6 +243,12 @@ ReactTranspBalanceEq <- function(setup, init, maxtime, step=c("time","iter","fix
immobile <- setup$immobile immobile <- setup$immobile
initsim <- setup$initsim initsim <- setup$initsim
if (procs > 1) {
registerDoParallel(procs)
msg("Registered default doParallel cluster with ", procs, "nodes")
}
cl <- getDefaultCluster()
n <- setup$n n <- setup$n
L <- setup$len # m L <- setup$len # m
U <- setup$U # m3/s U <- setup$U # m3/s
...@@ -460,6 +466,7 @@ ReactTranspBalanceEq <- function(setup, init, maxtime, step=c("time","iter","fix ...@@ -460,6 +466,7 @@ ReactTranspBalanceEq <- function(setup, init, maxtime, step=c("time","iter","fix
} }
on.exit() on.exit()
msg("total time of chemistry: ",round(sum(timing[,3]),3),"seconds") msg("total time of chemistry: ",round(sum(timing[,3]),3),"seconds")
msg("total number of simulations: ",sum(timing[,1])) msg("total number of simulations: ",sum(timing[,1]))
msg(" Bye.") msg(" Bye.")
...@@ -524,7 +531,12 @@ ReactTranspBalanceKin <- function(setup, init, maxtime, step=c("time","iter","fi ...@@ -524,7 +531,12 @@ ReactTranspBalanceKin <- function(setup, init, maxtime, step=c("time","iter","fi
kin <- setup$kin kin <- setup$kin
initsim <- setup$initsim initsim <- setup$initsim
ann <- setup$ann ann <- setup$ann
if (procs > 1) {
registerDoParallel(procs)
msg("Registered default doParallel cluster with ", procs, "nodes")
}
n <- setup$n n <- setup$n
L <- setup$len # m L <- setup$len # m
U <- setup$U # m3/s U <- setup$U # m3/s
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2018 ### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2018
### Janis Jatnieks, janisj@gfz-potsdam.de, jatnieks@janis.es ### Janis Jatnieks, janisj@gfz-potsdam.de, jatnieks@janis.es
### Time-stamp: "Last modified 2018-05-16 16:31:53 delucia" ### Time-stamp: "Last modified 2018-05-09 01:07:22 delucia"
### Licence: LGPL version 2.1 ### Licence: LGPL version 2.1
## resolve dependencies automatically ## resolve dependencies automatically
...@@ -25,16 +25,14 @@ start_up <- function(session_path=FALSE, ## to disable set to a non-string ...@@ -25,16 +25,14 @@ start_up <- function(session_path=FALSE, ## to disable set to a non-string
"cluster","stringr","gtools", #"ftsa", "cluster","stringr","gtools", #"ftsa",
"amap"), "amap"),
install=TRUE, install=TRUE,
use_cores=1) use_cores=4)
{ {
gc() gc()
if (Sys.info()[['sysname']]=="Linux") { msg("loading doParallel")
cat("\nYou are not on Windows, loading doMC!\n") list.of.packages = c(list.of.packages,"doParallel")
list.of.packages = c(list.of.packages,"doMC")
}
## ## load session data first ## load session data first
## if (class(session_path)[1]=="character" & file.exists(session_path) ) { ## if (class(session_path)[1]=="character" & file.exists(session_path) ) {
## msg("Loading...",session_path) ## msg("Loading...",session_path)
## load(session_path, .GlobalEnv) ## load(session_path, .GlobalEnv)
...@@ -57,11 +55,8 @@ start_up <- function(session_path=FALSE, ## to disable set to a non-string ...@@ -57,11 +55,8 @@ start_up <- function(session_path=FALSE, ## to disable set to a non-string
loadsuccess <- lapply(list.of.packages, require, character.only=TRUE) loadsuccess <- lapply(list.of.packages, require, character.only=TRUE)
if (!Sys.info()[["sysname"]]=="Windows") { msg("Registering parallelization with ", use_cores, "cores")
cat(":: Registering parallelization with ", use_cores, "cores\n") registerDoParallel( use_cores ) ## set up parallelization
registerDoMC( use_cores ) ## set up parallelization
}
### MDL: some global definitions ### MDL: some global definitions
## we use this to swich calls between Dice and caret or direct calls ## we use this to swich calls between Dice and caret or direct calls
...@@ -493,12 +488,9 @@ FastClust <- function(dfrm, clustnum=7, g=TRUE, link_type="complete") { ...@@ -493,12 +488,9 @@ FastClust <- function(dfrm, clustnum=7, g=TRUE, link_type="complete") {
##' @export ##' @export
safe_get_cores <- function() { safe_get_cores <- function() {
## register parallelization backends on anyhing but win, due to missing fork() ## register parallelization backends on anyhing but win, due to missing fork()
if ( !.Platform$OS.type=='windows') { require(doParallel)
require(doMC) ## detect using
require(parallel) report_cores <- detectCores()
## detect using
report_cores = detectCores() }
else report_cores = 1
return( report_cores ) return( report_cores )
} }
...@@ -1986,14 +1978,14 @@ Train <- function(surrogate_types = c(), ...@@ -1986,14 +1978,14 @@ Train <- function(surrogate_types = c(),
## run only the preprocessing methods that have not been blacklisted ## run only the preprocessing methods that have not been blacklisted
preprocessing_ind <- setdiff( preprocessing_ind, preprocessing_blacklist ) preprocessing_ind <- setdiff( preprocessing_ind, preprocessing_blacklist )
start_up( session_path = session_path, use_cores=use_cores) ## load libraries etc start_up( session_path = saved_simulation_data, use_cores=use_cores) ## load libraries etc
## if ( use_cores>0 ) { ## if ( use_cores>0 ) {
## if ( getDoParRegistered() ) { ## if ( getDoParRegistered() ) {
## cat("\nManually forcing",use_cores,"cores for parallelization!\n") ## cat("\nManually forcing",use_cores,"cores for parallelization!\n")
## registerDoMC( use_cores ) ## registerDoMC( use_cores )
## } ## }
## } else { cat("\nTried to set number of processing cores manually, but doMC does not appear to be loaded, ignoring!\n\n") } ## } else { cat("\nTried to set number of processing cores manually, but doParallel does not appear to be loaded, ignoring!\n\n") }
## cleanup, so no old data strs can affect new batch by mistake ## cleanup, so no old data strs can affect new batch by mistake
mrm( c("Tin","Oin","Oout","Cout","Fin","Fout","Tout","SRes","Sperf","valOUT","perftop","Residuals") ) mrm( c("Tin","Oin","Oout","Cout","Fin","Fout","Tout","SRes","Sperf","valOUT","perftop","Residuals") )
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment