From e746e94c5eca29d03a8c82c40508964b6bfff1f8 Mon Sep 17 00:00:00 2001
From: "raphael.bach" <raphael.bach@etu.hesge.ch>
Date: Sun, 26 Jun 2022 01:45:31 +0200
Subject: [PATCH] Add `fmpi_mpi_type()`

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

diff --git a/include/internal/fmpi_mpi.h b/include/internal/fmpi_mpi.h
index 9595a11..2e9f832 100644
--- a/include/internal/fmpi_mpi.h
+++ b/include/internal/fmpi_mpi.h
@@ -27,9 +27,10 @@
     INCLUDE
 ==============================================================================*/
 // External
-#include <mpi.h> // MPI_MAX_PROCESSOR_NAME
+#include <mpi.h> // MPI_MAX_PROCESSOR_NAME, MPI_Datatype
 // Internal
 #include "fmpi_error.h"
+#include "internal/fmpi_type.h"
 /*==============================================================================
     STRUCT
 ==============================================================================*/
@@ -203,6 +204,10 @@ void fmpi_mpi_abort(const struct fmpi_mpi_ctx * ctx);
     fmpi_mpi_world_barrier()
 ------------------------------------------------------------------------------*/
 int fmpi_mpi_world_barrier(const struct fmpi_mpi_ctx * ctx);
+/*------------------------------------------------------------------------------
+    fmpi_mpi_type()
+------------------------------------------------------------------------------*/
+MPI_Datatype fmpi_mpi_type(enum fmpi_type_base type);
 /*==============================================================================
     GUARD
 ==============================================================================*/
diff --git a/src/fmpi_mpi.c b/src/fmpi_mpi.c
index f00a749..03da923 100644
--- a/src/fmpi_mpi.c
+++ b/src/fmpi_mpi.c
@@ -32,6 +32,7 @@
 #include <mpi.h>
 // Internal
 #include "internal/fmpi_error.h"
+#include "internal/fmpi_type.h"
 /*==============================================================================
     DEFINE
 ==============================================================================*/
@@ -185,3 +186,23 @@ int fmpi_mpi_world_barrier(const struct fmpi_mpi_ctx * const ctx)
     }
     return err_id;
 }
+/*------------------------------------------------------------------------------
+    fmpi_mpi_type()
+------------------------------------------------------------------------------*/
+MPI_Datatype fmpi_mpi_type(const enum fmpi_type_base type)
+{
+    const static MPI_Datatype fmpi_mpi_type_list[] = {
+        [FMPI_TYPE_i8]   = MPI_INT8_T  ,
+        [FMPI_TYPE_i16]  = MPI_INT16_T ,
+        [FMPI_TYPE_i32]  = MPI_INT32_T ,
+        [FMPI_TYPE_i64]  = MPI_INT64_T ,
+        [FMPI_TYPE_u8]   = MPI_UINT8_T ,
+        [FMPI_TYPE_u16]  = MPI_UINT16_T,
+        [FMPI_TYPE_u32]  = MPI_UINT32_T,
+        [FMPI_TYPE_u64]  = MPI_UINT64_T,
+        [FMPI_TYPE_f32]  = MPI_FLOAT   ,
+        [FMPI_TYPE_f64]  = MPI_DOUBLE  ,
+        [FMPI_TYPE_bool] = MPI_C_BOOL
+    };
+    return fmpi_mpi_type_list[type];
+}
-- 
GitLab