uwesterr / CoronaPredict

With AdMOS develop a shiny app to predict corona progress
1 stars 2 forks source link

check whether parallel parameter for ga speeds up computation #153

Closed uwesterr closed 4 years ago

uwesterr commented 4 years ago

right now it takes about 7h to run optimizingChain.R as cronjob. the parameter parallel is set to 4. at https://cran.r-project.org/web/packages/GA/vignettes/GA.html#parallel-computing there is a test for different settings of that parameter.

running the test


library(GA)
fitness <- function(x)
{
  Sys.sleep(0.01)
  x*runif(1)
}

library(rbenchmark)
maxiter <- 10
out <- benchmark(
  GA1 = ga(type = "real-valued", 
           fitness = fitness, lower = 0, upper = 1,
           popSize = 50, maxiter = maxiter, monitor = FALSE,
           seed = 12345),
  GA2 = ga(type = "real-valued", 
           fitness = fitness, lower = 0, upper = 1,
           popSize = 50, maxiter = maxiter, monitor = FALSE,
           seed = 12345, parallel = TRUE),
  GA3 = ga(type = "real-valued", 
           fitness = fitness, lower = 0, upper = 1,
           popSize = 50, maxiter = maxiter, monitor = FALSE,
           seed = 12345, parallel = 4),
  GA4 = ga(type = "real-valued", 
           fitness = fitness, lower = 0, upper = 1,
           popSize = 50, maxiter = maxiter, monitor = FALSE,
           seed = 12345, parallel = "snow"),
  columns = c("test", "replications", "elapsed", "relative"),
  order = "test", 
  replications = 10)

logged into the RStudio server gets the following result

test replications elapsed relative 1 GA1 10 41.724 2.367 2 GA2 10 17.630 1.000 3 GA3 10 23.835 1.352 4 GA4 10 157.097 8.911

and shows that with 4 cores the computation is almost twice as fast as without parallelisation.