micSimParallel: Run a microsimulation on several cores

View source: R/parallel.R

micSimParallelR Documentation

Run a microsimulation on several cores

Description

Splits the population across processor cores, runs micSim() on each, and recombines the results into one pop data frame.

Usage

micSimParallel(
  initPop = NULL,
  immigrPop = NULL,
  initPopList = list(),
  immigrPopList = list(),
  transitionMatrix,
  absStates = NULL,
  varInitStates = c(),
  initStatesProb = c(),
  fixInitStates = c(),
  maxAge = 99,
  simHorizon,
  fertTr = c(),
  monthSchoolEnrol = c(),
  cores = 1L,
  seeds = 1254L,
  verbose = TRUE
)

Arguments

initPop

Data frame describing the starting population; see micSim().

immigrPop

Data frame describing immigrants, or NULL.

initPopList, immigrPopList

Pre-computed splits, one list element per core. Supply these to control which individuals go to which core; otherwise the split is made automatically into near-equal chunks. Immigrants assigned to a core without a starting population are simulated on the first core that has one.

transitionMatrix, absStates, varInitStates, initStatesProb, fixInitStates

As in micSim().

maxAge, simHorizon, fertTr, monthSchoolEnrol

As in micSim().

cores

Number of processor cores to use.

seeds

Integer seed of the run, used by every worker.

verbose

Report progress through message().

Details

Individuals are independent of one another in MicSim's model, so simulating them in separate groups and concatenating the results is exactly equivalent to simulating them together.

Reproducibility. Every worker runs with the seed seeds, and every individual draws from their own L'Ecuyer-CMRG stream derived from it and their ID. The life courses are therefore the same on any number of cores and under any split; only the identifiers of newborns depend on the split (see Identifiers).

Identifiers. Each worker assigns newborn IDs starting above the largest ID in its own group, so different workers can assign the same ID to different newborns. When the results are combined, newborns receive consecutive IDs starting one above the larger of the highest supplied ID and the total number of people in the starting and immigrant populations. All supplied IDs are preserved.

Rate functions are exported to the workers along with everything else visible where micSimParallel() was called.

Value

The same data frame micSim() returns, for the whole population.

Deprecated

micSimParallel() is deprecated as of MicSim 4.0.0 and will be removed in a future release. It still works, and shows a message once per R session naming its replacement: build the model with micsim_model() and run it with simulate(model, seed = , cores = ) (simulate.micsim_model()). Set options(MicSim.show_deprecation = FALSE) to turn the message off.

See Also

micSim(), MicSim-concepts


MicSim documentation built on Dec. 2, 2026, 1:09 a.m.