knitr::opts_chunk$set( echo = TRUE, eval = TRUE, # Change this later! message = FALSE, warning = FALSE, fig.width = 7, fig.height = 4 )
See https://doi-usgs.github.io/EGRET/articles/parallel.html for an introduction to running in parallel in EGRET. These directions supplement that article for EGRETci
functions.
library(EGRET) library(EGRETci) library(parallel) library(doParallel) eList <- Choptank_eList nCores <- detectCores(logical = FALSE) - 2 # leave a core or two out nCores <- max(c(nCores, 1)) nCores
A generalized workflow uses the doParallel
package:
cl <- parallel::makeCluster(nCores) doParallel::registerDoParallel(cl) eList <- modelEstimation(eList, verbose = FALSE, run.parallel = TRUE) parallel::stopCluster(cl)
nBoot <- 20 # Let's make sure things run with a small nBoot # but bump up later! blockLength <- 200 repAnnualResults <- vector(mode = "list", length = nBoot) for(n in 1:nBoot){ annualResults <- bootAnnual(eList, blockLength, startSeed = n, verbose = FALSE) repAnnualResults[[n]] <- annualResults } CIAnnualResults <- ciBands(eList, repAnnualResults) plotConcHistBoot(eList, CIAnnualResults)
cl <- parallel::makeCluster(nCores) doParallel::registerDoParallel(cl) repAnnual <- foreach(n = 1:nBoot, .packages=c('EGRETci', 'EGRET')) %dopar% { annualResults <- bootAnnual(eList, blockLength, startSeed = n, verbose = FALSE) } parallel::stopCluster(cl) CIAnnualResults_p <- ciBands(eList, repAnnual) plotConcHistBoot(eList, CIAnnualResults_p)
year1 <- 1985 year2 <- 2010 pairOut_2 <- runPairs(eList, year1, year2, windowSide = 11, verbose = FALSE) boot_pair_out <- runPairsBoot(eList, pairOut_2, nBoot = nBoot) plotHistogramTrend(eList = eList, eBoot = boot_pair_out, xMin = -5, xMax = 60, xStep = 5, caseSetUp = NA)
cl <- parallel::makeCluster(nCores) doParallel::registerDoParallel(cl) boot_pair_out <- runPairsBoot(eList, pairOut_2, nBoot = nBoot, run.parallel = TRUE) parallel::stopCluster(cl)
plotHistogramTrend(eList = eList, eBoot = boot_pair_out, xMin = -5, xMax = 60, xStep = 5, caseSetUp = NA)
groupResults <- runGroups(eList, group1firstYear = 1995, group1lastYear = 2004, group2firstYear = 2005, group2lastYear = 2014, windowSide = 7, wall = TRUE, sample1EndDate = "2004-10-30", paStart = 4, paLong = 2, verbose = FALSE) boot_group_out <- runGroupsBoot(eList, groupResults, nBoot = nBoot)
cl <- parallel::makeCluster(nCores) doParallel::registerDoParallel(cl) boot_group_out <- runGroupsBoot(eList = eList, groupResults = groupResults, nBoot = nBoot, run.parallel = TRUE) parallel::stopCluster(cl)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.