diff --git a/src/c++/error_handler.cpp b/src/c++/error_handler.cpp index acd47992..62295144 100644 --- a/src/c++/error_handler.cpp +++ b/src/c++/error_handler.cpp @@ -5,6 +5,7 @@ * ----------------------------------------------------------------------------- */ +#include #include #include @@ -21,6 +22,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 { + std::exit(errorCode); + } } 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; };