From 1957058afba43d65cf5b1b4d899375e9e69ebd22 Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Mon, 23 Oct 2023 17:53:15 +0200 Subject: [PATCH] Print MPI rank if available instead of locality in exception information --- libs/pika/runtime/src/custom_exception_info.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/libs/pika/runtime/src/custom_exception_info.cpp b/libs/pika/runtime/src/custom_exception_info.cpp index af27d6b2b..aff979a65 100644 --- a/libs/pika/runtime/src/custom_exception_info.cpp +++ b/libs/pika/runtime/src/custom_exception_info.cpp @@ -24,6 +24,10 @@ #include #include +#if defined(PIKA_HAVE_MPI) +# include +#endif + #include #include #include @@ -85,8 +89,17 @@ namespace pika { strm << "{stack-trace}: " << *back_trace << "\n"; } - std::uint32_t const* locality = xi.get(); - if (locality) strm << "{locality-id}: " << *locality << "\n"; +#if defined(PIKA_HAVE_MPI) + int mpi_initialized = 0; + if (MPI_Initialized(&mpi_initialized) == MPI_SUCCESS && mpi_initialized) + { + int rank = 0; + if (MPI_Comm_rank(MPI_COMM_WORLD, &rank) == MPI_SUCCESS) + { + strm << "{mpi-rank}: " << rank << '\n'; + } + } +#endif std::string const* hostname_ = xi.get(); if (hostname_ && !hostname_->empty()) strm << "{hostname}: " << *hostname_ << "\n";