MUQ  0.4.3
ParallelMIMCMCWorker.h
Go to the documentation of this file.
1 #ifndef PARALLELMIMCMCWORKER_H_
2 #define PARALLELMIMCMCWORKER_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 <chrono>
13 #include <list>
14 #include <thread>
15 #include "spdlog/spdlog.h"
16 #include "spdlog/fmt/ostr.h"
25 
26 namespace muq {
27  namespace SamplingAlgorithms {
28 
35  public:
36  CollectorClient(std::shared_ptr<parcer::Communicator> comm,
37  std::vector<int> subgroup,
38  std::shared_ptr<MultiIndex> modelindex);
39 
40  std::shared_ptr<MultiIndex> GetModelIndex() const;
41 
42  void CollectSamples (int numSamples);
43 
44  void ComputeMeans();
45 
46  void WriteToFile(std::string filename);
47 
48  bool Receive (ControlFlag command, const MPI_Status& status);
49 
50  Eigen::VectorXd GetQOIMean();
51 
52  void Unassign();
53 
54  bool IsSampling();
55 
56  bool IsComputingMeans();
57 
58  private:
59 
60  std::shared_ptr<parcer::Communicator> comm;
61  std::vector<int> subgroup;
62 
63  bool sampling = false;
64  bool computingMeans = false;
65  std::shared_ptr<MultiIndexSet> boxIndices;
66  Eigen::VectorXd boxQOIMean;
67 
68  std::shared_ptr<MultiIndex> boxHighestIndex;
69  std::shared_ptr<MultiIndex> boxLowestIndex;
70 
71  std::map<std::shared_ptr<MultiIndex>, Eigen::VectorXd, MultiPtrComp> means;
72 
73  };
74 
80  class WorkerClient {
81  public:
82  WorkerClient(std::shared_ptr<parcer::Communicator> comm,
83  std::shared_ptr<PhonebookClient> phonebookClient,
84  int RootRank);
85 
86  void assignGroup (std::vector<int> subgroup, std::shared_ptr<MultiIndex> modelindex);
87 
88  std::vector<int> UnassignGroup (std::shared_ptr<MultiIndex> modelIndex, int groupRootRank);
89 
90  void UnassignAll();
91 
92  void Finalize();
93 
94  private:
95  std::shared_ptr<parcer::Communicator> comm;
96  std::shared_ptr<PhonebookClient> phonebookClient;
97  };
98 
109  class WorkerServer {
110  public:
111  WorkerServer(boost::property_tree::ptree const& pt,
112  std::shared_ptr<parcer::Communicator> comm,
113  std::shared_ptr<PhonebookClient> phonebookClient,
114  int RootRank,
115  std::shared_ptr<ParallelizableMIComponentFactory> componentFactory,
116  std::shared_ptr<muq::Utilities::OTF2TracerBase> tracer);
117 
118  private:
119  std::string multiindexToConfigString (std::shared_ptr<MultiIndex> index);
120 
121  };
122 
123  }
124 }
125 
126 #endif
127 
128 #endif
High-level communication wrapper for controlling SampleCollectors.
std::map< std::shared_ptr< MultiIndex >, Eigen::VectorXd, MultiPtrComp > means
std::shared_ptr< MultiIndex > GetModelIndex() const
bool Receive(ControlFlag command, const MPI_Status &status)
std::shared_ptr< MultiIndexSet > boxIndices
CollectorClient(std::shared_ptr< parcer::Communicator > comm, std::vector< int > subgroup, std::shared_ptr< MultiIndex > modelindex)
std::shared_ptr< MultiIndex > boxLowestIndex
std::shared_ptr< parcer::Communicator > comm
std::shared_ptr< MultiIndex > boxHighestIndex
High-level communication wrapper for controlling worker processes.
std::shared_ptr< parcer::Communicator > comm
void assignGroup(std::vector< int > subgroup, std::shared_ptr< MultiIndex > modelindex)
std::shared_ptr< PhonebookClient > phonebookClient
std::vector< int > UnassignGroup(std::shared_ptr< MultiIndex > modelIndex, int groupRootRank)
WorkerClient(std::shared_ptr< parcer::Communicator > comm, std::shared_ptr< PhonebookClient > phonebookClient, int RootRank)
Implements the actual sampling / collecting logic for parallel MIMCMC.
WorkerServer(boost::property_tree::ptree const &pt, std::shared_ptr< parcer::Communicator > comm, std::shared_ptr< PhonebookClient > phonebookClient, int RootRank, std::shared_ptr< ParallelizableMIComponentFactory > componentFactory, std::shared_ptr< muq::Utilities::OTF2TracerBase > tracer)
std::string multiindexToConfigString(std::shared_ptr< MultiIndex > index)
ControlFlag
Flags used by parallel MCMC/MIMCMC type methods.
Definition: ParallelFlags.h:23