From dfbafd9b238bd0110c77b133ad7e4e2b818108f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kon=20H=C3=A6gland?= Date: Sun, 8 Dec 2024 14:23:51 +0100 Subject: [PATCH] Clearify that errhandler is a handle It is safe to free the error handler after MPI_Comm_set_errhandler() has been called --- opm/simulators/flow/ReservoirCoupling.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/opm/simulators/flow/ReservoirCoupling.cpp b/opm/simulators/flow/ReservoirCoupling.cpp index 0ca3f3212..8c4499a87 100644 --- a/opm/simulators/flow/ReservoirCoupling.cpp +++ b/opm/simulators/flow/ReservoirCoupling.cpp @@ -71,7 +71,15 @@ void setErrhandler(MPI_Comm comm, bool is_master) else { MPI_Comm_create_errhandler(custom_error_handler_slave_, &errhandler); } + // NOTE: The errhandler is a handle (an integer) that is associated with the communicator + // that is why we pass this by value below. And it is safe to free the errhandler after it has + // been associated with the communicator. MPI_Comm_set_errhandler(comm, errhandler); + // Mark the error handler for deletion. According to the documentation: "The error handler will + // be deallocated after all the objects associated with it (communicator, window, or file) have + // been deallocated." So the error handler will still be in effect until the communicator is + // deallocated. + MPI_Errhandler_free(&errhandler); } bool Seconds::compare_eq(double a, double b)