PURIFY
Next-generation radio interferometric imaging
Macros | Functions
common_mpi_catch_main.cc File Reference
#include <purify/config.h>
#include <memory>
#include <mpi.h>
#include <random>
#include <regex>
#include <vector>
#include <catch2/catch_all.hpp>
#include <purify/logging.h>
#include <sopt/logging.h>
#include <sopt/mpi/session.h>
+ Include dependency graph for common_mpi_catch_main.cc:

Go to the source code of this file.

Macros

#define CATCH_CONFIG_RUNNER
 

Functions

std::unique_ptr< std::mt19937_64 > mersenne (new std::mt19937_64(0))
 
int main (int argc, const char **argv)
 

Macro Definition Documentation

◆ CATCH_CONFIG_RUNNER

#define CATCH_CONFIG_RUNNER

Definition at line 1 of file common_mpi_catch_main.cc.

Function Documentation

◆ main()

int main ( int  argc,
const char **  argv 
)

Definition at line 16 of file common_mpi_catch_main.cc.

16  {
17  Catch::Session session; // There must be exactly once instance
18 
19  auto const mpi_session = sopt::mpi::init(argc, argv);
20 
21  // The following mess transforms the input arguments so that output files have different names
22  // on different processors
23  std::vector<std::string> arguments(argv, argv + argc);
24  auto output_opt = std::find_if(arguments.begin(), arguments.end(), [](std::string const &arg) {
25  if (arg == "-o" or arg == "--out") return true;
26  auto const N = std::string("--out=").size();
27  return arg.size() > N and arg.substr(0, N) == "--out=";
28  });
29  if (output_opt != arguments.end()) {
30  if (*output_opt == "-o" or *output_opt == "--out") output_opt += 1;
31  if (output_opt != arguments.end()) {
32  int rank;
33  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
34  if (rank > 0)
35  *output_opt =
36  std::regex_replace(*output_opt, std::regex("\\.xml"), std::to_string(rank) + ".xml");
37  }
38  }
39 
40  // transforms the modified arguments to a C-style array of pointers.
41  std::vector<char const *> cargs(arguments.size());
42  std::transform(arguments.begin(), arguments.end(), cargs.begin(),
43  [](std::string const &c) { return c.c_str(); });
44 
45  int returnCode = session.applyCommandLine(cargs.size(), const_cast<char **>(cargs.data()));
46  if (returnCode != 0) // Indicates a command line error
47  return returnCode;
48  mersenne.reset(new std::mt19937_64(session.configData().rngSeed));
49 
50  auto const result = session.run();
51 
52  return result;
53 }
std::unique_ptr< std::mt19937_64 > mersenne(new std::mt19937_64(0))
const t_real c
speed of light in vacuum
Definition: types.h:72

References purify::constant::c, and mersenne().

◆ mersenne()

std::unique_ptr<std::mt19937_64> mersenne ( new   std::mt19937_640)

Referenced by main().