Skip to content

Commit

Permalink
Use MPI_Init_thread if OpenMP is enabled
Browse files Browse the repository at this point in the history
If MPI is used in a multi-threaded environment the MPI implementation has
to be aware of the calling context of MPI methods. Therefore, initialize
the MPI environment with MPI_Init_thread requesting the desired thread
support level. So far ls1 makes MPI calls only from the main thread, i.e., uses
MPI_THREAD_FUNNELED. For details see the MPI standard.

Signed-off-by: Christoph Niethammer <[email protected]>
  • Loading branch information
cniethammer committed May 21, 2024
1 parent 969ed75 commit 3236f17
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/MarDyn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,18 @@ int run_unit_tests(const Values &options, const std::vector<std::string> &args)
*/
int main(int argc, char** argv) {
#ifdef ENABLE_MPI
#if defined(_OPENMP)
int thread_support_level_requested = MPI_THREAD_FUNNELED; /* So far only the main thread makes MPI calls */
int thread_support_level_provided = MPI_THREAD_SINGLE;
MPI_Init_thread(&argc, &argv, thread_support_level_requested, &thread_support_level_provided);
if (thread_support_level_requested < thread_support_level_provided) {
std::cerr << "Error: MPI implementation does not support the requested thread support level." << std::endl;
std::exit(EXIT_FAILURE);
}
#else
MPI_Init(&argc, &argv);
#endif
#endif /* _OPENMP */
#endif /* ENABLE_MPI */

/* Initialize the global log file */
Log::global_log = new Log::Logger(Log::Info);
Expand Down

0 comments on commit 3236f17

Please sign in to comment.