From 6ab78295cb6bddb675c1e65b59bc9fc603a31737 Mon Sep 17 00:00:00 2001
From: "raphael.bach" <raphael.bach@etu.hesge.ch>
Date: Thu, 23 Jun 2022 18:40:22 +0200
Subject: [PATCH] Add `fmpi_run_task()`

---
 examples/array_sum/main.c |  2 +-
 include/fmpi_core.h       |  4 ++++
 src/fmpi_core.c           | 14 ++++++++++++++
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/examples/array_sum/main.c b/examples/array_sum/main.c
index 3278d84..5310347 100644
--- a/examples/array_sum/main.c
+++ b/examples/array_sum/main.c
@@ -36,7 +36,7 @@ int main(int argc, char * argv[])
         fmpi_data_out(ctx, &out),
         fmpi_data_1d_in(ctx, in, in_size)
     );
-    fmpi_task_run_sync(ctx, &array_sum_task);
+    fmpi_run_task(ctx, &array_sum_task);
     printf("rank=%d sum=%ld\n", fmpi_world_rank(ctx), out);
     fmpi_exit(&ctx);
     return EXIT_SUCCESS;
diff --git a/include/fmpi_core.h b/include/fmpi_core.h
index f379529..0a91cd5 100644
--- a/include/fmpi_core.h
+++ b/include/fmpi_core.h
@@ -126,6 +126,10 @@ int fmpi_world_rank(const struct fmpi_ctx * ctx);
     fmpi_world_barrier()
 ------------------------------------------------------------------------------*/
 int fmpi_world_barrier(const struct fmpi_ctx * ctx);
+/*------------------------------------------------------------------------------
+    fmpi_run_task()
+------------------------------------------------------------------------------*/
+int fmpi_run_task(const struct fmpi_ctx * ctx, const struct fmpi_task * task);
 /*==============================================================================
     MACRO
 ==============================================================================*/
diff --git a/src/fmpi_core.c b/src/fmpi_core.c
index 99a4ff2..7eeb456 100644
--- a/src/fmpi_core.c
+++ b/src/fmpi_core.c
@@ -28,6 +28,7 @@
 #include <stdio.h>  // fprintf()
 #include <stdlib.h> // NULL, abort()
 // Internal
+#include "fmpi_task.h"
 #include "internal/fmpi_ctx.h"
 #include "internal/fmpi_error.h"
 #include "internal/fmpi_mpi.h"
@@ -94,3 +95,16 @@ int fmpi_world_barrier(const struct fmpi_ctx * const ctx)
     }
     return err_id;
 }
+/*------------------------------------------------------------------------------
+    fmpi_run_task()
+------------------------------------------------------------------------------*/
+int fmpi_run_task(
+    const struct fmpi_ctx * const ctx, const struct fmpi_task * const task
+){
+    assert(ctx != NULL);
+    assert(task != NULL);
+    if(task->type == FMPI_TASK_TYPE_SYNC) {
+        return fmpi_task_run_sync(ctx, task);
+    }
+    return fmpi_task_run_async(ctx, task);
+}
-- 
GitLab