From f2c5b7fd300d06bd23180c580d5953fd02801cf6 Mon Sep 17 00:00:00 2001
From: "raphael.bach" <raphael.bach@etu.hesge.ch>
Date: Mon, 6 Jun 2022 19:19:11 +0200
Subject: [PATCH] Add array of `fmpi_domain` to `fmpi_task`

---
 include/fmpi_task.h |  7 ++++---
 src/fmpi_data.c     |  1 -
 src/fmpi_task.c     | 19 ++++++++++++++++++-
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/include/fmpi_task.h b/include/fmpi_task.h
index 85ff21b..f13eba1 100644
--- a/include/fmpi_task.h
+++ b/include/fmpi_task.h
@@ -27,10 +27,10 @@
     INCLUDE
 ==============================================================================*/
 // C Standard Library
-#include <stddef.h>
+#include <stddef.h> // size_t
 // Internal
 #include "fmpi_data.h"
-#include "internal/fmpi_ctx.h"
+#include "fmpi_domain.h"
 #include "internal/fmpi_futhark.h"
 #include "internal/generic/fmpi_task_generic.h"
 /*==============================================================================
@@ -93,6 +93,7 @@ typedef void (*fmpi_task_func)(
 typedef struct fmpi_task {
     fmpi_task_func func;        //!< TODO
     struct fmpi_task_args args; //!< TODO
+    struct fmpi_domain domains[FMPI_TASK_ARGS_CNT_MAX]; //!< TODO
 } fmpi_task;
 /*==============================================================================
     PUBLIC FUNCTION
@@ -119,7 +120,7 @@ typedef struct fmpi_task {
  * }
  */
 struct fmpi_task fmpi_task_register(
-    const struct fmpi_ctx * ctx, const fmpi_task_func func,
+    struct fmpi_ctx * ctx, const fmpi_task_func func,
     const struct fmpi_task_args * args
 );
 /*------------------------------------------------------------------------------
diff --git a/src/fmpi_data.c b/src/fmpi_data.c
index 97ffa1d..dc53ee7 100644
--- a/src/fmpi_data.c
+++ b/src/fmpi_data.c
@@ -64,7 +64,6 @@ struct fmpi_data fmpi_data_##D##d_in_new_##T( \
     assert(ctx != NULL); \
     assert(data != NULL); \
     const size_t cnt = (x * y * z); \
-    struct futhark_##T##_##D##d * const start = fmpi_futhark_new_##D##d_##T(ctx->fut, data, x, y, z); \
     return (struct fmpi_data){ \
         .type = FMPI_TYPE_##T, \
         .type_size = sizeof(T), \
diff --git a/src/fmpi_task.c b/src/fmpi_task.c
index ee57913..91d4087 100644
--- a/src/fmpi_task.c
+++ b/src/fmpi_task.c
@@ -27,8 +27,12 @@
 #include <assert.h>
 #include <stdint.h> // int64_t
 // Internal
+#include "fmpi_domain.h"
+#include "internal/fmpi_ctx.h"
 #include "internal/fmpi_futhark.h"
 #include "internal/fmpi_futhark_entry.h"
+#include "internal/fmpi_mpi.h"
+#include "internal/generic/fmpi_type.h"
 /*==============================================================================
     PUBLIC FUNCTION DEFINITION
 ==============================================================================*/
@@ -36,14 +40,27 @@
     fmpi_task_run()
 ------------------------------------------------------------------------------*/
 struct fmpi_task fmpi_task_register(
-    const struct fmpi_ctx * const ctx, const fmpi_task_func func,
+    struct fmpi_ctx * const ctx, const fmpi_task_func func,
     const struct fmpi_task_args * const args
 ){
     assert(ctx != NULL);
+    assert(args != NULL);
     struct fmpi_task task = {
         .func = func,
         .args = *args
     };
+    const size_t rank = (size_t)ctx->mpi->rank;
+    for(size_t i = 0; i < task.args.cnt; i++) {
+        task.domains[i] = fmpi_new_domain(ctx, args->in[i]);
+        void * start = fmpi_futhark_new_data(
+            ctx->fut, task.domains[i].parts[rank].start, task.domains[i].data.type,
+            task.domains[i].data.dim_cnt,
+            task.domains[i].parts[rank].dim_len[0],
+            task.domains[i].parts[rank].dim_len[1],
+            task.domains[i].parts[rank].dim_len[2]
+        );
+        task.args.in[i].start = start;
+    }
     futhark_context_sync(ctx->fut->ctx);
     return task;
 }
-- 
GitLab