Doxygen 1.9.1
Toolkit for Adaptive Stochastic Modeling and Non-Intrusive ApproximatioN: Tasmanian v8.1
TasDREAM::DistributedPosterior< form > Class Template Reference

Class that enables distributed DREAM sampling with MPI. More...

#include <tsgMPISampleDream.hpp>

Public Member Functions

 DistributedPosterior (DreamModel distributed_model, DreamLikelihood likelihood, DreamPrior prior, int num_inputs, int num_chains, int mpi_root, MPI_Comm communicator)
 Constructor that sets the parameters for the distribued posterior. More...
 
 ~DistributedPosterior ()
 Destructor, unblocks the non-root ranks (if still blocked).
 
void clear ()
 Unblocks the non-root ranks, the object cannot be used after this calls (can be destroyed only).
 
 operator DreamPDF ()
 Allows passing the object as an input to TasDREAM::SampleDREAM().
 

Detailed Description

template<TypeSamplingForm form = regform>
class TasDREAM::DistributedPosterior< form >

Class that enables distributed DREAM sampling with MPI.

Models with many outputs are computationally expensive to sample when used in a Bayesian posterior. Such models can be distributed across ranks of an MPI communicator and the DREAM candidates can be computed in parallel, i.e., distributing the work. Of specific interest are posteriors with likelihood functions that can be expressed as a product (or sum) of one term per model outputs, e.g., constant or diagonal Gaussian likelihoods. The actual sampling is performed on a single rank while the values of the probability distribution at the candidate points is computed by all MPI ranks together (each ranks handling a separate set of inputs). The high-level algorithm can be expressed with two MPI calls, MPI_Bcast() all candidates to all ranks, then MPI_Reduce() the result. See TasGrid::MPIGridScatterOutputs() and TasDREAM::MPILikelihoodScatter() for ways to distribute a sparse grid model and a likelihood function.

The usage of this class is very similar to the calls to TasDREAM::posterior() template, the first two inputs are the local portions of the model and likelihood, followed by the prior which will only be used on the root rank. The other inputs define parameters of the MPI side of the algorithm. The constructor can be inlined in a call to TasDREAM::SampleDREAM().

MPI Synchronization
The call to the constructor will block all ranks except the root, all non-root ranks will enter into a worker cycle waiting for candidates from root. The root process will send-out the unblock signal to all workers whenever the root object is destroyed or the clear() method is called. The class can be passed as the probability distribution to TasDREAM::SampleDREAM(), but only the root rank can compute valid samples, the other ranks will use a no-op function. If SampleDREAM() is called with an empty TasmanianDREAM state then sampling will not be performed, thus the class should be coupled with an empty state on each of the non-root ranks; which helps mirror the code across all ranks and avoid extraneous if-statements. Here are some valid calls:
int me;
MPI_Comm_rank(MPI_COMM_WORLD, &me);
auto full_grid = TasGrid::readGrid("foo");
MPIGridScatterOutputs(full_grid, grid, root, 1, MPI_COMM_WORLD); // distribute the grid
MPILikelihoodScatter(full_likely, likely, root, 1, MPI_COMM_WORLD); // distribute the likelihood
TasDREAM::TasmanianDREAM state = (me == root) ? TasmanianDREAM(...) : TasmanianDREAM();
TasDREAM::SampleDREAM(..., DistributedPosterior(likely, grid, ..., root, ...), ..., state, ...);
DistributedPosterior(DreamModel distributed_model, DreamLikelihood likelihood, DreamPrior prior, int num_inputs, int num_chains, int mpi_root, MPI_Comm communicator)
Constructor that sets the parameters for the distribued posterior.
Definition: tsgMPISampleDream.hpp:133
Implements likelihood under the assumption of isotropic white noise.
Definition: tsgDreamLikelyGaussian.hpp:59
Contains the current state and the history of the DREAM chains.
Definition: tsgDreamState.hpp:70
The master-class that represents an instance of a Tasmanian sparse grid.
Definition: TasmanianSparseGrid.hpp:293
void SampleDREAM(int num_burnup, int num_collect, DreamPDF probability_distribution, DreamDomain inside, TasmanianDREAM &state, std::function< void(std::vector< double > &x)> independent_update=no_update, std::function< double(void)> differential_update=const_one, std::function< double(void)> get_random01=tsgCoreUniform01)
Core template for the sampling algorithm.
Definition: tsgDreamSample.hpp:414
int MPILikelihoodScatter(Likelihood const &source, Likelihood &destination, int root, int tag, MPI_Comm comm)
Split the likelihood across the comm where each rank receives an equal portion of the total outputs.
Definition: tsgMPIScatterDream.hpp:160
int MPIGridScatterOutputs(TasmanianSparseGrid const &source, TasmanianSparseGrid &destination, int root, int tag, MPI_Comm comm)
Split the grid across the comm where each rank receives an equal portion of the total outputs.
Definition: tsgMPIScatterGrid.hpp:276
TasmanianSparseGrid readGrid(const char *filename)
Factory method, creates a new grid and calls TasmanianSparseGrid::read().
Definition: TasmanianSparseGrid.hpp:2342

Alternatively, the object can also be assigned to a variable:

TasDREAM::DistributedPosterior post(likely, grid, ..., root, ...);
if (me == root) TasDREAM::SampleDREAM(..., post, ...); // the state on non-root ranks is irrelevant
post.clear(); // unblock the non-root ranks
Class that enables distributed DREAM sampling with MPI.
Definition: tsgMPISampleDream.hpp:112

Constructor & Destructor Documentation

◆ DistributedPosterior()

template<TypeSamplingForm form = regform>
TasDREAM::DistributedPosterior< form >::DistributedPosterior ( DreamModel  distributed_model,
DreamLikelihood  likelihood,
DreamPrior  prior,
int  num_inputs,
int  num_chains,
int  mpi_root,
MPI_Comm  communicator 
)
inline

Constructor that sets the parameters for the distribued posterior.

Constructs a distributed posterior object from local model and likelihood objects. See the class description for example usage, details on the parameters follow here:

Template Parameters
formis the same as in the call to TasDREAM::SampleDREAM() and both must match.
Parameters
distributed_modelis the local portion of the model, the sub-set of the outputs must match the set used by the likelihood.
likelihoodis the local portion of the likelihood. Same as in the call to TasDREAM::posterior().
priorwill be used only by the root rank, same as in the call to TasDREAM::posterior().
num_inputsmust match the dimensions of the state on the root rank, since the non-root ranks do not need a valid state this parameter is used to synchronize the dimensions across all ranks.
num_chainssame as the number set by the state, see the num_inputs.
mpi_rootis the root process that will perform the actual sampling.
communicatoris the communicator where all ranks reside.

The documentation for this class was generated from the following file: