PURIFY
Next-generation radio interferometric imaging
main.cc
Go to the documentation of this file.
1 #include "purify/config.h"
2 #include <benchmark/benchmark.h>
3 #include "purify/logging.h"
4 #include <sopt/logging.h>
5 #include <sopt/mpi/communicator.h>
6 #include <sopt/mpi/session.h>
7 
8 // This reporter does nothing.
9 // We can use it to disable output from all but the root process
10 class NullReporter : public ::benchmark::BenchmarkReporter {
11  public:
13  virtual bool ReportContext(const Context &) { return true; }
14  virtual void ReportRuns(const std::vector<Run> &) {}
15  virtual void Finalize() {}
16 };
17 
18 // The main is rewritten to allow for MPI initializing and for selecting a
19 // reporter according to the process rank
20 int main(int argc, char const **argv) {
23 
24 #ifdef PURIFY_MPI
25  auto const session = sopt::mpi::init(argc, argv);
26  auto const world = sopt::mpi::Communicator::World();
27  PURIFY_LOW_LOG("MPI initialized");
28 #endif
29  ::benchmark::Initialize(&argc, const_cast<char **>(argv));
30 
31 #ifdef PURIFY_MPI
32  if (world.is_root())
33  // root process will use a reporter from the usual set provided by
34  // ::benchmark
35  ::benchmark::RunSpecifiedBenchmarks();
36  else {
37  // reporting from other processes is disabled by passing a custom reporter
38  NullReporter null;
39  ::benchmark::RunSpecifiedBenchmarks(&null);
40  }
41 #endif
42  return 0;
43 }
int main(int argc, char const **argv)
Definition: main.cc:20
NullReporter()
Definition: main.cc:12
virtual void Finalize()
Definition: main.cc:15
virtual void ReportRuns(const std::vector< Run > &)
Definition: main.cc:14
virtual bool ReportContext(const Context &)
Definition: main.cc:13
#define PURIFY_LOW_LOG(...)
Low priority message.
Definition: logging.h:207
void set_level(const std::string &level)
Method to set the logging level of the default Log object.
Definition: logging.h:137