Skip to content

Draft: Use Meyer's singleton to initialize MPIHelper

Motivation

Currently, we use a mutex to initialize a unique instance of the MPIHelper by storing it in static std::unique_ptr<MPIHelper>. The reason for this is to allow fetching a program-wide instance of MPIHelper without having to pass the initial arguments around !952 (merged): i.e., call MPIHelper::instance() rather than MPIHelper::instance(argv, arc). There is two problems with the current implementation:

  • clang-17 -std=c++23 fails to compile this. I am not sure if this is an issue with clang or c++23.
  • The current implementation is actually not thread safe because the pointer is being read outside of the mutex guard. So we do all of this gymnastics and the implementation is wrong anyways: bug
  • Additionally, below, we discussed that the storage duration of the MPIHelper instance is wrong when MPIHelper is required in different object files. See #348

Proposal

Use Meyer's singleton and store it's address on the first call of MPIHelper::instance(argv, arc). Meyer's singleton is thread-safe by design and also solves the clang/c++23 issue because it doesn't use smart pointers. Notice that we were using Meyer's singleton before !952 (merged).

  • Add CHANGELOG entry
Edited by Christoph Grüninger

Merge request reports

Loading