SOPT
Sparse OPTimisation
Macros | Functions
common_mpi_catch_main.cc File Reference
#include "sopt/config.h"
#include <catch2/catch_all.hpp>
#include <memory>
#include <mpi.h>
#include <random>
#include <regex>
#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 14 of file common_mpi_catch_main.cc.

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

References cargs, sopt::mpi::init(), and mersenne().

◆ mersenne()

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

Referenced by main().