From bc64a248a72087787cbf73b219360baf2b0caf5e Mon Sep 17 00:00:00 2001
From: "raphael.bach" <raphael.bach@etu.hesge.ch>
Date: Wed, 15 Jun 2022 01:45:11 +0200
Subject: [PATCH] Add `fmpi_task_run_async()`

- Rename `fmpi_task_run()` to `fmpi_task_run_sync()`
- Rename `FMPI_TASK_FUTHARK_SYNC()` to `FMPI_TASK_FUTHARK()`
- Remove `FMPI_TASK_FUTHARK_ASYNC()`
---
 include/fmpi_task.h                          | 57 +++++++++-----------
 include/internal/generic/fmpi_task_generic.h |  1 -
 src/fmpi_task.c                              | 17 ++++--
 3 files changed, 40 insertions(+), 35 deletions(-)

diff --git a/include/fmpi_task.h b/include/fmpi_task.h
index 39d9f88..7f83530 100644
--- a/include/fmpi_task.h
+++ b/include/fmpi_task.h
@@ -124,10 +124,10 @@ struct fmpi_task fmpi_task_register(
     struct fmpi_stencil stencil, const struct fmpi_task_args * args
 );
 /*------------------------------------------------------------------------------
-    fmpi_task_run()
+    fmpi_task_run_sync()
 ------------------------------------------------------------------------------*/
 /**
- * TODO
+ * Runs a task synchronously.
  *
  * @param[in] ctx  : A pointer to a fmpi_ctx.
  * @param[in] task : A pointer to a fmpi_task.
@@ -142,43 +142,43 @@ struct fmpi_task fmpi_task_register(
  *  TODO
  * }
  */
-void fmpi_task_run(const struct fmpi_ctx * ctx, const struct fmpi_task * task);
-/*==============================================================================
-    MACRO
-==============================================================================*/
+void fmpi_task_run_sync(const struct fmpi_ctx * ctx, const struct fmpi_task * task);
 /*------------------------------------------------------------------------------
-    FMPI_TASK_REGISTER()
-------------------------------------------------------------------------------*/
-#define FMPI_TASK_REGISTER(ctx, func, stencil, ...) \
-    FMPI_TASK_REGISTER_IMPL(ctx, func, stencil, __VA_ARGS__)
-/*------------------------------------------------------------------------------
-    FMPI_TASK_FUTHARK_SYNC()
+    fmpi_task_run_async()
 ------------------------------------------------------------------------------*/
 /**
- * Declares and defines a task running a `futhark` function synchronously.
+ * Runs a task asynchronously.
  *
- * @param[in] func    : TODO
- * @param[in] arg_cnt : TODO
+ * @param[in] ctx  : A pointer to a fmpi_ctx.
+ * @param[in] task : A pointer to a fmpi_task.
  *
  * @return Nothing.
  *
  * @warning
- * - \b [UB] \p{func} must not be `NULL`.
+ * - \b [UB] \p{ctx} must not be `NULL`.
+ * - \b [UB] \p{task} must not be `NULL`.
  *
  * @example{
- *  FMPI_TASK_FUTHARK_SYNC(array_sum, 1)
+ *  TODO
  * }
  */
-#define FMPI_TASK_FUTHARK_SYNC(func, arg_cnt) \
-    FMPI_TASK_DEFINITION(func, arg_cnt)
+void fmpi_task_run_async(const struct fmpi_ctx * ctx, const struct fmpi_task * task);
+/*==============================================================================
+    MACRO
+==============================================================================*/
+/*------------------------------------------------------------------------------
+    FMPI_TASK_REGISTER()
+------------------------------------------------------------------------------*/
+#define FMPI_TASK_REGISTER(ctx, func, stencil, ...) \
+    FMPI_TASK_REGISTER_IMPL(ctx, func, stencil, __VA_ARGS__)
 /*------------------------------------------------------------------------------
-    FMPI_TASK_FUTHARK_ASYNC()
+    FMPI_TASK_FUTHARK()
 ------------------------------------------------------------------------------*/
 /**
- * Declares and defines a task running a `futhark` function asynchronously.
+ * Declares and defines a task running a `futhark` function.
  *
- * @param[in] task_name : The name to give to this task.
- * @param[in] func      : A pointer to a futhark function.
+ * @param[in] func    : TODO
+ * @param[in] arg_cnt : TODO
  *
  * @return Nothing.
  *
@@ -186,16 +186,11 @@ void fmpi_task_run(const struct fmpi_ctx * ctx, const struct fmpi_task * task);
  * - \b [UB] \p{func} must not be `NULL`.
  *
  * @example{
- *  FMPI_TASK_FUTHARK_ASYNC(fut_array_sum, futhark_entry_array_sum)
+ *  FMPI_TASK_FUTHARK(array_sum, 1)
  * }
  */
-#define FMPI_TASK_FUTHARK_ASYNC(task_name, func) \
-void task_name(const struct fmpi_ctx * ctx, const struct fmpi_task_args * args); \
-void task_name(const struct fmpi_ctx * const ctx, const struct fmpi_task_args * const args) { \
-    assert(ctx != NULL); \
-    assert(args != NULL); \
-    func(ctx->fut->ctx, args->out.start, args->in[0].start); \
-}
+#define FMPI_TASK_FUTHARK(func, arg_cnt) \
+    FMPI_TASK_DEFINITION(func, arg_cnt)
 /*==============================================================================
     GUARD
 ==============================================================================*/
diff --git a/include/internal/generic/fmpi_task_generic.h b/include/internal/generic/fmpi_task_generic.h
index dee037a..d3173d5 100644
--- a/include/internal/generic/fmpi_task_generic.h
+++ b/include/internal/generic/fmpi_task_generic.h
@@ -43,7 +43,6 @@ void FUNC##_##N( \
     assert(args != NULL); \
     assert(args->cnt == N); \
     FMPI_TASK_FUNC_##N(FUNC, ctx->fut->ctx, args); \
-    fmpi_futhark_sync(ctx->fut); \
 }
 
 #define FMPI_TASK_REGISTER_IMPL(ctx, func, stencil, ...) \
diff --git a/src/fmpi_task.c b/src/fmpi_task.c
index f3554e8..58bc607 100644
--- a/src/fmpi_task.c
+++ b/src/fmpi_task.c
@@ -72,11 +72,22 @@ struct fmpi_task fmpi_task_register(
     return task;
 }
 /*------------------------------------------------------------------------------
-    fmpi_task_run()
+    fmpi_task_run_sync()
 ------------------------------------------------------------------------------*/
-void fmpi_task_run(
+void fmpi_task_run_sync(
     const struct fmpi_ctx * const ctx, const struct fmpi_task * const task
-) {
+){
+    assert(ctx != NULL);
+    assert(task != NULL);
+    task->func(ctx, &task->args);
+    fmpi_futhark_sync(ctx->fut);
+}
+/*------------------------------------------------------------------------------
+    fmpi_task_run_async()
+------------------------------------------------------------------------------*/
+void fmpi_task_run_async(
+    const struct fmpi_ctx * const ctx, const struct fmpi_task * const task
+){
     assert(ctx != NULL);
     assert(task != NULL);
     task->func(ctx, &task->args);
-- 
GitLab