MUQ  0.4.3
ParallelAbstractSamplingProblem.h
Go to the documentation of this file.
1 #ifndef PARALLELABSTRACTSAMPLINGPROBLEM_H_
2 #define PARALLELABSTRACTSAMPLINGPROBLEM_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 <parcer/Communicator.h>
16 
17 namespace muq {
18  namespace SamplingAlgorithms {
19 
38  {
39  public:
40 
41  ParallelAbstractSamplingProblem(std::shared_ptr<parcer::Communicator> comm, int id, std::shared_ptr<AbstractSamplingProblem> abstractSamplingProblem)
43  {
44  this->comm = comm;
45  this->id = id;
46  this->abstractSamplingProblem = abstractSamplingProblem;
47  }
48 
49  virtual ~ParallelAbstractSamplingProblem() = default;
50 
51  virtual double LogDensity(std::shared_ptr<SamplingState> const& state) override {
52 
53  if (comm->GetRank() == 0) {
54  for (int dest = 1; dest < comm->GetSize(); dest++) {
56  comm->Send(id, dest, WorkgroupTag);
57  comm->Send(state->state[0], dest, WorkgroupTag);
58  }
59  }
60 
61  return abstractSamplingProblem->LogDensity(state);
62  }
63 
64  virtual std::shared_ptr<SamplingState> QOI() override {
65  return abstractSamplingProblem->QOI();
66  }
67 
68  std::shared_ptr<AbstractSamplingProblem> GetSequentialProblem() {
70  }
71 
72  private:
73  int id;
74  std::shared_ptr<parcer::Communicator> comm;
75  std::shared_ptr<AbstractSamplingProblem> abstractSamplingProblem;
76  };
77 
78  }
79 }
80 
81 #endif
82 
83 #endif
Abstract base class for MCMC and Importance Sampling problems.
Parallelization layer supporting parallel models underlying a SamplingProblem.
virtual std::shared_ptr< SamplingState > QOI() override
std::shared_ptr< AbstractSamplingProblem > GetSequentialProblem()
std::shared_ptr< AbstractSamplingProblem > abstractSamplingProblem
virtual double LogDensity(std::shared_ptr< SamplingState > const &state) override
ParallelAbstractSamplingProblem(std::shared_ptr< parcer::Communicator > comm, int id, std::shared_ptr< AbstractSamplingProblem > abstractSamplingProblem)