diff --git a/include/internal/fmpi_mpi.h b/include/internal/fmpi_mpi.h index 9595a1108a885a5439ac07ec6ebdc4913c2884c5..2e9f832740ded562f29dcb378bb958d3ede045ed 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 f00a7493799c74f1a28f885799eb39394edff1e3..03da923bb3119230c7b1313a4cc43017a8a0e04d 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]; +}