From 4f5c99b18d18c2b459d0ddd42861aa738462850c Mon Sep 17 00:00:00 2001
From: "raphael.bach" <raphael.bach@etu.hesge.ch>
Date: Fri, 1 Jul 2022 21:43:30 +0200
Subject: [PATCH] Add `fmpi_mpi_world_size()`

---
 include/internal/fmpi_mpi.h |  4 ++++
 src/fmpi_mpi.c              | 14 ++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/include/internal/fmpi_mpi.h b/include/internal/fmpi_mpi.h
index 5de44f6..b77dbbe 100644
--- a/include/internal/fmpi_mpi.h
+++ b/include/internal/fmpi_mpi.h
@@ -243,6 +243,10 @@ int fmpi_mpi_world_reduce_in_place(
 int fmpi_mpi_dims_create(
     const struct fmpi_mpi_ctx * ctx, size_t * const dim_len, size_t dim_cnt
 );
+/*------------------------------------------------------------------------------
+    fmpi_mpi_world_size()
+------------------------------------------------------------------------------*/
+int fmpi_mpi_world_size(const struct fmpi_mpi_ctx * ctx);
 /*==============================================================================
     GUARD
 ==============================================================================*/
diff --git a/src/fmpi_mpi.c b/src/fmpi_mpi.c
index 1af313b..d0499e9 100644
--- a/src/fmpi_mpi.c
+++ b/src/fmpi_mpi.c
@@ -336,3 +336,17 @@ int fmpi_mpi_dims_create(
     }
     return fmpi_mpi_check_error(ctx, err, "MPI_Dims_create");
 }
+/*------------------------------------------------------------------------------
+    fmpi_mpi_world_size()
+------------------------------------------------------------------------------*/
+int fmpi_mpi_world_size(const struct fmpi_mpi_ctx * const ctx)
+{
+    assert(ctx != NULL);
+    int size = FMPI_ERROR;
+    int err = MPI_Comm_size(ctx->world, &size);
+    err = fmpi_mpi_check_error(ctx, err, "MPI_Comm_size");
+    if(err != FMPI_SUCCESS) {
+        return err;
+    }
+    return size;
+}
-- 
GitLab