diff --git a/include/internal/fmpi_ctx.h b/include/internal/fmpi_ctx.h index 845e01a18305482e3debde10a67481a453cc2b16..1ac74a1c3052223c31a7a41ebb7655ca5230ed6a 100644 --- a/include/internal/fmpi_ctx.h +++ b/include/internal/fmpi_ctx.h @@ -51,7 +51,7 @@ typedef struct fmpi_ctx { size_t task_cnt; double timer_start; //!< TODO double timer_stop; //!< TODO - const struct fmpi_error_handler * err_handler; //!< TODO + struct fmpi_error_handler err_handler; //!< TODO } fmpi_ctx; /*============================================================================== PUBLIC FUNCTION diff --git a/include/internal/fmpi_error.h b/include/internal/fmpi_error.h index 1c088248b5ae81d6f70adabd7c97949d9b1bd68d..915e6321eb23de9e4b12ef7de8f2e144d0c2cbf5 100644 --- a/include/internal/fmpi_error.h +++ b/include/internal/fmpi_error.h @@ -194,7 +194,7 @@ typedef struct fmpi_error_handler { * } */ void fmpi_raise_error( - const struct fmpi_error_handler * err_handler, + struct fmpi_error_handler err_handler, const char * file, size_t line, const char * func, const char * module, const char * fmt, ... ); @@ -271,7 +271,7 @@ const char * fmpi_error_timestamp_str(time_t t, char * buf, size_t size); * } */ #define FMPI_RAISE_ERROR(err_handler, module, ...) \ - fmpi_raise_error((err_handler), __FILE__, __LINE__, __func__, (module), __VA_ARGS__) + fmpi_raise_error(err_handler, __FILE__, __LINE__, __func__, (module), __VA_ARGS__) /*============================================================================== GUARD ==============================================================================*/ diff --git a/include/internal/fmpi_futhark.h b/include/internal/fmpi_futhark.h index 65c7af10d49fa0d8f8e91a7bb55e41b128e696da..3edddb51ce4e4816f3ac0a69be7d655315b30a75 100644 --- a/include/internal/fmpi_futhark.h +++ b/include/internal/fmpi_futhark.h @@ -41,9 +41,9 @@ * TODO */ typedef struct fmpi_futhark_ctx { - struct futhark_context * ctx; //!< TODO - struct futhark_context_config * cfg; //!< TODO - const struct fmpi_error_handler * err_handler; //!< TODO + struct futhark_context * ctx; //!< TODO + struct futhark_context_config * cfg; //!< TODO + struct fmpi_error_handler err_handler; //!< TODO } fmpi_futhark_ctx; /*============================================================================== PUBLIC FUNCTION @@ -66,7 +66,7 @@ typedef struct fmpi_futhark_ctx { * TODO * } */ -struct fmpi_futhark_ctx * fmpi_futhark_init(const struct fmpi_error_handler * err_handler); +struct fmpi_futhark_ctx * fmpi_futhark_init(struct fmpi_error_handler err_handler); /*------------------------------------------------------------------------------ fmpi_futhark_exit() ------------------------------------------------------------------------------*/ diff --git a/include/internal/fmpi_mpi.h b/include/internal/fmpi_mpi.h index dd0119acddc432ec04277f0646257c1de37f7e7c..ca5bb465ae67a26285b6783362fb0b4ac6470189 100644 --- a/include/internal/fmpi_mpi.h +++ b/include/internal/fmpi_mpi.h @@ -52,7 +52,7 @@ typedef struct fmpi_mpi_ctx { int root; //!< TODO int futhark_err_class; //!< TODO int futhark_err_code; //!< TODO - const struct fmpi_error_handler * err_handler; //!< TODO + struct fmpi_error_handler err_handler; //!< TODO } fmpi_mpi_ctx; /*============================================================================== PUBLIC FUNCTION @@ -78,7 +78,7 @@ typedef struct fmpi_mpi_ctx { * } */ struct fmpi_mpi_ctx * fmpi_mpi_init( - int * argc, char ** argv[], const struct fmpi_error_handler * err_handler + int * argc, char ** argv[], struct fmpi_error_handler err_handler ); /*------------------------------------------------------------------------------ fmpi_mpi_exit() diff --git a/src/fmpi_ctx.c b/src/fmpi_ctx.c index 0d6f9221faf2f505b3f2de66dab727656eb1c5bf..fe7030ba6f1968abeaf483c4809daf32dacfe35b 100644 --- a/src/fmpi_ctx.c +++ b/src/fmpi_ctx.c @@ -64,12 +64,12 @@ struct fmpi_ctx * fmpi_ctx_create(int * argc, char ** argv[]) fprintf(stderr, "malloc(fmpi_ctx) failed!\n"); return NULL; } - ctx->err_handler = &(struct fmpi_error_handler) { + ctx->err_handler = (struct fmpi_error_handler) { .func = fmpi_error_callback, .user_data = ctx }; // MPI initialization - ctx->mpi = fmpi_mpi_init(argc, argv, &(struct fmpi_error_handler) { + ctx->mpi = fmpi_mpi_init(argc, argv, (struct fmpi_error_handler) { .func = fmpi_error_callback, .user_data = ctx }); @@ -79,7 +79,7 @@ struct fmpi_ctx * fmpi_ctx_create(int * argc, char ** argv[]) return NULL; } // Futhark Initialization - ctx->fut = fmpi_futhark_init(&(struct fmpi_error_handler) { + ctx->fut = fmpi_futhark_init((struct fmpi_error_handler) { .func = fmpi_error_callback, .user_data = ctx }); diff --git a/src/fmpi_error.c b/src/fmpi_error.c index eec4f567c5f9e3e37e2cf2ab576639d4e7a15ac0..8b8b397adc7e9e2f5de56a3821ae212f851ef0e9 100644 --- a/src/fmpi_error.c +++ b/src/fmpi_error.c @@ -35,7 +35,7 @@ fmpi_raise_error() ------------------------------------------------------------------------------*/ void fmpi_raise_error( - const struct fmpi_error_handler * const err_handler, + const struct fmpi_error_handler err_handler, const char * const file, const size_t line, const char * const func, const char * const module, const char * const fmt, ... ){ @@ -43,7 +43,7 @@ void fmpi_raise_error( assert(func != NULL); assert(module != NULL); assert(fmt != NULL); - if(err_handler->func == NULL) { + if(err_handler.func == NULL) { return; } const time_t t = time(NULL); @@ -60,7 +60,7 @@ void fmpi_raise_error( } va_end(args); } - err_handler->func(&(const struct fmpi_error){ + err_handler.func(&(const struct fmpi_error){ .file = file, .line = line, .func = func, @@ -68,7 +68,7 @@ void fmpi_raise_error( .module = module, .msg = msg_str, }, - err_handler->user_data + err_handler.user_data ); } /*------------------------------------------------------------------------------ diff --git a/src/fmpi_futhark.c b/src/fmpi_futhark.c index e49b554d1f4c5f4a9f5625b0c0c14807d5e7bca9..c3137f4692f57942c29b9d438c62114c5eba9ef8 100644 --- a/src/fmpi_futhark.c +++ b/src/fmpi_futhark.c @@ -50,7 +50,7 @@ static const fmpi_futhark_new_data_func fmpi_futhark_new_data_func_list[] = { ==============================================================================*/ #define FMPI_RAISE_FUTHARK_ERROR(ctx, ...) \ do { \ - if((ctx)->err_handler != NULL) { \ + if((ctx)->err_handler.func != NULL) { \ FMPI_RAISE_ERROR((ctx)->err_handler, "FUTHARK", __VA_ARGS__); \ } \ } while(0) @@ -61,16 +61,14 @@ do { \ fmpi_futhark_init() ------------------------------------------------------------------------------*/ struct fmpi_futhark_ctx * fmpi_futhark_init( - const struct fmpi_error_handler * const err_handler + const struct fmpi_error_handler err_handler ){ struct fmpi_futhark_ctx * ctx = malloc(sizeof(*ctx)); if(ctx == NULL) { - if(err_handler != NULL) { - FMPI_RAISE_ERROR(err_handler, "FUTHARK", "malloc(fmpi_futhark_ctx) failed!"); - } + FMPI_RAISE_ERROR(err_handler, "FUTHARK", "malloc(fmpi_futhark_ctx) failed!"); return NULL; } - ctx->err_handler = (err_handler != NULL) ? err_handler : NULL; + ctx->err_handler = err_handler; ctx->cfg = futhark_context_config_new(); if(ctx->cfg == NULL) { FMPI_RAISE_FUTHARK_ERROR(ctx, "futhark_context_config_new() failed!"); diff --git a/src/fmpi_mpi.c b/src/fmpi_mpi.c index 4df0f27070475309b1782ec98a317e1e439f9995..11e95ff94c36301ee34562d733df9278f3a8c062 100644 --- a/src/fmpi_mpi.c +++ b/src/fmpi_mpi.c @@ -41,7 +41,7 @@ ==============================================================================*/ #define FMPI_RAISE_MPI_ERROR(ctx, ...) \ do { \ - if((ctx)->err_handler != NULL) { \ + if((ctx)->err_handler.func != NULL) { \ FMPI_RAISE_ERROR((ctx)->err_handler, "MPI", __VA_ARGS__); \ } \ } while(0) @@ -53,17 +53,15 @@ do { \ ------------------------------------------------------------------------------*/ struct fmpi_mpi_ctx * fmpi_mpi_init( int * const argc, char *** const argv, - const struct fmpi_error_handler * const err_handler + const struct fmpi_error_handler err_handler ){ struct fmpi_mpi_ctx * ctx = malloc(sizeof(*ctx)); if(ctx == NULL) { - if(err_handler != NULL) { - FMPI_RAISE_ERROR(err_handler, "MPI", "malloc(fmpi_mpi_ctx) failed!"); - } + FMPI_RAISE_ERROR(err_handler, "MPI", "malloc(fmpi_mpi_ctx) failed!"); return NULL; } ctx->root = FMPI_MPI_ROOT; - ctx->err_handler = (err_handler != NULL) ? err_handler : NULL; + ctx->err_handler = err_handler; int err_id = MPI_Init(argc, argv); if(fmpi_mpi_check_error(ctx, err_id, "MPI_Init") == true) {