LOCAL <- identical(Sys.getenv("LOCAL"), "true") knitr::opts_chunk$set( purl = LOCAL, collapse = TRUE, comment = "#>", fig.width = 6 )
This document discusses parallelization options for this package. Because the full analysis can involve many independent calculations (esp. at the step of identifying the pairwise interactions), taking advantage of the ability to run code in parallel can speed things up.
To facilitate different computer setups, we use the future
package, which enables the user to define the parallelization setup.
library(portalDS) library(drake) options(drake_make_menu = FALSE, drake_clean_recovery_msg = FALSE)
Setup the data and compute simplex results.
data("block_3sp", package = "rEDM") block <- setNames(block_3sp[, c("time", "x_t", "y_t", "z_t")], c("time", "x", "y", "z")) simplex_results <- compute_simplex(block = block, E_list = 3:5, surrogate_method = "random_shuffle", num_surr = 20, id_var = "time")
# future::plan(NULL) tictoc::tic() ccm_results <- compute_ccm(simplex_results, lib_sizes = seq(10, 100, by = 10), random_libs = TRUE, num_samples = 10, replace = TRUE, RNGseed = 42, silent = TRUE) tictoc::toc()
future.callr
.future::plan(future.callr::callr) tictoc::tic() ccm_results_parallel <- compute_ccm(simplex_results, lib_sizes = seq(10, 100, by = 10), random_libs = TRUE, num_samples = 10, replace = TRUE, RNGseed = 42, silent = TRUE) tictoc::toc()
my_plan <- drake_plan(ccm_results_drake = compute_ccm(simplex_results, lib_sizes = seq(10, 100, by = 10), random_libs = TRUE, num_samples = 10, replace = TRUE, RNGseed = 42, silent = TRUE) ) future::plan(future.callr::callr) tictoc::tic() clean(destroy = TRUE, force = TRUE) make(my_plan) tictoc::toc()
Check that the calculations are the same. (Note that the call to compute_ccm
is setup to do random subsampling, but we supply a fixed seed so that the random subsamples are selected identically across runs and for each pair of variables.)
identical(ccm_results, ccm_results_parallel)
ccm_results_drake <- readd(ccm_results_drake) identical(ccm_results, ccm_results_drake)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.