Skip to contents

Runs multiple MCMC chains on a PSOCK cluster using a baseline NIMBLE configuration. The reported runtime follows the historic semantics used in samOptiPro: runtime_s measures only the wall-clock time spent inside nimble::runMCMC() across all chains, excluding model building, MCMC setup, and compilation.

Usage

run_baseline_config_parallel(
  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

Function that builds per-chain model objects (see Builder contract).

niter

Integer, total MCMC iterations.

nburnin

Integer, burn-in iterations.

thin

Integer, thinning interval.

monitors

Optional character vector of additional monitors to add.

nchains

Integer, number of chains to run.

seed

Integer, base seed; chain k uses seed + k - 1.

n_cores

Integer, number of PSOCK workers (defaults to nchains).

extra_export

Character vector of additional objects to export to workers.

samplesAsCodaMCMC

Logical; if TRUE, runMCMC() returns coda objects.

export_global

Logical; if TRUE export full .GlobalEnv (use with care).

opts

Optional samOptiPro options object (reserved for future use).

Value

A list with:

  • samples : list of samples (one element per chain; type depends on samplesAsCodaMCMC)

  • runtime_s : global wall time (seconds) for the parallel runMCMC() phase only

  • runtime_by_chain : per-chain wall time (seconds) for runMCMC() only

Details

Implementation notes:

  • Each worker calls build_fn() to build (and possibly compile) the model and MCMC configuration outside the timed section.

  • Each worker then builds + compiles the MCMC and runs nimble::runMCMC(); only the runMCMC() call is timed per chain.

  • The master records a global wall-clock time around the parallel runMCMC() phase (start just before parLapply(), stop after all chains return).

Builder contract:

  • build_fn() must work as either build_fn() or build_fn(chain_id = <int>, export_global = <logical>).

  • It must return a list containing at least:

    • model : an uncompiled nimbleModel (recommended; used for diagnostics)

    • cmodel : the compiled model (compileNimble(model))

    • conf : an MCMC configuration (e.g. from nimble::configureMCMC()) Optionally it may include monitors.