From 3e1ae396657ea230995bb94c071a66c52bdf119d Mon Sep 17 00:00:00 2001
From: "raphael.bach" <raphael.bach@etu.hesge.ch>
Date: Sat, 25 Jun 2022 20:59:37 +0200
Subject: [PATCH] Change `data` member of `struct fmpi_domain` to a pointer

---
 include/fmpi_domain.h | 6 ++++--
 src/fmpi_domain.c     | 7 ++++---
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/include/fmpi_domain.h b/include/fmpi_domain.h
index 25c4f32..0b640d2 100644
--- a/include/fmpi_domain.h
+++ b/include/fmpi_domain.h
@@ -42,7 +42,7 @@ struct fmpi_ctx;
  * TODO
  */
 typedef struct fmpi_domain {
-    struct fmpi_data data;    //!< Data composing the domain.
+    const struct fmpi_data * data; //!< Data composing the domain.
     struct fmpi_data * parts; //!< Partitions of the domain after decomposition.
     size_t part_cnt;          //!< Number of partitions.
 } fmpi_domain;
@@ -52,7 +52,9 @@ typedef struct fmpi_domain {
 /*------------------------------------------------------------------------------
     fmpi_new_domain()
 ------------------------------------------------------------------------------*/
-struct fmpi_domain fmpi_new_domain(const struct fmpi_ctx * ctx, struct fmpi_data data);
+struct fmpi_domain fmpi_new_domain(
+    const struct fmpi_ctx * ctx, const struct fmpi_data * data
+);
 /*==============================================================================
     GUARD
 ==============================================================================*/
diff --git a/src/fmpi_domain.c b/src/fmpi_domain.c
index 23cab51..63a8c21 100644
--- a/src/fmpi_domain.c
+++ b/src/fmpi_domain.c
@@ -25,7 +25,8 @@
 #include "fmpi_domain.h"
 // C Standard Library
 #include <assert.h>
-#include <stdlib.h> // size_t, NULL, malloc()
+#include <stdlib.h> // size_t, NULL, malloc(), free()
+#include <string.h> // memcpy()
 // Internal
 #include "fmpi_data.h"
 #include "internal/fmpi_ctx.h"
@@ -51,7 +52,7 @@ static struct fmpi_data * fmpi_partition_block_1d(
     fmpi_new_domain()
 ------------------------------------------------------------------------------*/
 struct fmpi_domain fmpi_new_domain(
-    const struct fmpi_ctx * const ctx, const struct fmpi_data data)
+    const struct fmpi_ctx * const ctx, const struct fmpi_data * const data)
 {
     assert(ctx != NULL);
     const size_t proc_cnt = (size_t)ctx->mpi->size;
@@ -60,7 +61,7 @@ struct fmpi_domain fmpi_new_domain(
         .parts = NULL,
         .part_cnt = proc_cnt
     };
-    domain.parts = fmpi_partition_block_1d(ctx, &data);
+    domain.parts = fmpi_partition_block_1d(ctx, data);
     if(domain.parts == NULL) {
         FMPI_RAISE_ERROR(ctx->err_handler, "FMPI", "fmpi_partition_block_1d() failed!");
     }
-- 
GitLab