From a05880468a29b9787dd0795615c4b398c969d03e Mon Sep 17 00:00:00 2001 From: "raphael.bach" <raphael.bach@etu.hesge.ch> Date: Sun, 26 Jun 2022 21:38:34 +0200 Subject: [PATCH] Update error handling in `fmpi_core` module --- src/fmpi_core.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/src/fmpi_core.c b/src/fmpi_core.c index 7567eea..cb9065c 100644 --- a/src/fmpi_core.c +++ b/src/fmpi_core.c @@ -53,7 +53,12 @@ struct fmpi_ctx * fmpi_init(int * const argc, char ** argv[]) int fmpi_exit(struct fmpi_ctx ** const ctx) { assert(ctx != NULL); - return fmpi_ctx_destroy(ctx); + assert(*ctx != NULL); + const int err = fmpi_ctx_destroy(ctx); + if(err != FMPI_SUCCESS) { + fprintf(stderr, "fmpi_ctx_destroy() failed!\n"); + } + return err; } /*------------------------------------------------------------------------------ fmpi_abort() @@ -79,7 +84,7 @@ int fmpi_world_rank(const struct fmpi_ctx * const ctx) { assert(ctx != NULL); const int rank = fmpi_mpi_world_rank(ctx->mpi); - if(rank < 0) { + if(rank < FMPI_SUCCESS) { FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "fmpi_mpi_world_rank() failed!"); } return rank; @@ -90,11 +95,11 @@ int fmpi_world_rank(const struct fmpi_ctx * const ctx) int fmpi_world_barrier(const struct fmpi_ctx * const ctx) { assert(ctx != NULL); - const int err_id = fmpi_mpi_world_barrier(ctx->mpi); - if(err_id == -1) { + const int err = fmpi_mpi_world_barrier(ctx->mpi); + if(err != FMPI_SUCCESS) { FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "fmpi_mpi_world_barrier() failed!"); } - return err_id; + return err; } /*------------------------------------------------------------------------------ fmpi_run_task() @@ -105,9 +110,20 @@ int fmpi_run_task( assert(ctx != NULL); assert(task != NULL); if(task->type == FMPI_TASK_TYPE_SYNC) { - return fmpi_task_run_sync(ctx, task); + const int err = fmpi_task_run_sync(ctx, task); + if(err != FMPI_SUCCESS) { + FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "fmpi_task_run_sync() failed!"); + } + return err; + } + if(task->type == FMPI_TASK_TYPE_ASYNC) { + const int err = fmpi_task_run_async(ctx, task); + if(err != FMPI_SUCCESS) { + FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "fmpi_task_run_async() failed!"); + } + return err; } - return fmpi_task_run_async(ctx, task); + return FMPI_ERROR; } /*------------------------------------------------------------------------------ fmpi_sync() @@ -115,5 +131,9 @@ int fmpi_run_task( int fmpi_sync(const struct fmpi_ctx * const ctx) { assert(ctx != NULL); - return fmpi_futhark_sync(ctx->fut); + const int err = fmpi_futhark_sync(ctx->fut); + if(err != FMPI_SUCCESS) { + FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "fmpi_futhark_sync() failed!"); + } + return err; } -- GitLab