From 3646decebcb5208b252f9117c121c794f1d92b86 Mon Sep 17 00:00:00 2001 From: Sam Clarke-Green Date: Wed, 26 Nov 2025 13:19:56 +0000 Subject: [PATCH 1/4] Fix return type of MPIContext::get_handle The get_handle() method should return an MPI_Comm and not an int, because this causes failures when building with OpenMPI. --- src/c++/mpi_context.cpp | 2 +- src/c++/mpi_context.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/c++/mpi_context.cpp b/src/c++/mpi_context.cpp index 551273af..72e8b7b3 100644 --- a/src/c++/mpi_context.cpp +++ b/src/c++/mpi_context.cpp @@ -123,7 +123,7 @@ int meto::MPIContext::get_size() { return comm_size_; } * @returns The MPI communicator handle. */ -int meto::MPIContext::get_handle() { return comm_handle_; } +MPI_Comm meto::MPIContext::get_handle() { return comm_handle_; } /** * @brief Gets the identifying tag. diff --git a/src/c++/mpi_context.h b/src/c++/mpi_context.h index cb6668a7..ce0baabd 100644 --- a/src/c++/mpi_context.h +++ b/src/c++/mpi_context.h @@ -55,7 +55,7 @@ class MPIContext { // Getters int get_size(); int get_rank(); - int get_handle(); + MPI_Comm get_handle(); std::string get_tag() const; }; From c73512fa261fdbe2882c77c88708873edbb044ff Mon Sep 17 00:00:00 2001 From: Sam Clarke-Green Date: Thu, 8 Jan 2026 19:53:44 +0000 Subject: [PATCH 2/4] Protect MPI_Abort in error handler Check whether MPI is initialised before trying to call MPI_Abort. This improves compliance with the standard and prevents test failures when building with OpenMPI. --- src/c++/error_handler.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/c++/error_handler.cpp b/src/c++/error_handler.cpp index acd47992..4818d567 100644 --- a/src/c++/error_handler.cpp +++ b/src/c++/error_handler.cpp @@ -21,6 +21,13 @@ meto::error_handler::error_handler(const std::string &customError, int errorCode) { MPI_Comm comm = MPI_COMM_WORLD; + int flag = 0; + std::cerr << customError << "\n"; - MPI_Abort(comm, errorCode); + + if (MPI_Initialized(&flag)) { + MPI_Abort(comm, errorCode); + } else { + exit(errorCode); + } } From fc074894abedd0acb26a6207d6b208d4d9c05711 Mon Sep 17 00:00:00 2001 From: Sam Clarke-Green Date: Tue, 20 Jan 2026 15:34:00 +0000 Subject: [PATCH 3/4] Replace exit with std::exit --- src/c++/error_handler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/c++/error_handler.cpp b/src/c++/error_handler.cpp index 4818d567..e8fbb85b 100644 --- a/src/c++/error_handler.cpp +++ b/src/c++/error_handler.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "error_handler.h" #include "vernier_mpi.h" @@ -28,6 +29,6 @@ meto::error_handler::error_handler(const std::string &customError, if (MPI_Initialized(&flag)) { MPI_Abort(comm, errorCode); } else { - exit(errorCode); + std::exit(errorCode); } } From 2ed46f25ae454d97a123bbb4f23926bd6483a508 Mon Sep 17 00:00:00 2001 From: Sam Clarke-Green Date: Tue, 20 Jan 2026 15:35:42 +0000 Subject: [PATCH 4/4] Let clang format reorder the includes --- src/c++/error_handler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/c++/error_handler.cpp b/src/c++/error_handler.cpp index e8fbb85b..62295144 100644 --- a/src/c++/error_handler.cpp +++ b/src/c++/error_handler.cpp @@ -5,9 +5,9 @@ * ----------------------------------------------------------------------------- */ +#include #include #include -#include #include "error_handler.h" #include "vernier_mpi.h"