MUQ  0.4.3
ParallelFixedSamplesMIMCMC.h
Go to the documentation of this file.
1 #ifndef PARALLELFIXEDSAMPLESMIMCMC_H_
2 #define PARALLELFIXEDSAMPLESMIMCMC_H_
3 
4 #include "MUQ/config.h"
5 
6 #if MUQ_HAS_MPI
7 
8 #if !MUQ_HAS_PARCER
9 #error
10 #endif
11 
12 #include "spdlog/spdlog.h"
13 #include <boost/property_tree/ptree.hpp>
14 
18 
19 namespace muq {
20  namespace SamplingAlgorithms {
21 
28  public:
30  int numGroups;
32  };
33 
34  virtual void setup(std::shared_ptr<ParallelizableMIComponentFactory> componentFactory, uint availableRanks) = 0;
35 
39  virtual int numCollectors(std::shared_ptr<MultiIndex> modelIndex) = 0;
40 
44  virtual WorkerAssignment numWorkers(std::shared_ptr<MultiIndex> modelIndex) = 0;
45  };
46 
56  public:
57  void setup(std::shared_ptr<ParallelizableMIComponentFactory> componentFactory, uint availableRanks) override;
58 
59  int numCollectors(std::shared_ptr<MultiIndex> modelIndex) override;
60 
61  WorkerAssignment numWorkers(std::shared_ptr<MultiIndex> modelIndex) override;
62 
63  private:
66 
67  };
68 
82  public:
83  StaticLoadBalancingMIMCMC (pt::ptree pt,
84  std::shared_ptr<ParallelizableMIComponentFactory> componentFactory,
85  std::shared_ptr<StaticLoadBalancer> loadBalancing = std::make_shared<RoundRobinStaticLoadBalancer>(),
86  std::shared_ptr<parcer::Communicator> comm = std::make_shared<parcer::Communicator>(MPI_COMM_WORLD),
87  std::shared_ptr<muq::Utilities::OTF2TracerBase> tracer = std::make_shared<OTF2TracerDummy>());
88 
92  Eigen::VectorXd MeanQOI();
93 
97  virtual std::shared_ptr<SampleCollection> GetSamples() const;
98 
102  virtual std::shared_ptr<SampleCollection> GetQOIs() const;
103 
108  void Finalize();
109 
113  void RequestSamples(std::shared_ptr<MultiIndex> index, int numSamples);
114 
118  void RequestSamplesAll(int numSamples);
119 
127  void RunSamples();
128 
129  void WriteToFile(std::string filename);
130 
131 
132  protected:
133  virtual std::shared_ptr<SampleCollection> RunImpl(std::vector<Eigen::VectorXd> const& x0);
134 
135  private:
136 
137  std::string multiindexToConfigString (std::shared_ptr<MultiIndex> index);
138 
139  const int rootRank = 0;
140  const int phonebookRank = 1;
141  pt::ptree pt;
142  std::shared_ptr<parcer::Communicator> comm;
143  std::shared_ptr<ParallelizableMIComponentFactory> componentFactory;
144  std::shared_ptr<PhonebookClient> phonebookClient;
145  std::vector<CollectorClient> collectorClients;
147  };
148  }
149 }
150 
151 #endif // #if MUQ_HAS_MPI
152 #endif // #ifndef PARALLELFIXEDSAMPLESMIMCMC_H_
Simple default static load balancing strategy suitable for many cases.
WorkerAssignment numWorkers(std::shared_ptr< MultiIndex > modelIndex) override
Number of worker groups and number of workers per group for a given model index.
int numCollectors(std::shared_ptr< MultiIndex > modelIndex) override
Number of collector processes assigned to a model index.
void setup(std::shared_ptr< ParallelizableMIComponentFactory > componentFactory, uint availableRanks) override
Base class handling the static load balancing of parallel MIMCMC.
virtual void setup(std::shared_ptr< ParallelizableMIComponentFactory > componentFactory, uint availableRanks)=0
virtual WorkerAssignment numWorkers(std::shared_ptr< MultiIndex > modelIndex)=0
Number of worker groups and number of workers per group for a given model index.
virtual int numCollectors(std::shared_ptr< MultiIndex > modelIndex)=0
Number of collector processes assigned to a model index.
virtual std::shared_ptr< SampleCollection > RunImpl(std::vector< Eigen::VectorXd > const &x0)
void Finalize()
Cleanup parallel method, wait for all ranks to finish.
std::shared_ptr< ParallelizableMIComponentFactory > componentFactory
StaticLoadBalancingMIMCMC(pt::ptree pt, std::shared_ptr< ParallelizableMIComponentFactory > componentFactory, std::shared_ptr< StaticLoadBalancer > loadBalancing=std::make_shared< RoundRobinStaticLoadBalancer >(), std::shared_ptr< parcer::Communicator > comm=std::make_shared< parcer::Communicator >(MPI_COMM_WORLD), std::shared_ptr< muq::Utilities::OTF2TracerBase > tracer=std::make_shared< OTF2TracerDummy >())
std::string multiindexToConfigString(std::shared_ptr< MultiIndex > index)
void RequestSamplesAll(int numSamples)
Request an additional number of samples to be computed on each level.
virtual std::shared_ptr< SampleCollection > GetSamples() const
Dummy implementation; required by interface, has no meaning in ML/MI setting.
Eigen::VectorXd MeanQOI()
Get mean quantity of interest estimate computed via telescoping sum.
void RequestSamples(std::shared_ptr< MultiIndex > index, int numSamples)
Request additional samples to be compute for a given model index.
virtual std::shared_ptr< SampleCollection > GetQOIs() const
Dummy implementation; required by interface, has no meaning in ML/MI setting.
High-level communication wrapper for controlling worker processes.