MUQ  0.4.3
FullParallelMultilevelGaussianSampling.cpp
Go to the documentation of this file.
4 
7 
13 
15 
16 #include <boost/property_tree/ptree.hpp>
17 
18 namespace pt = boost::property_tree;
19 using namespace muq::Modeling;
20 using namespace muq::SamplingAlgorithms;
21 using namespace muq::Utilities;
22 
25 
26 #include "ParallelProblem.h"
27 
28 #include <ctime>
29 
30 int main(int argc, char **argv){
31  spdlog::set_level(spdlog::level::debug);
32 
33  MPI_Init(&argc, &argv);
34  auto comm = std::make_shared<parcer::Communicator>(MPI_COMM_WORLD);
35 
36  // Name trace according to current time stamp
37  std::time_t result = std::time(nullptr);
38  std::string timestamp = std::asctime(std::localtime(&result));
39  comm->Bcast(timestamp, 0);
40  auto tracer = std::make_shared<OTF2Tracer>("trace", timestamp);
41 
42  pt::ptree pt;
43  pt.put("NumSamples_0", 10);
44  pt.put("NumSamples_1", 1);
45  pt.put("NumSamples_2", 1e2);
46  pt.put("NumSamples_3", 2e1);
47  pt.put("MCMC.BurnIn", 0);
48  pt.put("MLMCMC.Scheduling", false);
49  pt.put("MLMCMC.Subsampling_0", 10);
50  pt.put("MLMCMC.Subsampling_1", 1);
51  pt.put("MLMCMC.Subsampling_2", 3);
52  pt.put("MLMCMC.Subsampling_3", 0);
53 
54 
55  auto componentFactory = std::make_shared<MyMIComponentFactory>(pt);
56  StaticLoadBalancingMIMCMC parallelMIMCMC (pt, componentFactory, std::make_shared<RoundRobinStaticLoadBalancer>(), comm, tracer);
57 
58  if (comm->GetRank() == 0) {
59  parallelMIMCMC.Run();
60  Eigen::VectorXd meanQOI = parallelMIMCMC.GetQOIs()->Mean();
61  std::cout << "mean QOI: " << meanQOI.transpose() << std::endl;
62  }
63  parallelMIMCMC.WriteToFile("FullParallelGaussianSampling.h5");
64  parallelMIMCMC.Finalize();
65  tracer->write();
66 
67  MPI_Finalize();
68 }
int main(int argc, char **argv)
virtual std::shared_ptr< SampleCollection > Run(std::vector< Eigen::VectorXd > const &x0=std::vector< Eigen::VectorXd >())
void Finalize()
Cleanup parallel method, wait for all ranks to finish.
virtual std::shared_ptr< SampleCollection > GetQOIs() const
Dummy implementation; required by interface, has no meaning in ML/MI setting.