From 911363549a9bcc73898003b603e2a656b76f8234 Mon Sep 17 00:00:00 2001
From: "raphael.bach" <raphael.bach@etu.hesge.ch>
Date: Thu, 23 Jun 2022 19:11:38 +0200
Subject: [PATCH] Add `fmpi_futhark_get_data_async()`

---
 include/internal/fmpi_futhark.h |  7 +++++++
 src/fmpi_futhark.c              | 21 ++++++++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/include/internal/fmpi_futhark.h b/include/internal/fmpi_futhark.h
index 99673c4..c87d0a0 100644
--- a/include/internal/fmpi_futhark.h
+++ b/include/internal/fmpi_futhark.h
@@ -139,6 +139,13 @@ void * fmpi_futhark_get_data_sync(
     const struct fmpi_futhark_ctx * ctx, void * in, void * out,
     enum fmpi_type_base type, size_t dim_cnt
 );
+/*------------------------------------------------------------------------------
+    fmpi_futhark_get_data_async()
+------------------------------------------------------------------------------*/
+void * fmpi_futhark_get_data_async(
+    const struct fmpi_futhark_ctx * ctx, void * in, void * out,
+    enum fmpi_type_base type, size_t dim_cnt
+);
 /*==============================================================================
    MACRO
 ==============================================================================*/
diff --git a/src/fmpi_futhark.c b/src/fmpi_futhark.c
index 112a8ea..991d4df 100644
--- a/src/fmpi_futhark.c
+++ b/src/fmpi_futhark.c
@@ -161,7 +161,7 @@ void * fmpi_futhark_new_data(
     return fmpi_futhark_new_data_func_list[idx](ctx, data, x, y, z);
 }
 /*------------------------------------------------------------------------------
-    fmpi_futhark_get_data()
+    fmpi_futhark_get_data_sync()
 ------------------------------------------------------------------------------*/
 void * fmpi_futhark_get_data_sync(
     const struct fmpi_futhark_ctx * const ctx, void * const in, void * const out,
@@ -183,6 +183,25 @@ void * fmpi_futhark_get_data_sync(
     }
     return out;
 }
+/*------------------------------------------------------------------------------
+    fmpi_futhark_get_data_async()
+------------------------------------------------------------------------------*/
+void * fmpi_futhark_get_data_async(
+    const struct fmpi_futhark_ctx * const ctx, void * const in, void * const out,
+    const enum fmpi_type_base type, const size_t dim_cnt
+){
+    assert(ctx != NULL);
+    assert(in != NULL);
+    assert(out != NULL);
+    assert(dim_cnt <= FMPI_DIM_MAX);
+    const size_t idx = FMPI_PRIV_FUTHARK_FUNC_IDX(dim_cnt, type);
+    const int err = fmpi_futhark_get_data_func_list[idx](ctx, in, out);
+    if(err != FUTHARK_SUCCESS) {
+        FMPI_RAISE_FUTHARK_ERROR(ctx, "futhark_values_##T##_##D##d() failed!");
+        return NULL;
+    }
+    return out;
+}
 
 #define FMPI_FUTHARK_DEFINITION(D, T) \
 void * fmpi_futhark_new_##D##d_##T( \
-- 
GitLab