From 5eeecf57f26f6f75310d46e81782c925d0402b9f Mon Sep 17 00:00:00 2001 From: "raphael.bach" <raphael.bach@etu.hesge.ch> Date: Wed, 22 Jun 2022 23:09:23 +0200 Subject: [PATCH] Add `FMPI_PRIV_FUTHARK_FUNC_IDX()` --- include/internal/generic/fmpi_futhark_generic.h | 5 ++++- src/fmpi_futhark.c | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/internal/generic/fmpi_futhark_generic.h b/include/internal/generic/fmpi_futhark_generic.h index 39ebf6d..139cf0a 100644 --- a/include/internal/generic/fmpi_futhark_generic.h +++ b/include/internal/generic/fmpi_futhark_generic.h @@ -42,8 +42,11 @@ struct fmpi_futhark_ctx; #define FMPI_FUTHARK_TYPES \ FMPI_TYPE_REAL +#define FMPI_PRIV_FUTHARK_FUNC_IDX(d, t) \ + (((t) * FMPI_DIM_MAX) + (d) - 1) + #define FMPI_PRIV_FUTHARK_ARRAY_ENTRY(D, T) \ - [FMPI_TYPE_##T * (FMPI_DIM_MAX) + ((D)-1)] = fmpi_futhark_new_##D##d_##T + [FMPI_PRIV_FUTHARK_FUNC_IDX(D, FMPI_TYPE_##T)] = fmpi_futhark_new_##D##d_##T #define FMPI_FUTHARK_ARRAY_ENTRY_LIST(D) \ CPL_MAP_FIXED(FMPI_PRIV_FUTHARK_ARRAY_ENTRY, CPL_COMMA, (D), FMPI_FUTHARK_TYPES) diff --git a/src/fmpi_futhark.c b/src/fmpi_futhark.c index 22760b4..706880c 100644 --- a/src/fmpi_futhark.c +++ b/src/fmpi_futhark.c @@ -148,7 +148,7 @@ void * fmpi_futhark_new_data( assert(ctx != NULL); assert(data != NULL); assert(dim_cnt <= FMPI_DIM_MAX); - const size_t idx = (type * (FMPI_DIM_MAX) + ((dim_cnt)-1)); + const size_t idx = FMPI_PRIV_FUTHARK_FUNC_IDX(dim_cnt, type); return fmpi_futhark_new_data_func_list[idx](ctx, data, x, y, z); } @@ -166,14 +166,14 @@ void * fmpi_futhark_new_##D##d_##T( \ } \ fmpi_futhark_sync(ctx); \ return data; \ -}\ +} \ void fmpi_futhark_free_##D##d_##T( \ const struct fmpi_futhark_ctx * const ctx, void * const array \ ){ \ _Static_assert((D) <= FMPI_DIM_MAX, ""); \ assert(ctx != NULL); \ assert(array != NULL); \ - fmpi_futhark_sync(ctx);\ + fmpi_futhark_sync(ctx); \ const int err = futhark_free_##T##_##D##d(ctx->ctx, array); \ if(err != 0) { \ fmpi_futhark_check_error(ctx, CPL_STRINGIFY(futhark_free_##T##_##D##d)); \ -- GitLab