Run a baseline NIMBLE MCMC configuration in parallel (robust “large-model” variant)
Source:R/runners.R
run_baseline_config_parallel_bis.Rdrun_baseline_config_parallel_bis() is the large-model counterpart of
run_baseline_config_parallel(). It is designed to remain stable on very large
NIMBLE models (e.g., >80,000 nodes; WGNAS-scale) and on HPC/cluster environments,
where naïve PSOCK parallelization can trigger memory blow-ups or fail due to
missing closure bindings on workers.
Compared to the non-_bis function, this version:
supports resolving
build_fnby name (character) on workers, including optional namespace lookup;supports injecting
build_fnas text (opts$build_fn_text) and exporting the captured environment of the builder closure (opts$build_fn_object,opts$builder_env_names) to prevent errors like “objet 'hindcast_' introuvable”;avoids mandatory disk I/O (no log files required), suitable for clusters with restricted write access;
times only the MCMC execution phase (optionally using
$run(time=TRUE)), keeping compilation outside the per-chain runtime by construction;says memory: optional worker-side
gc()clean-up after each chain to reduce peak usage on large graphs;can optionally return the actual
nimbleMCMCconfused on each worker (opts$return_conf = TRUE) so downstream diagnostics can reuse the exact sampler/monitor configuration.
The function assumes that build_fn returns at least a list with model and conf
(plus optional monitors). The returned object includes samples, runtime_s,
runtime_by_chain, and sampler_times, and optionally conf_by_chain.
Usage
run_baseline_config_parallel_bis(
build_fn,
niter,
nburnin,
thin,
monitors = NULL,
nchains = 3L,
seed = 1L,
n_cores = nchains,
extra_export = character(0),
samplesAsCodaMCMC = FALSE,
export_global = FALSE,
opts = NULL
)Arguments
- build_fn
A builder function, or a single character string giving the builder name. The builder must return a list with at least
modelandconf.- niter, nburnin, thin
MCMC settings passed to NIMBLE.
- monitors
Optional monitor vector (if
NULL, may fall back toparts$monitors).- nchains
Number of parallel chains to run.
- seed
Base RNG seed (each chain uses
seed + chain_id - 1).- n_cores
Number of PSOCK workers.
- extra_export
Optional additional symbols to export to workers.
- samplesAsCodaMCMC
Passed to
nimble::runMCMC()fallback (when not using$run()).- export_global
If
TRUE, exports the whole master.GlobalEnv(not recommended unless needed).- opts
List of advanced options (cluster type, packages, builder injection, timings).
Value
A list with:
samples: list of per-chain samples (matrix or coda, depending on options),runtime_s: wall-clock time of the full parallel phase,runtime_by_chain: numeric vector of per-chain MCMC runtimes,sampler_times: list ofCmcmc$getTimes()outputs (if enabled),conf_by_chain: optional list ofnimbleMCMCconf(ifopts$return_conf = TRUE),opts_effective: the effective options used.