1 #ifndef PARALLELMICOMPONENTFACTORY_H_
2 #define PARALLELMICOMPONENTFACTORY_H_
12 #include "spdlog/spdlog.h"
16 namespace SamplingAlgorithms {
38 if (
comm->GetRank() != 0) {
40 spdlog::trace(
"Parallel factory rank {} waiting...",
comm->GetRank());
42 spdlog::trace(
"Parallel factory rank {} received command",
comm->GetRank(), command);
46 spdlog::trace(
"Parallel factory rank {} passed finalize barrier",
comm->GetRank());
50 auto index = std::make_shared<MultiIndex>(
comm->Recv<MultiIndex>(0,
WorkgroupTag));
52 spdlog::trace(
"Parallel factory rank {} building model index {}",
comm->GetRank(), *index);
57 auto state = std::make_shared<SamplingState>(
comm->Recv<Eigen::VectorXd>(0,
WorkgroupTag));
62 auto state = std::make_shared<SamplingState>(
comm->Recv<Eigen::VectorXd>(0,
WorkgroupTag));
65 std::cerr <<
"Not implemented!!!" << std::endl;
72 std::cerr <<
"Unexpected command!" << std::endl;
87 if (
comm->GetRank() != 0)
89 spdlog::trace(
"Parallel factory sending finalize");
90 for (
int dest = 1; dest <
comm->GetSize(); dest++)
94 spdlog::trace(
"Parallel factory finalized");
97 virtual std::shared_ptr<MCMCProposal>
Proposal (std::shared_ptr<MultiIndex>
const& index, std::shared_ptr<AbstractSamplingProblem>
const& samplingProblem)
override {
105 virtual std::shared_ptr<MCMCProposal>
CoarseProposal (std::shared_ptr<MultiIndex>
const& fineIndex,
106 std::shared_ptr<MultiIndex>
const& coarseIndex,
107 std::shared_ptr<AbstractSamplingProblem>
const& coarseProblem,
108 std::shared_ptr<SingleChainMCMC>
const& coarseChain)
override {
109 return componentFactory->CoarseProposal(fineIndex, coarseIndex, coarseProblem, coarseChain);
112 virtual std::shared_ptr<AbstractSamplingProblem>
SamplingProblem (std::shared_ptr<MultiIndex>
const& index)
override {
114 if (
comm->GetRank() == 0) {
115 spdlog::debug(
"Rank {} requesting model {} from parallel factory",
comm->GetRank(), *index);
116 for (
int dest = 1; dest <
comm->GetSize(); dest++) {
126 virtual std::shared_ptr<MIInterpolation>
Interpolation (std::shared_ptr<MultiIndex>
const& index)
override {
130 virtual Eigen::VectorXd
StartingPoint (std::shared_ptr<MultiIndex>
const& index)
override {
136 std::shared_ptr<parcer::Communicator>
comm;
Interface defining models on a multiindex structure.
Wrapper for MIComponentFactory supporting parallel model setup.
virtual Eigen::VectorXd StartingPoint(std::shared_ptr< MultiIndex > const &index) override
virtual std::shared_ptr< MultiIndex > FinestIndex() override
std::shared_ptr< parcer::Communicator > comm
virtual std::shared_ptr< MIInterpolation > Interpolation(std::shared_ptr< MultiIndex > const &index) override
virtual std::shared_ptr< MCMCProposal > Proposal(std::shared_ptr< MultiIndex > const &index, std::shared_ptr< AbstractSamplingProblem > const &samplingProblem) override
virtual std::shared_ptr< MCMCProposal > CoarseProposal(std::shared_ptr< MultiIndex > const &fineIndex, std::shared_ptr< MultiIndex > const &coarseIndex, std::shared_ptr< AbstractSamplingProblem > const &coarseProblem, std::shared_ptr< SingleChainMCMC > const &coarseChain) override
virtual std::shared_ptr< AbstractSamplingProblem > SamplingProblem(std::shared_ptr< MultiIndex > const &index) override
std::shared_ptr< parcer::Communicator > global_comm
ParallelMIComponentFactory(std::shared_ptr< parcer::Communicator > comm, std::shared_ptr< parcer::Communicator > global_comm, std::shared_ptr< MIComponentFactory > componentFactory)
virtual bool IsInverseProblem() override
std::shared_ptr< MIComponentFactory > componentFactory
void finalize()
Stops worker processes command loop, freeing them for other tasks.
std::map< int, std::shared_ptr< AbstractSamplingProblem > > samplingProblems
ControlFlag
Flags used by parallel MCMC/MIMCMC type methods.