Class MPIGuard

Class Documentation

class MPIGuard

RAII wrapper calling initMPI() on construction, finalizeMPI() on destruction.

Construct exactly one of these in main(), as the very first thing it does, and let it live for main()’s entire remaining scope. main() has several early-return exit paths (bad usage, a failed parse, a caught exception, normal completion); this guarantees finalizeMPI() runs on every one of them without it needing to be called explicitly at each, the same way a destructor guarantees cleanup regardless of how a scope is exited.

Public Functions

inline MPIGuard(int *argc, char ***argv)

Construct the guard, calling initMPI() with the given argc/argv.

Parameters:
  • argc – Address of main()’s own argc

  • argv – Address of main()’s own argv

inline ~MPIGuard()

Destroy the guard, calling finalizeMPI()

MPIGuard(const MPIGuard&) = delete
MPIGuard(MPIGuard&&) = delete
auto operator=(const MPIGuard&) -> MPIGuard& = delete
auto operator=(MPIGuard&&) -> MPIGuard& = delete