From 30830e087ed83fc1c12bc24d66cb470a9f9d5391 Mon Sep 17 00:00:00 2001 From: "raphael.bach" <raphael.bach@etu.hesge.ch> Date: Tue, 21 Jun 2022 03:31:37 +0200 Subject: [PATCH] Add `fmpi_data_out()` --- examples/array_sum/main.c | 4 ++-- include/fmpi_data.h | 5 +++++ include/internal/generic/fmpi_data_generic.h | 7 +++++++ src/fmpi_data.c | 22 ++++++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/examples/array_sum/main.c b/examples/array_sum/main.c index 5418317..6e0ee99 100644 --- a/examples/array_sum/main.c +++ b/examples/array_sum/main.c @@ -21,7 +21,7 @@ int main(int argc, char * argv[]) } T in[] = { 1,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,1, + 0,0,0,0,0,0,0,1, 2,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,2, 3,0,0,0,0,0,0,0, @@ -33,7 +33,7 @@ int main(int argc, char * argv[]) T out = -1; struct fmpi_task array_sum_task = FMPI_TASK_REGISTER( ctx, array_sum, fmpi_no_stencil(), - fmpi_data_1d_out(ctx, &out, 1), + fmpi_data_out(ctx, &out), fmpi_data_1d_in(ctx, in, in_size) ); fmpi_task_run_sync(ctx, &array_sum_task); diff --git a/include/fmpi_data.h b/include/fmpi_data.h index 4b4a974..7ca407c 100644 --- a/include/fmpi_data.h +++ b/include/fmpi_data.h @@ -52,6 +52,11 @@ typedef struct fmpi_data { /*============================================================================== PUBLIC FUNCTION ==============================================================================*/ +/*------------------------------------------------------------------------------ + fmpi_data_out() +------------------------------------------------------------------------------*/ +#define fmpi_data_out(ctx, data) \ + FMPI_DATA_FUNC(out, data)(ctx, data) /*------------------------------------------------------------------------------ fmpi_data_1d() ------------------------------------------------------------------------------*/ diff --git a/include/internal/generic/fmpi_data_generic.h b/include/internal/generic/fmpi_data_generic.h index 2467456..ca0cb4f 100644 --- a/include/internal/generic/fmpi_data_generic.h +++ b/include/internal/generic/fmpi_data_generic.h @@ -42,6 +42,13 @@ struct fmpi_ctx; #define FMPI_DATA_FUNC(func, data) \ FMPI_GENERIC_FUNC(data, data_##func, FMPI_DATA_TYPES) +#define FMPI_DATA_FUNC_DECLARATION_T(T) \ +struct fmpi_data fmpi_data_out_##T( \ + const struct fmpi_ctx * ctx, T * data \ +) + +FMPI_DECLARE_FUNCS_T(FMPI_DATA_FUNC_DECLARATION_T, FMPI_DATA_TYPES); + #define FMPI_DATA_DECLARATION(D, T) \ struct fmpi_data fmpi_data_##D##d_in_##T( \ const struct fmpi_ctx * ctx, T * data, size_t x, size_t y, size_t z \ diff --git a/src/fmpi_data.c b/src/fmpi_data.c index b98922a..b7a3484 100644 --- a/src/fmpi_data.c +++ b/src/fmpi_data.c @@ -33,6 +33,28 @@ /*============================================================================== PUBLIC FUNCTION DEFINITION ==============================================================================*/ +#define FMPI_DATA_FUNC_DEFINITION_T(T) \ +struct fmpi_data fmpi_data_out_##T( \ + const struct fmpi_ctx * const ctx, T * const data \ +){ \ + assert(ctx != NULL); \ + assert(data != NULL); \ + return (struct fmpi_data){ \ + .type = { \ + .base = FMPI_TYPE_##T, \ + .derived = FMPI_TYPE_NONE, \ + .size = sizeof(T) \ + }, \ + .cnt = 1, \ + .size = sizeof(T), \ + .dim_len = {0, 0, 0}, \ + .dim_cnt = 0, \ + .start = data \ + }; \ +} + +FMPI_DEFINE_FUNCS_T(FMPI_DATA_FUNC_DEFINITION_T, FMPI_DATA_TYPES) + #define FMPI_DATA_DEFINITION(D, T) \ struct fmpi_data fmpi_data_##D##d_in_##T( \ const struct fmpi_ctx * const ctx, T * const data, \ -- GitLab