diff --git a/include/internal/fmpi_mpi.h b/include/internal/fmpi_mpi.h index ca5bb465ae67a26285b6783362fb0b4ac6470189..1b5f1d9fdb5bff5a1a3e398bb16fbb0d2d5d20fe 100644 --- a/include/internal/fmpi_mpi.h +++ b/include/internal/fmpi_mpi.h @@ -167,6 +167,23 @@ void fmpi_mpi_ctx_print(const struct fmpi_mpi_ctx * ctx); * TODO */ int fmpi_mpi_world_rank(const struct fmpi_mpi_ctx * ctx); +/*------------------------------------------------------------------------------ + fmpi_mpi_finalized() +------------------------------------------------------------------------------*/ +/** + * Checks if `MPI_Finalize()` has been called. + * + * @param[in] ctx : A pointer to a fmpi_mpi_ctx. + * + * @return + * - `true` if `MPI_Finalize()` has been called. + * - `false` if `MPI_Finalize()` has not been called. + * + * @example{ + * TODO + * } + */ +_Bool fmpi_mpi_finalized(const struct fmpi_mpi_ctx * ctx); /*============================================================================== GUARD ==============================================================================*/ diff --git a/src/fmpi_mpi.c b/src/fmpi_mpi.c index 11e95ff94c36301ee34562d733df9278f3a8c062..67983d6e30e0c648556ae68a765f7a8a7c2e01d3 100644 --- a/src/fmpi_mpi.c +++ b/src/fmpi_mpi.c @@ -93,7 +93,7 @@ int fmpi_mpi_exit(struct fmpi_mpi_ctx ** const ctx) if(fmpi_mpi_check_error(*ctx, err_id, "MPI_Finalize") == true) { err_id = -1; } - free(*ctx); *ctx = NULL; + //free(*ctx); *ctx = NULL; return err_id; } /*------------------------------------------------------------------------------ @@ -150,3 +150,15 @@ int fmpi_mpi_world_rank(const struct fmpi_mpi_ctx * const ctx) } return rank; } +/*------------------------------------------------------------------------------ + fmpi_mpi_finalized() +------------------------------------------------------------------------------*/ +_Bool fmpi_mpi_finalized(const struct fmpi_mpi_ctx * const ctx) +{ + int finalized = 0; + int err_id = MPI_Finalized(&finalized); + if(ctx != NULL) { + fmpi_mpi_check_error(ctx, err_id, "MPI_Finalized"); + } + return finalized; +}