model-method-sample_mpi | R Documentation |
The $sample_mpi()
method of a CmdStanModel
object is
identical to the $sample()
method but with support for
MPI (message passing interface). The target audience for MPI are
those with large computer clusters. For other users, the
$sample()
method provides both parallelization of
chains and threading support for within-chain parallelization.
In order to use MPI with Stan, an MPI implementation must be installed. For Unix systems the most commonly used implementations are MPICH and OpenMPI. The implementations provide an MPI C++ compiler wrapper (for example mpicxx), which is required to compile the model.
An example of compiling with MPI:
mpi_options = list(STAN_MPI=TRUE, CXX="mpicxx", TBB_CXX_TYPE="gcc") mod = cmdstan_model("model.stan", cpp_options = mpi_options)
The C++ options that must be supplied to the compile call are:
STAN_MPI
: Enables the use of MPI with Stan if TRUE
.
CXX
: The name of the MPI C++ compiler wrapper. Typically "mpicxx"
.
TBB_CXX_TYPE
: The C++ compiler the MPI wrapper wraps. Typically "gcc"
on Linux and "clang"
on macOS.
In the call to the $sample_mpi()
method it is also possible to provide
the name of the MPI launcher (mpi_cmd
, defaulting to "mpiexec"
) and any
other MPI launch arguments (mpi_args
). In most cases, it is enough to
only define the number of processes. To use n_procs
processes specify
mpi_args = list("n" = n_procs)
.
sample_mpi(
data = NULL,
mpi_cmd = "mpiexec",
mpi_args = NULL,
seed = NULL,
refresh = NULL,
init = NULL,
save_latent_dynamics = FALSE,
output_dir = getOption("cmdstanr_output_dir"),
output_basename = NULL,
chains = 1,
chain_ids = seq_len(chains),
iter_warmup = NULL,
iter_sampling = NULL,
save_warmup = FALSE,
thin = NULL,
max_treedepth = NULL,
adapt_engaged = TRUE,
adapt_delta = NULL,
step_size = NULL,
metric = NULL,
metric_file = NULL,
inv_metric = NULL,
init_buffer = NULL,
term_buffer = NULL,
window = NULL,
fixed_param = FALSE,
sig_figs = NULL,
show_messages = TRUE,
show_exceptions = TRUE,
diagnostics = c("divergences", "treedepth", "ebfmi"),
save_cmdstan_config = NULL,
validate_csv = TRUE
)
data |
(multiple options) The data to use for the variables specified in the data block of the Stan program. One of the following:
|
mpi_cmd |
(string) The MPI launcher used for launching MPI
processes. The default launcher is |
mpi_args |
(list) A list of arguments to use when launching MPI
processes. For example, |
seed |
(positive integer(s)) A seed for the (P)RNG to pass to CmdStan.
In the case of multi-chain sampling the single |
refresh |
(non-negative integer) The number of iterations between
printed screen updates. If |
init |
(multiple options) The initialization method to use for the variables declared in the parameters block of the Stan program. One of the following:
|
save_latent_dynamics |
(logical) Should auxiliary diagnostic information
about the latent dynamics be written to temporary diagnostic CSV files?
This argument replaces CmdStan's |
output_dir |
(string) A path to a directory where CmdStan should write
its output CSV files. For MCMC there will be one file per chain; for other
methods there will be a single file. For interactive use this can typically
be left at
|
output_basename |
(string) A string to use as a prefix for the names of
the output CSV files of CmdStan. If |
chains |
(positive integer) The number of Markov chains to run. The default is 4. |
chain_ids |
(integer vector) A vector of chain IDs. Must contain as many
unique positive integers as the number of chains. If not set, the default
chain IDs are used (integers starting from |
iter_warmup |
(positive integer) The number of warmup iterations to run
per chain. Note: in the CmdStan User's Guide this is referred to as
|
iter_sampling |
(positive integer) The number of post-warmup iterations
to run per chain. Note: in the CmdStan User's Guide this is referred to as
|
save_warmup |
(logical) Should warmup iterations be saved? The default
is |
thin |
(positive integer) The period between saved samples. This should typically be left at its default (no thinning) unless memory is a problem. |
max_treedepth |
(positive integer) The maximum allowed tree depth for the NUTS engine. See the Tree Depth section of the CmdStan User's Guide for more details. |
adapt_engaged |
(logical) Do warmup adaptation? The default is |
adapt_delta |
(real in |
step_size |
(positive real) The initial step size for the discrete approximation to continuous Hamiltonian dynamics. This is further tuned during warmup. |
metric |
(string) One of |
metric_file |
(character vector) The paths to JSON or Rdump files (one
per chain) compatible with CmdStan that contain precomputed inverse
metrics. The |
inv_metric |
(vector, matrix) A vector (if |
init_buffer |
(nonnegative integer) Width of initial fast timestep adaptation interval during warmup. |
term_buffer |
(nonnegative integer) Width of final fast timestep adaptation interval during warmup. |
window |
(nonnegative integer) Initial width of slow timestep/metric adaptation interval. |
fixed_param |
(logical) When |
sig_figs |
(positive integer) The number of significant figures used
when storing the output values. By default, CmdStan represent the output
values with 6 significant figures. The upper limit for |
show_messages |
(logical) When |
show_exceptions |
(logical) When |
diagnostics |
(character vector) The diagnostics to automatically check
and warn about after sampling. Setting this to an empty string These diagnostics are also available after fitting. The
Diagnostics like R-hat and effective sample size are not currently
available via the |
save_cmdstan_config |
(logical) When |
validate_csv |
Deprecated. Use |
A CmdStanMCMC
object.
The CmdStanR website (mc-stan.org/cmdstanr) for online documentation and tutorials.
The Stan and CmdStan documentation:
Stan documentation: mc-stan.org/users/documentation
CmdStan User’s Guide: mc-stan.org/docs/cmdstan-guide
The Stan Math Library's documentation (mc-stan.org/math) for more details on MPI support in Stan.
Other CmdStanModel methods:
model-method-check_syntax
,
model-method-compile
,
model-method-diagnose
,
model-method-expose_functions
,
model-method-format
,
model-method-generate-quantities
,
model-method-laplace
,
model-method-optimize
,
model-method-pathfinder
,
model-method-sample
,
model-method-variables
,
model-method-variational
## Not run:
# mpi_options <- list(STAN_MPI=TRUE, CXX="mpicxx", TBB_CXX_TYPE="gcc")
# mod <- cmdstan_model("model.stan", cpp_options = mpi_options)
# fit <- mod$sample_mpi(..., mpi_args = list("n" = 4))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.