Skip to content

Use Mayers' singleton pattern to initialize MPIHelper

Simon Praetorius requested to merge issue/mpihelper-singleton into master

Summary

The singleton initialization of MPIHelper is broken (at least in c++23). The solution proposed here is very similar to the old implementation before !952 (merged) and is discussed in !1274 (closed). We use a static variable in the instance(...) method that is returned as singleton object since initialized only once.

The difference to the old implementation is that we allow also to pass zero arguments to the instance() method. Passing no arguments results in passing NULL to MPI_Init. These are vaild arguments to MPI_Init.

The consequence of this MR is as follows:

  • Calling MPI_Helper::instance(argc, argv) with arguments passed to main results in MPI_Init(&argc, &argv)
  • Calling MPI_Helper::instance() withou arguments, results in MPI_Init(NULL, NULL)

See https://www.mpi-forum.org/docs/mpi-2.0/mpi-20-html/node43.htm for the rational why passing NULL is fine.

Superseeds !1274 (closed)

Edited by Simon Praetorius

Merge request reports

Loading