Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Bring C++ for MPI_Group.
authordegomme <augustin.degomme@unibas.ch>
Sun, 5 Mar 2017 20:00:03 +0000 (21:00 +0100)
committerdegomme <augustin.degomme@unibas.ch>
Sun, 5 Mar 2017 20:00:03 +0000 (21:00 +0100)
The worm is in the apple.

17 files changed:
include/smpi/forward.hpp [new file with mode: 0644]
include/smpi/smpi.h
src/smpi/colls/bcast-mvapich-smp.cpp
src/smpi/colls/gather-mvapich.cpp
src/smpi/colls/reduce-mvapich-two-level.cpp
src/smpi/colls/scatter-mvapich-two-level.cpp
src/smpi/private.h
src/smpi/smpi_base.cpp
src/smpi/smpi_comm.cpp
src/smpi/smpi_deployment.cpp
src/smpi/smpi_global.cpp
src/smpi/smpi_group.cpp
src/smpi/smpi_group.hpp [new file with mode: 0644]
src/smpi/smpi_pmpi.cpp
src/smpi/smpi_replay.cpp
src/smpi/smpi_rma.cpp
src/smpi/smpi_topo.cpp

diff --git a/include/smpi/forward.hpp b/include/smpi/forward.hpp
new file mode 100644 (file)
index 0000000..d93e895
--- /dev/null
@@ -0,0 +1,29 @@
+/* Copyright (c) 2016. The SimGrid Team. All rights reserved.          */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef SIMGRID_SMPI_FORWARD_HPP
+#define SIMGRID_SMPI_FORWARD_HPP
+
+
+#ifdef __cplusplus
+
+#include <boost/intrusive_ptr.hpp>
+namespace simgrid {
+namespace SMPI {
+
+class Group;
+
+}
+}
+
+typedef simgrid::SMPI::Group SMPI_Group;
+
+#else
+
+typedef struct SMPI_Group SMPI_Group;
+
+#endif
+
+#endif
index d87e94d..bd54ea2 100644 (file)
@@ -18,6 +18,8 @@
 #include <xbt/function_types.h>
 #include "simgrid/datatypes.h"
 
+#include "forward.hpp"
+
 #ifdef _WIN32
 #define MPI_CALL(type,name,args) \
   type name args; \
@@ -363,9 +365,8 @@ XBT_PUBLIC_DATA( MPI_Op ) MPI_REPLACE;
 
 struct s_smpi_mpi_topology;
 typedef struct s_smpi_mpi_topology *MPI_Topology;
-                                   
-struct s_smpi_mpi_group;
-typedef struct s_smpi_mpi_group *MPI_Group;
+
+typedef SMPI_Group* MPI_Group;
 
 #define MPI_GROUP_NULL ((MPI_Group)NULL)
 
index 5202177..21302b7 100644 (file)
@@ -35,6 +35,7 @@
  *      See COPYRIGHT in top-level directory.
  */
 #include "colls_private.h"
+#include "src/smpi/smpi_group.hpp"
 
 
 extern int (*MV2_Bcast_function) (void *buffer, int count, MPI_Datatype datatype,
@@ -113,8 +114,8 @@ int smpi_coll_tuned_bcast_mvapich2_inter_node(void *buffer,
     }
 
     int* leaders_map = smpi_comm_get_leaders_map(comm);
-    leader_of_root = smpi_group_rank(smpi_comm_group(comm),leaders_map[root]);
-    leader_root = smpi_group_rank(smpi_comm_group(leader_comm),leaders_map[root]);
+    leader_of_root = smpi_comm_group(comm)->rank(leaders_map[root]);
+    leader_root = smpi_comm_group(leader_comm)->rank(leaders_map[root]);
     
     
     if (local_size > 1) {
index d1447c1..2202b9e 100644 (file)
@@ -36,7 +36,7 @@
  */
 
 #include "colls_private.h"
-
+#include "src/smpi/smpi_group.hpp"
 
 #define MPIR_Gather_MV2_Direct smpi_coll_tuned_gather_ompi_basic_linear
 #define MPIR_Gather_MV2_two_level_Direct smpi_coll_tuned_gather_ompi_basic_linear
@@ -265,8 +265,8 @@ int smpi_coll_tuned_gather_mvapich2_two_level(void *sendbuf,
     }
     leader_comm = smpi_comm_get_leaders_comm(comm);
     int* leaders_map = smpi_comm_get_leaders_map(comm);
-    leader_of_root = smpi_group_rank(smpi_comm_group(comm),leaders_map[root]);
-    leader_root = smpi_group_rank(smpi_comm_group(leader_comm),leaders_map[root]);
+    leader_of_root = smpi_comm_group(comm)->rank(leaders_map[root]);
+    leader_root = smpi_comm_group(leader_comm)->rank(leaders_map[root]);
     /* leader_root is the rank of the leader of the root in leader_comm. 
      * leader_root is to be used as the root of the inter-leader gather ops 
      */
index 8bb18d0..d810f75 100644 (file)
@@ -36,6 +36,7 @@
  */
 
 #include "colls_private.h"
+#include "src/smpi/smpi_group.hpp"
 #define MV2_INTRA_SHMEM_REDUCE_MSG 2048
 
 #define mv2_g_shmem_coll_max_msg_size (1 << 17)
@@ -108,8 +109,8 @@ int smpi_coll_tuned_reduce_mvapich2_two_level( void *sendbuf,
     
     leader_comm = smpi_comm_get_leaders_comm(comm);
     int* leaders_map = smpi_comm_get_leaders_map(comm);
-    leader_of_root = smpi_group_rank(smpi_comm_group(comm),leaders_map[root]);
-    leader_root = smpi_group_rank(smpi_comm_group(leader_comm),leaders_map[root]);
+    leader_of_root = smpi_comm_group(comm)->rank(leaders_map[root]);
+    leader_root = smpi_comm_group(leader_comm)->rank(leaders_map[root]);
 
     is_commutative=smpi_op_is_commute(op);
 
index 695f08b..09f5615 100644 (file)
@@ -35,6 +35,7 @@
  *      See COPYRIGHT in top-level directory.
  */
 #include "colls_private.h"
+#include "src/smpi/smpi_group.hpp"
 
 #define MPIR_Scatter_MV2_Binomial smpi_coll_tuned_scatter_ompi_binomial
 #define MPIR_Scatter_MV2_Direct smpi_coll_tuned_scatter_ompi_basic_linear
@@ -113,8 +114,8 @@ int smpi_coll_tuned_scatter_mvapich2_two_level_direct(void *sendbuf,
 
         leader_comm = smpi_comm_get_leaders_comm(comm);
         int* leaders_map = smpi_comm_get_leaders_map(comm);
-        leader_of_root = smpi_group_rank(smpi_comm_group(comm),leaders_map[root]);
-        leader_root = smpi_group_rank(smpi_comm_group(leader_comm),leaders_map[root]);
+        leader_of_root = smpi_comm_group(comm)->rank(leaders_map[root]);
+        leader_root = smpi_comm_group(leader_comm)->rank(leaders_map[root]);
         /* leader_root is the rank of the leader of the root in leader_comm.
          * leader_root is to be used as the root of the inter-leader gather ops
          */
@@ -296,8 +297,8 @@ int smpi_coll_tuned_scatter_mvapich2_two_level_binomial(void *sendbuf,
         }
         leader_comm = smpi_comm_get_leaders_comm(comm);
         int* leaders_map = smpi_comm_get_leaders_map(comm);
-        leader_of_root = smpi_group_rank(smpi_comm_group(comm),leaders_map[root]);
-        leader_root = smpi_group_rank(smpi_comm_group(leader_comm),leaders_map[root]);
+        leader_of_root = smpi_comm_group(comm)->rank(leaders_map[root]);
+        leader_root = smpi_comm_group(leader_comm)->rank(leaders_map[root]);
         /* leader_root is the rank of the leader of the root in leader_comm.
          * leader_root is to be used as the root of the inter-leader gather ops
          */
index 30d679f..52b5803 100644 (file)
@@ -245,17 +245,6 @@ XBT_PRIVATE void smpi_op_destroy(MPI_Op op);
 XBT_PRIVATE void smpi_op_set_fortran(MPI_Op op);
 XBT_PRIVATE void smpi_op_apply(MPI_Op op, void *invec, void *inoutvec, int *len, MPI_Datatype * datatype);
 
-XBT_PRIVATE MPI_Group smpi_group_new(int size);
-XBT_PRIVATE MPI_Group smpi_group_copy(MPI_Group origin);
-XBT_PRIVATE void smpi_group_destroy(MPI_Group group);
-XBT_PRIVATE void smpi_group_set_mapping(MPI_Group group, int index, int rank);
-XBT_PRIVATE int smpi_group_index(MPI_Group group, int rank);
-XBT_PRIVATE int smpi_group_rank(MPI_Group group, int index);
-XBT_PRIVATE int smpi_group_use(MPI_Group group);
-XBT_PRIVATE int smpi_group_unuse(MPI_Group group);
-XBT_PRIVATE int smpi_group_size(MPI_Group group);
-XBT_PRIVATE int smpi_group_compare(MPI_Group group1, MPI_Group group2);
-XBT_PRIVATE int smpi_group_incl(MPI_Group group, int n, int* ranks, MPI_Group* newgroup);
 
 XBT_PRIVATE MPI_Topology smpi_comm_topo(MPI_Comm comm);
 XBT_PRIVATE MPI_Comm smpi_comm_new(MPI_Group group, MPI_Topology topo);
index 0ec0ca0..8ca91f9 100644 (file)
@@ -17,6 +17,7 @@
 #include "surf/surf.h"
 #include "simgrid/sg_config.h"
 #include "smpi/smpi_utils.hpp"
+#include "src/smpi/smpi_group.hpp"
 #include "colls/colls.h"
 #include <simgrid/s4u/host.hpp>
 
@@ -259,7 +260,7 @@ MPI_Request smpi_mpi_send_init(void *buf, int count, MPI_Datatype datatype, int
 {
   MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
   request = build_request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, smpi_process_index(),
-                          smpi_group_index(smpi_comm_group(comm), dst), tag, comm, PERSISTENT | SEND | PREPARED);
+                          smpi_comm_group(comm)->index(dst), tag, comm, PERSISTENT | SEND | PREPARED);
   return request;
 }
 
@@ -267,7 +268,7 @@ MPI_Request smpi_mpi_ssend_init(void *buf, int count, MPI_Datatype datatype, int
 {
   MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
   request = build_request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, smpi_process_index(),
-                        smpi_group_index(smpi_comm_group(comm), dst), tag, comm, PERSISTENT | SSEND | SEND | PREPARED);
+                        smpi_comm_group(comm)->index(dst), tag, comm, PERSISTENT | SSEND | SEND | PREPARED);
   return request;
 }
 
@@ -275,7 +276,7 @@ MPI_Request smpi_mpi_recv_init(void *buf, int count, MPI_Datatype datatype, int
 {
   MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
   request = build_request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype,
-                          src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : smpi_group_index(smpi_comm_group(comm), src),
+                          src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE : smpi_comm_group(comm)->index(src),
                           smpi_process_index(), tag, comm, PERSISTENT | RECV | PREPARED);
   return request;
 }
@@ -505,7 +506,7 @@ MPI_Request smpi_isend_init(void *buf, int count, MPI_Datatype datatype, int dst
 {
   MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
   request = build_request(buf==MPI_BOTTOM ? nullptr : buf , count, datatype, smpi_process_index(),
-                          smpi_group_index(smpi_comm_group(comm), dst), tag,comm, PERSISTENT | ISEND | SEND | PREPARED);
+                          smpi_comm_group(comm)->index(dst), tag,comm, PERSISTENT | ISEND | SEND | PREPARED);
   return request;
 }
 
@@ -513,7 +514,7 @@ MPI_Request smpi_mpi_isend(void *buf, int count, MPI_Datatype datatype, int dst,
 {
   MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
   request =  build_request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, smpi_process_index(),
-                           smpi_group_index(smpi_comm_group(comm), dst), tag, comm, NON_PERSISTENT | ISEND | SEND);
+                           smpi_comm_group(comm)->index(dst), tag, comm, NON_PERSISTENT | ISEND | SEND);
   smpi_mpi_start(request);
   return request;
 }
@@ -522,7 +523,7 @@ MPI_Request smpi_mpi_issend(void *buf, int count, MPI_Datatype datatype, int dst
 {
   MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
   request = build_request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, smpi_process_index(),
-                        smpi_group_index(smpi_comm_group(comm), dst), tag,comm, NON_PERSISTENT | ISEND | SSEND | SEND);
+                        smpi_comm_group(comm)->index(dst), tag,comm, NON_PERSISTENT | ISEND | SSEND | SEND);
   smpi_mpi_start(request);
   return request;
 }
@@ -531,7 +532,7 @@ MPI_Request smpi_irecv_init(void *buf, int count, MPI_Datatype datatype, int src
 {
   MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
   request = build_request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE :
-                          smpi_group_index(smpi_comm_group(comm), src), smpi_process_index(), tag,
+                          smpi_comm_group(comm)->index(src), smpi_process_index(), tag,
                           comm, PERSISTENT | RECV | PREPARED);
   return request;
 }
@@ -540,7 +541,7 @@ MPI_Request smpi_mpi_irecv(void *buf, int count, MPI_Datatype datatype, int src,
 {
   MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
   request = build_request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, src == MPI_ANY_SOURCE ? MPI_ANY_SOURCE :
-                          smpi_group_index(smpi_comm_group(comm), src), smpi_process_index(), tag, comm,
+                          smpi_comm_group(comm)->index(src), smpi_process_index(), tag, comm,
                           NON_PERSISTENT | RECV);
   smpi_mpi_start(request);
   return request;
@@ -558,7 +559,7 @@ void smpi_mpi_send(void *buf, int count, MPI_Datatype datatype, int dst, int tag
 {
   MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
   request = build_request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, smpi_process_index(),
-                          smpi_group_index(smpi_comm_group(comm), dst), tag, comm, NON_PERSISTENT | SEND);
+                          smpi_comm_group(comm)->index(dst), tag, comm, NON_PERSISTENT | SEND);
 
   smpi_mpi_start(request);
   smpi_mpi_wait(&request, MPI_STATUS_IGNORE);
@@ -569,7 +570,7 @@ void smpi_mpi_ssend(void *buf, int count, MPI_Datatype datatype, int dst, int ta
 {
   MPI_Request request = nullptr; /* MC needs the comm to be set to nullptr during the call */
   request = build_request(buf==MPI_BOTTOM ? nullptr : buf, count, datatype, smpi_process_index(),
-                          smpi_group_index(smpi_comm_group(comm), dst), tag, comm, NON_PERSISTENT | SSEND | SEND);
+                          smpi_comm_group(comm)->index(dst), tag, comm, NON_PERSISTENT | SSEND | SEND);
 
   smpi_mpi_start(request);
   smpi_mpi_wait(&request, MPI_STATUS_IGNORE);
@@ -583,7 +584,7 @@ void smpi_mpi_sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,int d
   MPI_Request requests[2];
   MPI_Status stats[2];
   int myid=smpi_process_index();
-  if ((smpi_group_index(smpi_comm_group(comm), dst) == myid) && (smpi_group_index(smpi_comm_group(comm), src) == myid)){
+  if ((smpi_comm_group(comm)->index(dst) == myid) && (smpi_comm_group(comm)->index(src) == myid)){
       smpi_datatype_copy(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype);
       return;
   }
@@ -612,7 +613,7 @@ static void finish_wait(MPI_Request * request, MPI_Status * status)
   if(!((req->detached != 0) && ((req->flags & SEND) != 0)) && ((req->flags & PREPARED) == 0)){
     if(status != MPI_STATUS_IGNORE) {
       int src = req->src == MPI_ANY_SOURCE ? req->real_src : req->src;
-      status->MPI_SOURCE = smpi_group_rank(smpi_comm_group(req->comm), src);
+      status->MPI_SOURCE = smpi_comm_group(req->comm)->rank(src);
       status->MPI_TAG = req->tag == MPI_ANY_TAG ? req->real_tag : req->tag;
       status->MPI_ERROR = req->truncated != 0 ? MPI_ERR_TRUNCATE : MPI_SUCCESS;
       // this handles the case were size in receive differs from size in send
@@ -775,7 +776,7 @@ void smpi_mpi_probe(int source, int tag, MPI_Comm comm, MPI_Status* status){
 
 void smpi_mpi_iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status){
   MPI_Request request = build_request(nullptr, 0, MPI_CHAR, source == MPI_ANY_SOURCE ? MPI_ANY_SOURCE :
-                 smpi_group_index(smpi_comm_group(comm), source), smpi_comm_rank(comm), tag, comm, PERSISTENT | RECV);
+                 smpi_comm_group(comm)->index(source), smpi_comm_rank(comm), tag, comm, PERSISTENT | RECV);
 
   // to avoid deadlock, we have to sleep some time here, or the timer won't advance and we will only do iprobe simcalls
   // (especially when used as a break condition, such as while(MPI_Iprobe(...)) ... )
@@ -811,7 +812,7 @@ void smpi_mpi_iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status*
     MPI_Request req                            = static_cast<MPI_Request>(sync_comm->src_data);
     *flag = 1;
     if(status != MPI_STATUS_IGNORE && (req->flags & PREPARED) == 0) {
-      status->MPI_SOURCE = smpi_group_rank(smpi_comm_group(comm), req->src);
+      status->MPI_SOURCE = smpi_comm_group(comm)->rank(req->src);
       status->MPI_TAG    = req->tag;
       status->MPI_ERROR  = MPI_SUCCESS;
       status->count      = req->real_size;
index d365751..1ab9eae 100644 (file)
@@ -12,6 +12,7 @@
 #include <xbt/ex.hpp>
 
 #include <simgrid/s4u/host.hpp>
+#include <src/smpi/smpi_group.hpp>
 
 #include "private.h"
 #include "smpi_mpi_dt_private.h"
@@ -92,7 +93,7 @@ int smpi_comm_dup(MPI_Comm comm, MPI_Comm* newcomm){
   if(smpi_privatize_global_variables){ //we need to switch as the called function may silently touch global variables
      smpi_switch_data_segment(smpi_process_index());
    }
-  MPI_Group cp=smpi_group_copy(smpi_comm_group(comm));
+  MPI_Group cp=new simgrid::SMPI::Group(smpi_comm_group(comm));
   (*newcomm) = smpi_comm_new(cp, smpi_comm_topo(comm));
   int ret = MPI_SUCCESS;
 
@@ -139,14 +140,14 @@ int smpi_comm_size(MPI_Comm comm)
 {
   if (comm == MPI_COMM_UNINITIALIZED)
     comm = smpi_process_comm_world();
-  return smpi_group_size(smpi_comm_group(comm));
+  return smpi_comm_group(comm)->getsize();
 }
 
 int smpi_comm_rank(MPI_Comm comm)
 {
   if (comm == MPI_COMM_UNINITIALIZED)
     comm = smpi_process_comm_world();
-  return smpi_group_rank(smpi_comm_group(comm), smpi_process_index());
+  return smpi_comm_group(comm)->rank(smpi_process_index());
 }
 
 void smpi_comm_get_name (MPI_Comm comm, char* name, int* len)
@@ -251,25 +252,25 @@ MPI_Comm smpi_comm_split(MPI_Comm comm, int color, int key)
         rankmap[2 * count + 1] = recvbuf[2 * i + 1];
         count++;
         qsort(rankmap, count, 2 * sizeof(int), &smpi_compare_rankmap);
-        group_out = smpi_group_new(count);
+        group_out = new simgrid::SMPI::Group(count);
         if (i == 0) {
           group_root = group_out; /* Save root's group */
         }
         for (int j = 0; j < count; j++) {
-          int index = smpi_group_index(group, rankmap[2 * j]);
-          smpi_group_set_mapping(group_out, index, j);
+          int index = group->index(rankmap[2 * j]);
+          group_out->set_mapping(index, j);
         }
         MPI_Request* requests = xbt_new(MPI_Request, count);
         int reqs              = 0;
         for (int j = 0; j < count; j++) {
           if(rankmap[2 * j] != 0) {
-            group_snd[reqs]=smpi_group_copy(group_out);
+            group_snd[reqs]=new simgrid::SMPI::Group(group_out);
             requests[reqs] = smpi_mpi_isend(&(group_snd[reqs]), 1, MPI_PTR, rankmap[2 * j], system_tag, comm);
             reqs++;
           }
         }
         if(i != 0) {
-          smpi_group_destroy(group_out);
+          group_out->destroy();
         }
         smpi_mpi_waitall(reqs, requests, MPI_STATUS_IGNORE);
         xbt_free(requests);
@@ -290,7 +291,7 @@ MPI_Comm smpi_comm_split(MPI_Comm comm, int color, int key)
 void smpi_comm_use(MPI_Comm comm){
   if (comm == MPI_COMM_UNINITIALIZED)
     comm = smpi_process_comm_world();
-  smpi_group_use(comm->group);
+  comm->group->use();
   comm->refcount++;
 }
 
@@ -324,7 +325,7 @@ void smpi_comm_unuse(MPI_Comm comm){
   if (comm == MPI_COMM_UNINITIALIZED)
     comm = smpi_process_comm_world();
   comm->refcount--;
-  smpi_group_unuse(comm->group);
+  comm->group->unuse();
 
   if(comm->refcount==0){
     smpi_comm_cleanup_smp(comm);
@@ -370,7 +371,7 @@ void smpi_comm_init_smp(MPI_Comm comm){
   xbt_swag_foreach(process, process_list) {
     int index = process->pid -1;
 
-    if(smpi_group_rank(smpi_comm_group(comm),  index)!=MPI_UNDEFINED){
+    if(smpi_comm_group(comm)->rank(index)!=MPI_UNDEFINED){
         intra_comm_size++;
       //the process is in the comm
       if(index < min_index)
@@ -379,13 +380,13 @@ void smpi_comm_init_smp(MPI_Comm comm){
     }
   }
   XBT_DEBUG("number of processes deployed on my node : %d", intra_comm_size);
-  MPI_Group group_intra = smpi_group_new(intra_comm_size);
+  MPI_Group group_intra = new simgrid::SMPI::Group(intra_comm_size);
   i=0;
   process = nullptr;
   xbt_swag_foreach(process, process_list) {
     int index = process->pid -1;
-    if(smpi_group_rank(smpi_comm_group(comm),  index)!=MPI_UNDEFINED){
-      smpi_group_set_mapping(group_intra, index, i);
+    if(smpi_comm_group(comm)->rank(index)!=MPI_UNDEFINED){
+      group_intra->set_mapping(index, i);
       i++;
     }
   }
@@ -426,13 +427,13 @@ void smpi_comm_init_smp(MPI_Comm comm){
   }
   qsort(leader_list, leader_group_size, sizeof(int),compare_ints);
 
-  MPI_Group leaders_group = smpi_group_new(leader_group_size);
+  MPI_Group leaders_group = new simgrid::SMPI::Group(leader_group_size);
 
   MPI_Comm leader_comm = MPI_COMM_NULL;
   if(MPI_COMM_WORLD!=MPI_COMM_UNINITIALIZED && comm!=MPI_COMM_WORLD){
     //create leader_communicator
     for (i=0; i< leader_group_size;i++)
-      smpi_group_set_mapping(leaders_group, leader_list[i], i);
+      leaders_group->set_mapping(leader_list[i], i);
     leader_comm = smpi_comm_new(leaders_group, nullptr);
     smpi_comm_set_leaders_comm(comm, leader_comm);
     smpi_comm_set_intra_comm(comm, comm_intra);
@@ -440,14 +441,14 @@ void smpi_comm_init_smp(MPI_Comm comm){
    //create intracommunicator
   }else{
     for (i=0; i< leader_group_size;i++)
-      smpi_group_set_mapping(leaders_group, leader_list[i], i);
+      leaders_group->set_mapping(leader_list[i], i);
 
     if(smpi_comm_get_leaders_comm(comm)==MPI_COMM_NULL){
       leader_comm = smpi_comm_new(leaders_group, nullptr);
       smpi_comm_set_leaders_comm(comm, leader_comm);
     }else{
       leader_comm=smpi_comm_get_leaders_comm(comm);
-      smpi_group_unuse(leaders_group);
+      leaders_group->unuse();
     }
     smpi_process_set_comm_intra(comm_intra);
   }
@@ -480,9 +481,9 @@ void smpi_comm_init_smp(MPI_Comm comm){
    }
   // Are the ranks blocked ? = allocated contiguously on the SMP nodes
   int is_blocked=1;
-  int prev=smpi_group_rank(smpi_comm_group(comm), smpi_group_index(smpi_comm_group(comm_intra), 0));
+  int prev=smpi_comm_group(comm)->rank(smpi_comm_group(comm_intra)->index(0));
     for (i=1; i<my_local_size; i++){
-      int that=smpi_group_rank(smpi_comm_group(comm),smpi_group_index(smpi_comm_group(comm_intra), i));
+      int that=smpi_comm_group(comm)->rank(smpi_comm_group(comm_intra)->index(i));
       if(that!=prev+1){
         is_blocked=0;
         break;
index d9ad5ac..fc75d75 100644 (file)
@@ -9,6 +9,7 @@
 #include "xbt/dict.h"
 #include "xbt/log.h"
 #include "xbt/sysdep.h"
+#include <src/smpi/smpi_group.hpp>
 
 static xbt_dict_t smpi_instances = nullptr;
 extern int process_count;
@@ -69,12 +70,12 @@ void smpi_deployment_register_process(const char* instance_id, int rank, int ind
   xbt_assert(instance, "Error, unknown instance %s", instance_id);
 
   if(instance->comm_world == MPI_COMM_NULL){
-    MPI_Group group = smpi_group_new(instance->size);
+    MPI_Group group = new simgrid::SMPI::Group(instance->size);
     instance->comm_world = smpi_comm_new(group, nullptr);
   }
   instance->present_processes++;
   index_to_process_data[index]=instance->index+rank;
-  smpi_group_set_mapping(smpi_comm_group(instance->comm_world), index, rank);
+  smpi_comm_group(instance->comm_world)->set_mapping(index, rank);
   *bar = instance->finalization_barrier;
   *comm = &instance->comm_world;
 }
@@ -85,7 +86,7 @@ void smpi_deployment_cleanup_instances(){
   char *name = nullptr;
   xbt_dict_foreach(smpi_instances, cursor, name, instance) {
     if(instance->comm_world!=MPI_COMM_NULL)
-      while (smpi_group_unuse(smpi_comm_group(instance->comm_world)) > 0);
+      while (smpi_comm_group(instance->comm_world)->unuse() > 0);
     xbt_free(instance->comm_world);
     MSG_barrier_destroy(instance->finalization_barrier);
   }
index bcc611c..2ecc4f3 100644 (file)
@@ -15,6 +15,7 @@
 #include "src/mc/mc_replay.h"
 #include "src/msg/msg_private.h"
 #include "src/simix/smx_private.h"
+#include "src/smpi/smpi_group.hpp"
 #include "surf/surf.h"
 #include "xbt/replay.h"
 
@@ -352,9 +353,9 @@ MPI_Comm smpi_process_comm_self()
 {
   smpi_process_data_t data = smpi_process_data();
   if(data->comm_self==MPI_COMM_NULL){
-    MPI_Group group = smpi_group_new(1);
+    MPI_Group group = new simgrid::SMPI::Group(1);
     data->comm_self = smpi_comm_new(group, nullptr);
-    smpi_group_set_mapping(group, smpi_process_index(), 0);
+    group->set_mapping(smpi_process_index(), 0);
   }
 
   return data->comm_self;
@@ -604,13 +605,13 @@ void smpi_global_init()
   //if the process was launched through smpirun script we generate a global mpi_comm_world
   //if not, we let MPI_COMM_NULL, and the comm world will be private to each mpi instance
   if(smpirun){
-    group = smpi_group_new(process_count);
+    group = new simgrid::SMPI::Group(process_count);
     MPI_COMM_WORLD = smpi_comm_new(group, nullptr);
     MPI_Attr_put(MPI_COMM_WORLD, MPI_UNIVERSE_SIZE, reinterpret_cast<void *>(process_count));
     msg_bar_t bar = MSG_barrier_init(process_count);
 
     for (i = 0; i < process_count; i++) {
-      smpi_group_set_mapping(group, i, i);
+      group->set_mapping(i, i);
       process_data[i]->finalization_barrier = bar;
     }
   }
@@ -622,7 +623,7 @@ void smpi_global_destroy()
 
   smpi_bench_destroy();
   if (MPI_COMM_WORLD != MPI_COMM_UNINITIALIZED){
-      while (smpi_group_unuse(smpi_comm_group(MPI_COMM_WORLD)) > 0);
+      while (smpi_comm_group(MPI_COMM_WORLD)->unuse() > 0);
       MSG_barrier_destroy(process_data[0]->finalization_barrier);
   }else{
       smpi_deployment_cleanup_instances();
index 41eb245..b45e31b 100644 (file)
@@ -5,45 +5,38 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "private.h"
+#include "smpi_group.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_group, smpi, "Logging specific to SMPI (group)");
+simgrid::SMPI::Group mpi_MPI_GROUP_EMPTY;
+MPI_Group MPI_GROUP_EMPTY=&mpi_MPI_GROUP_EMPTY;
 
-typedef struct s_smpi_mpi_group {
-  int size;
-  int *rank_to_index_map;
-  xbt_dict_t index_to_rank_map;
-  int refcount;
-} s_smpi_mpi_group_t;
+namespace simgrid{
+namespace SMPI{
 
-static s_smpi_mpi_group_t mpi_MPI_GROUP_EMPTY = {
-  0,                            /* size */
-  nullptr,                         /* rank_to_index_map */
-  nullptr,                         /* index_to_rank_map */
-  1,                            /* refcount: start > 0 so that this group never gets freed */
-};
-
-MPI_Group MPI_GROUP_EMPTY = &mpi_MPI_GROUP_EMPTY;
+Group::Group()
+{
+  m_size=0;                            /* size */
+  m_rank_to_index_map=nullptr;                         /* m_rank_to_index_map */
+  m_index_to_rank_map=nullptr;                         /* m_index_to_rank_map */
+  m_refcount=1;                            /* m_refcount: start > 0 so that this group never gets freed */
+}
 
-MPI_Group smpi_group_new(int size)
+Group::Group(int n)
 {
-  MPI_Group group;
   int i;
 
-  group = xbt_new(s_smpi_mpi_group_t, 1);
-  group->size = size;
-  group->rank_to_index_map = xbt_new(int, size);
-  group->index_to_rank_map = xbt_dict_new_homogeneous(xbt_free_f);
-  group->refcount = 1;
-  for (i = 0; i < size; i++) {
-    group->rank_to_index_map[i] = MPI_UNDEFINED;
+  m_size = n;
+  m_rank_to_index_map = xbt_new(int, m_size);
+  m_index_to_rank_map = xbt_dict_new_homogeneous(xbt_free_f);
+  m_refcount = 1;
+  for (i = 0; i < m_size; i++) {
+    m_rank_to_index_map[i] = MPI_UNDEFINED;
   }
-
-  return group;
 }
 
-MPI_Group smpi_group_copy(MPI_Group origin)
+Group::Group(MPI_Group origin)
 {
-  MPI_Group group=origin;
   char *key;
   char *ptr_rank;
   xbt_dict_cursor_t cursor = nullptr;
@@ -52,67 +45,70 @@ MPI_Group smpi_group_copy(MPI_Group origin)
   if(origin != MPI_GROUP_NULL
             && origin != MPI_GROUP_EMPTY)
     {
-      group = xbt_new(s_smpi_mpi_group_t, 1);
-      group->size = origin->size;
-      group->rank_to_index_map = xbt_new(int, group->size);
-      group->index_to_rank_map = xbt_dict_new_homogeneous(xbt_free_f);
-      group->refcount = 1;
-      for (i = 0; i < group->size; i++) {
-        group->rank_to_index_map[i] = origin->rank_to_index_map[i];
+      m_size = origin->getsize();
+      m_rank_to_index_map = xbt_new(int, m_size);
+      m_index_to_rank_map = xbt_dict_new_homogeneous(xbt_free_f);
+      m_refcount = 1;
+      for (i = 0; i < m_size; i++) {
+        m_rank_to_index_map[i] = origin->m_rank_to_index_map[i];
       }
 
-      xbt_dict_foreach(origin->index_to_rank_map, cursor, key, ptr_rank) {
+      xbt_dict_foreach(origin->m_index_to_rank_map, cursor, key, ptr_rank) {
         int * cp = static_cast<int*>(xbt_malloc(sizeof(int)));
         *cp=*reinterpret_cast<int*>(ptr_rank);
-        xbt_dict_set(group->index_to_rank_map, key, cp, nullptr);
+        xbt_dict_set(m_index_to_rank_map, key, cp, nullptr);
       }
     }
+}
 
-  return group;
+Group::~Group()
+{
+  xbt_free(m_rank_to_index_map);
+  xbt_dict_free(&m_index_to_rank_map);
 }
 
-void smpi_group_destroy(MPI_Group group)
+void Group::destroy()
 {
-  if(group!= smpi_comm_group(MPI_COMM_WORLD)
-          && group != MPI_GROUP_NULL
-          && group != MPI_GROUP_EMPTY)
-  smpi_group_unuse(group);
+  if(this != smpi_comm_group(MPI_COMM_WORLD)
+          && this != MPI_GROUP_NULL
+          && this != MPI_GROUP_EMPTY)
+  this->unuse();
 }
 
-void smpi_group_set_mapping(MPI_Group group, int index, int rank)
+void Group::set_mapping(int index, int rank)
 {
   int * val_rank;
 
-  if (rank < group->size) {
-    group->rank_to_index_map[rank] = index;
+  if (rank < m_size) {
+    m_rank_to_index_map[rank] = index;
     if (index!=MPI_UNDEFINED ) {
       val_rank = static_cast<int *>(xbt_malloc(sizeof(int)));
       *val_rank = rank;
 
       char * key = bprintf("%d", index);
-      xbt_dict_set(group->index_to_rank_map, key, val_rank, nullptr);
+      xbt_dict_set(m_index_to_rank_map, key, val_rank, nullptr);
       xbt_free(key);
     }
   }
 }
 
-int smpi_group_index(MPI_Group group, int rank)
+int Group::index(int rank)
 {
   int index = MPI_UNDEFINED;
 
-  if (0 <= rank && rank < group->size) {
-    index = group->rank_to_index_map[rank];
+  if (0 <= rank && rank < m_size) {
+    index = m_rank_to_index_map[rank];
   }
   return index;
 }
 
-int smpi_group_rank(MPI_Group group, int index)
+int Group::rank(int index)
 {
   int * ptr_rank = nullptr;
-  if (group==MPI_GROUP_EMPTY)
+  if (this==MPI_GROUP_EMPTY)
     return MPI_UNDEFINED;
   char * key = bprintf("%d", index);
-  ptr_rank = static_cast<int*>(xbt_dict_get_or_null(group->index_to_rank_map, key));
+  ptr_rank = static_cast<int*>(xbt_dict_get_or_null(m_index_to_rank_map, key));
   xbt_free(key);
 
   if (ptr_rank==nullptr)
@@ -120,42 +116,40 @@ int smpi_group_rank(MPI_Group group, int index)
   return *ptr_rank;
 }
 
-int smpi_group_use(MPI_Group group)
+int Group::use()
 {
-  group->refcount++;
-  return group->refcount;
+  m_refcount++;
+  return m_refcount;
 }
 
-int smpi_group_unuse(MPI_Group group)
+int Group::unuse()
 {
-  group->refcount--;
-  if (group->refcount <= 0) {
-    xbt_free(group->rank_to_index_map);
-    xbt_dict_free(&group->index_to_rank_map);
-    xbt_free(group);
+  m_refcount--;
+  if (m_refcount <= 0) {
+    delete this;
     return 0;
   }
-  return group->refcount;
+  return m_refcount;
 }
 
-int smpi_group_size(MPI_Group group)
+int Group::getsize()
 {
-  return group->size;
+  return m_size;
 }
 
-int smpi_group_compare(MPI_Group group1, MPI_Group group2)
+int Group::compare(MPI_Group group2)
 {
   int result;
-  int i, index, rank, size;
+  int i, index, rank, sz;
 
   result = MPI_IDENT;
-  if (smpi_group_size(group1) != smpi_group_size(group2)) {
+  if (m_size != group2->getsize()) {
     result = MPI_UNEQUAL;
   } else {
-    size = smpi_group_size(group2);
-    for (i = 0; i < size; i++) {
-      index = smpi_group_index(group1, i);
-      rank = smpi_group_rank(group2, index);
+    sz = group2->getsize();
+    for (i = 0; i < sz; i++) {
+      index = this->index(i);
+      rank = group2->rank(index);
       if (rank == MPI_UNDEFINED) {
         result = MPI_UNEQUAL;
         break;
@@ -168,24 +162,233 @@ int smpi_group_compare(MPI_Group group1, MPI_Group group2)
   return result;
 }
 
-int smpi_group_incl(MPI_Group group, int n, int* ranks, MPI_Group* newgroup)
+int Group::incl(int n, int* ranks, MPI_Group* newgroup)
 {
   int i=0, index=0;
   if (n == 0) {
     *newgroup = MPI_GROUP_EMPTY;
-  } else if (n == smpi_group_size(group)) {
-    *newgroup = group;
-    if(group!= smpi_comm_group(MPI_COMM_WORLD)
-              && group != MPI_GROUP_NULL
-              && group != smpi_comm_group(MPI_COMM_SELF)
-              && group != MPI_GROUP_EMPTY)
-    smpi_group_use(group);
+  } else if (n == m_size) {
+    *newgroup = this;
+    if(this!= smpi_comm_group(MPI_COMM_WORLD)
+              && this != MPI_GROUP_NULL
+              && this != smpi_comm_group(MPI_COMM_SELF)
+              && this != MPI_GROUP_EMPTY)
+    this->use();
   } else {
-    *newgroup = smpi_group_new(n);
+    *newgroup = new Group(n);
     for (i = 0; i < n; i++) {
-      index = smpi_group_index(group, ranks[i]);
-      smpi_group_set_mapping(*newgroup, index, i);
+      index = this->index(ranks[i]);
+      (*newgroup)->set_mapping(index, i);
+    }
+  }
+  return MPI_SUCCESS;
+}
+
+int Group::group_union(MPI_Group group2, MPI_Group* newgroup)
+{
+  int size1 = m_size;
+  int size2 = group2->getsize();
+  for (int i = 0; i < size2; i++) {
+    int proc2 = group2->index(i);
+    int proc1 = this->rank(proc2);
+    if (proc1 == MPI_UNDEFINED) {
+      size1++;
+    }
+  }
+  if (size1 == 0) {
+    *newgroup = MPI_GROUP_EMPTY;
+  } else {
+    *newgroup = new simgrid::SMPI::Group(size1);
+    size2 = this->getsize();
+    for (int i = 0; i < size2; i++) {
+      int proc1 = this->index(i);
+      (*newgroup)->set_mapping(proc1, i);
+    }
+    for (int i = size2; i < size1; i++) {
+      int proc2 = group2->index(i - size2);
+      (*newgroup)->set_mapping(proc2, i);
+    }
+  }
+  return MPI_SUCCESS;
+}
+
+int Group::intersection(MPI_Group group2, MPI_Group* newgroup)
+{
+  int size2 = group2->getsize();
+  for (int i = 0; i < size2; i++) {
+    int proc2 = group2->index(i);
+    int proc1 = this->rank(proc2);
+    if (proc1 == MPI_UNDEFINED) {
+      size2--;
+    }
+  }
+  if (size2 == 0) {
+    *newgroup = MPI_GROUP_EMPTY;
+  } else {
+    *newgroup = new simgrid::SMPI::Group(size2);
+    int j=0;
+    for (int i = 0; i < group2->getsize(); i++) {
+      int proc2 = group2->index(i);
+      int proc1 = this->rank(proc2);
+      if (proc1 != MPI_UNDEFINED) {
+        (*newgroup)->set_mapping(proc2, j);
+        j++;
+      }
     }
   }
   return MPI_SUCCESS;
 }
+
+int Group::difference(MPI_Group group2, MPI_Group* newgroup)
+{
+  int newsize = m_size;
+  int size2 = m_size;
+  for (int i = 0; i < size2; i++) {
+    int proc1 = this->index(i);
+    int proc2 = group2->rank(proc1);
+    if (proc2 != MPI_UNDEFINED) {
+      newsize--;
+    }
+  }
+  if (newsize == 0) {
+    *newgroup = MPI_GROUP_EMPTY;
+  } else {
+    *newgroup = new simgrid::SMPI::Group(newsize);
+    for (int i = 0; i < size2; i++) {
+      int proc1 = this->index(i);
+      int proc2 = group2->rank(proc1);
+      if (proc2 == MPI_UNDEFINED) {
+        (*newgroup)->set_mapping(proc1, i);
+      }
+    }
+  }
+  return MPI_SUCCESS;
+}
+
+int Group::excl(int n, int *ranks, MPI_Group * newgroup){
+  int oldsize = m_size;
+  int newsize = oldsize - n;
+  *newgroup = new simgrid::SMPI::Group(newsize);
+  int* to_exclude=xbt_new0(int, m_size);
+  for (int i     = 0; i < oldsize; i++)
+    to_exclude[i]=0;
+  for (int i            = 0; i < n; i++)
+    to_exclude[ranks[i]]=1;
+  int j = 0;
+  for (int i = 0; i < oldsize; i++) {
+    if(to_exclude[i]==0){
+      int index = this->index(i);
+      (*newgroup)->set_mapping(index, j);
+      j++;
+    }
+  }
+  xbt_free(to_exclude);
+  return MPI_SUCCESS;
+
+}
+
+int Group::range_incl(int n, int ranges[][3], MPI_Group * newgroup){
+  int newsize = 0;
+  for (int i = 0; i < n; i++) {
+    for (int rank = ranges[i][0];                    /* First */
+         rank >= 0 && rank < m_size; /* Last */
+         ) {
+      newsize++;
+      if(rank == ranges[i][1]){/*already last ?*/
+        break;
+      }
+      rank += ranges[i][2]; /* Stride */
+      if (ranges[i][0] < ranges[i][1]) {
+        if (rank > ranges[i][1])
+          break;
+      } else {
+        if (rank < ranges[i][1])
+          break;
+      }
+    }
+  }
+  *newgroup = new simgrid::SMPI::Group(newsize);
+  int j     = 0;
+  for (int i = 0; i < n; i++) {
+    for (int rank = ranges[i][0];                    /* First */
+         rank >= 0 && rank < m_size; /* Last */
+         ) {
+      int index = this->index(rank);
+      (*newgroup)->set_mapping(index, j);
+      j++;
+      if(rank == ranges[i][1]){/*already last ?*/
+        break;
+      }
+      rank += ranges[i][2]; /* Stride */
+      if (ranges[i][0] < ranges[i][1]) {
+        if (rank > ranges[i][1])
+          break;
+      } else {
+        if (rank < ranges[i][1])
+          break;
+      }
+    }
+  }
+  return MPI_SUCCESS;
+}
+
+int Group::range_excl(int n, int ranges[][3], MPI_Group * newgroup){
+  int newsize = m_size;
+  for (int i = 0; i < n; i++) {
+    for (int rank = ranges[i][0];                    /* First */
+         rank >= 0 && rank < m_size; /* Last */
+         ) {
+      newsize--;
+      if(rank == ranges[i][1]){/*already last ?*/
+        break;
+      }
+      rank += ranges[i][2]; /* Stride */
+      if (ranges[i][0] < ranges[i][1]) {
+        if (rank > ranges[i][1])
+          break;
+      } else {
+        if (rank < ranges[i][1])
+          break;
+      }
+    }
+  }
+  if (newsize == 0) {
+    *newgroup = MPI_GROUP_EMPTY;
+  } else {
+    *newgroup = new simgrid::SMPI::Group(newsize);
+    int newrank = 0;
+    int oldrank = 0;
+    while (newrank < newsize) {
+      int add = 1;
+      for (int i = 0; i < n; i++) {
+        for (int rank = ranges[i][0]; rank >= 0 && rank < m_size;) {
+          if(rank==oldrank){
+            add = 0;
+            break;
+          }
+          if(rank == ranges[i][1]){/*already last ?*/
+            break;
+          }
+          rank += ranges[i][2]; /* Stride */
+          if (ranges[i][0]<ranges[i][1]){
+            if (rank > ranges[i][1])
+              break;
+          }else{
+            if (rank < ranges[i][1])
+              break;
+          }
+        }
+      }
+      if(add==1){
+        int index = this->index(oldrank);
+        (*newgroup)->set_mapping(index, newrank);
+        newrank++;
+      }
+      oldrank++;
+    }
+  }
+  return MPI_SUCCESS;
+}
+
+}
+}
diff --git a/src/smpi/smpi_group.hpp b/src/smpi/smpi_group.hpp
new file mode 100644 (file)
index 0000000..f016df3
--- /dev/null
@@ -0,0 +1,42 @@
+/* Copyright (c) 2010, 2013-2015. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "private.h"
+
+namespace simgrid{
+namespace SMPI{
+
+class Group {
+  private:
+    int m_size;
+    int *m_rank_to_index_map;
+    xbt_dict_t m_index_to_rank_map;
+    int m_refcount;
+  public:
+
+    Group();
+    Group(int size);
+    Group(Group* origin);
+    ~Group();
+
+    void destroy();
+    void set_mapping(int index, int rank);
+    int index(int rank);
+    int rank(int index);
+    int use();
+    int unuse();
+    int getsize();
+    int compare(MPI_Group group2);
+    int incl(int n, int* ranks, MPI_Group* newgroup);
+    int excl(int n, int *ranks, MPI_Group * newgroup);
+    int group_union(MPI_Group group2, MPI_Group* newgroup);
+    int intersection(MPI_Group group2, MPI_Group* newgroup);
+    int difference(MPI_Group group2, MPI_Group* newgroup);
+    int range_incl(int n, int ranges[][3], MPI_Group * newgroup);
+    int range_excl(int n, int ranges[][3], MPI_Group * newgroup);
+};
+}
+}
index 658588d..0b59547 100644 (file)
@@ -4,6 +4,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include <simgrid/s4u/host.hpp>
+#include <src/smpi/smpi_group.hpp>
 #include <xbt/ex.hpp>
 
 #include "private.h"
@@ -270,7 +271,7 @@ int PMPI_Group_free(MPI_Group * group)
   if (group == nullptr) {
     return MPI_ERR_ARG;
   } else {
-    smpi_group_destroy(*group);
+    (*group)->destroy();
     *group = MPI_GROUP_NULL;
     return MPI_SUCCESS;
   }
@@ -283,7 +284,7 @@ int PMPI_Group_size(MPI_Group group, int *size)
   } else if (size == nullptr) {
     return MPI_ERR_ARG;
   } else {
-    *size = smpi_group_size(group);
+    *size = group->getsize();
     return MPI_SUCCESS;
   }
 }
@@ -295,7 +296,7 @@ int PMPI_Group_rank(MPI_Group group, int *rank)
   } else if (rank == nullptr) {
     return MPI_ERR_ARG;
   } else {
-    *rank = smpi_group_rank(group, smpi_process_index());
+    *rank = group->rank(smpi_process_index());
     return MPI_SUCCESS;
   }
 }
@@ -309,8 +310,8 @@ int PMPI_Group_translate_ranks(MPI_Group group1, int n, int *ranks1, MPI_Group g
       if(ranks1[i]==MPI_PROC_NULL){
         ranks2[i]=MPI_PROC_NULL;
       }else{
-        int index = smpi_group_index(group1, ranks1[i]);
-        ranks2[i] = smpi_group_rank(group2, index);
+        int index = group1->index(ranks1[i]);
+        ranks2[i] = group2->rank(index);
       }
     }
     return MPI_SUCCESS;
@@ -324,7 +325,7 @@ int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result)
   } else if (result == nullptr) {
     return MPI_ERR_ARG;
   } else {
-    *result = smpi_group_compare(group1, group2);
+    *result = group1->compare(group2);
     return MPI_SUCCESS;
   }
 }
@@ -337,30 +338,7 @@ int PMPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup)
   } else if (newgroup == nullptr) {
     return MPI_ERR_ARG;
   } else {
-    int size  = smpi_group_size(group1);
-    int size2 = smpi_group_size(group2);
-    for (int i = 0; i < size2; i++) {
-      int proc2 = smpi_group_index(group2, i);
-      int proc1 = smpi_group_rank(group1, proc2);
-      if (proc1 == MPI_UNDEFINED) {
-        size++;
-      }
-    }
-    if (size == 0) {
-      *newgroup = MPI_GROUP_EMPTY;
-    } else {
-      *newgroup = smpi_group_new(size);
-      size2 = smpi_group_size(group1);
-      for (int i = 0; i < size2; i++) {
-        int proc1 = smpi_group_index(group1, i);
-        smpi_group_set_mapping(*newgroup, proc1, i);
-      }
-      for (int i = size2; i < size; i++) {
-        int proc2 = smpi_group_index(group2, i - size2);
-        smpi_group_set_mapping(*newgroup, proc2, i);
-      }
-    }
-    return MPI_SUCCESS;
+    return group1->group_union(group2, newgroup);
   }
 }
 
@@ -372,29 +350,7 @@ int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2, MPI_Group * newg
   } else if (newgroup == nullptr) {
     return MPI_ERR_ARG;
   } else {
-    int size = smpi_group_size(group2);
-    for (int i = 0; i < size; i++) {
-      int proc2 = smpi_group_index(group2, i);
-      int proc1 = smpi_group_rank(group1, proc2);
-      if (proc1 == MPI_UNDEFINED) {
-        size--;
-      }
-    }
-    if (size == 0) {
-      *newgroup = MPI_GROUP_EMPTY;
-    } else {
-      *newgroup = smpi_group_new(size);
-      int j=0;
-      for (int i = 0; i < smpi_group_size(group2); i++) {
-        int proc2 = smpi_group_index(group2, i);
-        int proc1 = smpi_group_rank(group1, proc2);
-        if (proc1 != MPI_UNDEFINED) {
-          smpi_group_set_mapping(*newgroup, proc2, j);
-          j++;
-        }
-      }
-    }
-    return MPI_SUCCESS;
+    return group1->intersection(group2,newgroup);
   }
 }
 
@@ -405,28 +361,7 @@ int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgro
   } else if (newgroup == nullptr) {
     return MPI_ERR_ARG;
   } else {
-    int size  = smpi_group_size(group1);
-    int size2 = size;
-    for (int i = 0; i < size2; i++) {
-      int proc1 = smpi_group_index(group1, i);
-      int proc2 = smpi_group_rank(group2, proc1);
-      if (proc2 != MPI_UNDEFINED) {
-        size--;
-      }
-    }
-    if (size == 0) {
-      *newgroup = MPI_GROUP_EMPTY;
-    } else {
-      *newgroup = smpi_group_new(size);
-      for (int i = 0; i < size2; i++) {
-        int proc1 = smpi_group_index(group1, i);
-        int proc2 = smpi_group_rank(group2, proc1);
-        if (proc2 == MPI_UNDEFINED) {
-          smpi_group_set_mapping(*newgroup, proc1, i);
-        }
-      }
-    }
-    return MPI_SUCCESS;
+    return group1->difference(group2,newgroup);
   }
 }
 
@@ -437,7 +372,7 @@ int PMPI_Group_incl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
   } else if (newgroup == nullptr) {
     return MPI_ERR_ARG;
   } else {
-    return smpi_group_incl(group, n, ranks, newgroup);
+    return group->incl(n, ranks, newgroup);
   }
 }
 
@@ -452,32 +387,14 @@ int PMPI_Group_excl(MPI_Group group, int n, int *ranks, MPI_Group * newgroup)
       *newgroup = group;
       if (group != smpi_comm_group(MPI_COMM_WORLD)
                 && group != smpi_comm_group(MPI_COMM_SELF) && group != MPI_GROUP_EMPTY)
-      smpi_group_use(group);
-    } else if (n == smpi_group_size(group)) {
+      group->use();
+      return MPI_SUCCESS;
+    } else if (n == group->getsize()) {
       *newgroup = MPI_GROUP_EMPTY;
+      return MPI_SUCCESS;
     } else {
-      int oldsize = smpi_group_size(group);
-      int newsize = oldsize - n;
-      *newgroup = smpi_group_new(newsize);
-
-      int* to_exclude=xbt_new0(int, smpi_group_size(group));
-      for (int i     = 0; i < oldsize; i++)
-        to_exclude[i]=0;
-      for (int i            = 0; i < n; i++)
-        to_exclude[ranks[i]]=1;
-
-      int j = 0;
-      for (int i = 0; i < oldsize; i++) {
-        if(to_exclude[i]==0){
-          int index = smpi_group_index(group, i);
-          smpi_group_set_mapping(*newgroup, index, j);
-          j++;
-        }
-      }
-
-      xbt_free(to_exclude);
+      return group->excl(n,ranks,newgroup);
     }
-    return MPI_SUCCESS;
   }
 }
 
@@ -490,51 +407,10 @@ int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3], MPI_Group * n
   } else {
     if (n == 0) {
       *newgroup = MPI_GROUP_EMPTY;
+      return MPI_SUCCESS;
     } else {
-      int size = 0;
-      for (int i = 0; i < n; i++) {
-        for (int rank = ranges[i][0];                    /* First */
-             rank >= 0 && rank < smpi_group_size(group); /* Last */
-             ) {
-          size++;
-          if(rank == ranges[i][1]){/*already last ?*/
-            break;
-          }
-          rank += ranges[i][2]; /* Stride */
-          if (ranges[i][0] < ranges[i][1]) {
-            if (rank > ranges[i][1])
-              break;
-          } else {
-            if (rank < ranges[i][1])
-              break;
-          }
-        }
-      }
-
-      *newgroup = smpi_group_new(size);
-      int j     = 0;
-      for (int i = 0; i < n; i++) {
-        for (int rank = ranges[i][0];                    /* First */
-             rank >= 0 && rank < smpi_group_size(group); /* Last */
-             ) {
-          int index = smpi_group_index(group, rank);
-          smpi_group_set_mapping(*newgroup, index, j);
-          j++;
-          if(rank == ranges[i][1]){/*already last ?*/
-            break;
-          }
-          rank += ranges[i][2]; /* Stride */
-          if (ranges[i][0] < ranges[i][1]) {
-            if (rank > ranges[i][1])
-              break;
-          } else {
-            if (rank < ranges[i][1])
-              break;
-          }
-        }
-      }
+      return group->range_incl(n,ranges,newgroup);
     }
-    return MPI_SUCCESS;
   }
 }
 
@@ -549,64 +425,11 @@ int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3], MPI_Group * n
       *newgroup = group;
       if (group != smpi_comm_group(MPI_COMM_WORLD) && group != smpi_comm_group(MPI_COMM_SELF) &&
           group != MPI_GROUP_EMPTY)
-        smpi_group_use(group);
+        group->use();
+      return MPI_SUCCESS;
     } else {
-      int size = smpi_group_size(group);
-      for (int i = 0; i < n; i++) {
-        for (int rank = ranges[i][0];                    /* First */
-             rank >= 0 && rank < smpi_group_size(group); /* Last */
-             ) {
-          size--;
-          if(rank == ranges[i][1]){/*already last ?*/
-            break;
-          }
-          rank += ranges[i][2]; /* Stride */
-          if (ranges[i][0] < ranges[i][1]) {
-            if (rank > ranges[i][1])
-              break;
-          } else {
-            if (rank < ranges[i][1])
-              break;
-          }
-        }
-      }
-      if (size == 0) {
-        *newgroup = MPI_GROUP_EMPTY;
-      } else {
-        *newgroup = smpi_group_new(size);
-        int newrank = 0;
-        int oldrank = 0;
-        while (newrank < size) {
-          int add = 1;
-          for (int i = 0; i < n; i++) {
-            for (int rank = ranges[i][0]; rank >= 0 && rank < smpi_group_size(group);) {
-              if(rank==oldrank){
-                add = 0;
-                break;
-              }
-              if(rank == ranges[i][1]){/*already last ?*/
-                break;
-              }
-              rank += ranges[i][2]; /* Stride */
-              if (ranges[i][0]<ranges[i][1]){
-                if (rank > ranges[i][1])
-                  break;
-              }else{
-                if (rank < ranges[i][1])
-                  break;
-              }
-            }
-          }
-          if(add==1){
-            int index = smpi_group_index(group, oldrank);
-            smpi_group_set_mapping(*newgroup, index, newrank);
-            newrank++;
-          }
-          oldrank++;
-        }
-      }
+      return group->range_excl(n,ranges,newgroup);
     }
-    return MPI_SUCCESS;
   }
 }
 
@@ -655,7 +478,7 @@ int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group)
   } else {
     *group = smpi_comm_group(comm);
     if (*group != smpi_comm_group(MPI_COMM_WORLD) && *group != MPI_GROUP_NULL && *group != MPI_GROUP_EMPTY)
-      smpi_group_use(*group);
+      (*group)->use();
     return MPI_SUCCESS;
   }
 }
@@ -670,7 +493,7 @@ int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result)
     if (comm1 == comm2) {       /* Same communicators means same groups */
       *result = MPI_IDENT;
     } else {
-      *result = smpi_group_compare(smpi_comm_group(comm1), smpi_comm_group(comm2));
+      *result = smpi_comm_group(comm1)->compare(smpi_comm_group(comm2));
       if (*result == MPI_IDENT) {
         *result = MPI_CONGRUENT;
       }
@@ -698,11 +521,11 @@ int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm)
     return MPI_ERR_GROUP;
   } else if (newcomm == nullptr) {
     return MPI_ERR_ARG;
-  } else if(smpi_group_rank(group,smpi_process_index())==MPI_UNDEFINED){
+  } else if(group->rank(smpi_process_index())==MPI_UNDEFINED){
     *newcomm= MPI_COMM_NULL;
     return MPI_SUCCESS;
   }else{
-    smpi_group_use(group);
+    group->use();
     *newcomm = smpi_comm_new(group, nullptr);
     return MPI_SUCCESS;
   }
@@ -903,7 +726,7 @@ int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MP
   } else if (src == MPI_PROC_NULL) {
     *request = MPI_REQUEST_NULL;
     retval = MPI_SUCCESS;
-  } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
+  } else if (src!=MPI_ANY_SOURCE && (src >= smpi_comm_group(comm)->getsize() || src <0)){
     retval = MPI_ERR_RANK;
   } else if ((count < 0) || (buf==nullptr && count > 0)) {
     retval = MPI_ERR_COUNT;
@@ -914,7 +737,7 @@ int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MP
   } else {
 
     int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
-    int src_traced = smpi_group_index(smpi_comm_group(comm), src);
+    int src_traced = smpi_comm_group(comm)->index(src);
 
     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
     extra->type = TRACING_IRECV;
@@ -954,7 +777,7 @@ int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MP
   } else if (dst == MPI_PROC_NULL) {
     *request = MPI_REQUEST_NULL;
     retval = MPI_SUCCESS;
-  } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
+  } else if (dst >= smpi_comm_group(comm)->getsize() || dst <0){
     retval = MPI_ERR_RANK;
   } else if ((count < 0) || (buf==nullptr && count > 0)) {
     retval = MPI_ERR_COUNT;
@@ -964,7 +787,7 @@ int PMPI_Isend(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MP
     retval = MPI_ERR_TAG;
   } else {
     int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
-    int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
+    int dst_traced = smpi_comm_group(comm)->index(dst);
     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
     extra->type = TRACING_ISEND;
     extra->src = rank;
@@ -1003,7 +826,7 @@ int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, M
   } else if (dst == MPI_PROC_NULL) {
     *request = MPI_REQUEST_NULL;
     retval = MPI_SUCCESS;
-  } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
+  } else if (dst >= smpi_comm_group(comm)->getsize() || dst <0){
     retval = MPI_ERR_RANK;
   } else if ((count < 0)|| (buf==nullptr && count > 0)) {
     retval = MPI_ERR_COUNT;
@@ -1013,7 +836,7 @@ int PMPI_Issend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, M
     retval = MPI_ERR_TAG;
   } else {
     int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
-    int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
+    int dst_traced = smpi_comm_group(comm)->index(dst);
     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
     extra->type = TRACING_ISSEND;
     extra->src = rank;
@@ -1051,7 +874,7 @@ int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI
     smpi_empty_status(status);
     status->MPI_SOURCE = MPI_PROC_NULL;
     retval = MPI_SUCCESS;
-  } else if (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0)){
+  } else if (src!=MPI_ANY_SOURCE && (src >= smpi_comm_group(comm)->getsize() || src <0)){
     retval = MPI_ERR_RANK;
   } else if ((count < 0) || (buf==nullptr && count > 0)) {
     retval = MPI_ERR_COUNT;
@@ -1061,7 +884,7 @@ int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI
     retval = MPI_ERR_TAG;
   } else {
     int rank               = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
-    int src_traced         = smpi_group_index(smpi_comm_group(comm), src);
+    int src_traced         = smpi_comm_group(comm)->index(src);
     instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
     extra->type            = TRACING_RECV;
     extra->src             = src_traced;
@@ -1079,7 +902,7 @@ int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI
 
     // the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
     if (status != MPI_STATUS_IGNORE) {
-      src_traced = smpi_group_index(smpi_comm_group(comm), status->MPI_SOURCE);
+      src_traced = smpi_comm_group(comm)->index(status->MPI_SOURCE);
       if (!TRACE_smpi_view_internals()) {
         TRACE_smpi_recv(rank, src_traced, rank, tag);
       }
@@ -1101,7 +924,7 @@ int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI
     retval = MPI_ERR_COMM;
   } else if (dst == MPI_PROC_NULL) {
     retval = MPI_SUCCESS;
-  } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
+  } else if (dst >= smpi_comm_group(comm)->getsize() || dst <0){
     retval = MPI_ERR_RANK;
   } else if ((count < 0) || (buf == nullptr && count > 0)) {
     retval = MPI_ERR_COUNT;
@@ -1111,7 +934,7 @@ int PMPI_Send(void *buf, int count, MPI_Datatype datatype, int dst, int tag, MPI
     retval = MPI_ERR_TAG;
   } else {
     int rank               = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
-    int dst_traced         = smpi_group_index(smpi_comm_group(comm), dst);
+    int dst_traced         = smpi_comm_group(comm)->index(dst);
     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
     extra->type            = TRACING_SEND;
     extra->src             = rank;
@@ -1147,7 +970,7 @@ int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MP
     retval = MPI_ERR_COMM;
   } else if (dst == MPI_PROC_NULL) {
     retval = MPI_SUCCESS;
-  } else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0){
+  } else if (dst >= smpi_comm_group(comm)->getsize() || dst <0){
     retval = MPI_ERR_RANK;
   } else if ((count < 0) || (buf==nullptr && count > 0)) {
     retval = MPI_ERR_COUNT;
@@ -1157,7 +980,7 @@ int PMPI_Ssend(void* buf, int count, MPI_Datatype datatype, int dst, int tag, MP
     retval = MPI_ERR_TAG;
   } else {
     int rank               = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
-    int dst_traced         = smpi_group_index(smpi_comm_group(comm), dst);
+    int dst_traced         = smpi_comm_group(comm)->index(dst);
     instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
     extra->type            = TRACING_SSEND;
     extra->src             = rank;
@@ -1197,8 +1020,8 @@ int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dst,
     smpi_empty_status(status);
     status->MPI_SOURCE = MPI_PROC_NULL;
     retval             = MPI_SUCCESS;
-  }else if (dst >= smpi_group_size(smpi_comm_group(comm)) || dst <0 ||
-      (src!=MPI_ANY_SOURCE && (src >= smpi_group_size(smpi_comm_group(comm)) || src <0))){
+  }else if (dst >= smpi_comm_group(comm)->getsize() || dst <0 ||
+      (src!=MPI_ANY_SOURCE && (src >= smpi_comm_group(comm)->getsize() || src <0))){
     retval = MPI_ERR_RANK;
   } else if ((sendcount < 0 || recvcount<0) || 
       (sendbuf==nullptr && sendcount > 0) || (recvbuf==nullptr && recvcount>0)) {
@@ -1208,8 +1031,8 @@ int PMPI_Sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype, int dst,
   } else {
 
   int rank = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
-  int dst_traced = smpi_group_index(smpi_comm_group(comm), dst);
-  int src_traced = smpi_group_index(smpi_comm_group(comm), src);
+  int dst_traced = smpi_comm_group(comm)->index(dst);
+  int src_traced = smpi_comm_group(comm)->index(src);
   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
   extra->type = TRACING_SENDRECV;
   extra->src = src_traced;
@@ -1392,7 +1215,7 @@ int PMPI_Wait(MPI_Request * request, MPI_Status * status)
     if (is_wait_for_receive) {
       if(src_traced==MPI_ANY_SOURCE)
         src_traced = (status!=MPI_STATUS_IGNORE) ?
-          smpi_group_rank(smpi_comm_group(comm), status->MPI_SOURCE) :
+          smpi_comm_group(comm)->rank(status->MPI_SOURCE) :
           src_traced;
       TRACE_smpi_recv(rank, src_traced, dst_traced, tag_traced);
     }
@@ -1442,7 +1265,7 @@ int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * sta
     if (is_wait_for_receive) {
       if(savedvals[*index].src==MPI_ANY_SOURCE)
         src_traced = (status != MPI_STATUSES_IGNORE)
-                         ? smpi_group_rank(smpi_comm_group(savedvals[*index].comm), status->MPI_SOURCE)
+                         ? smpi_comm_group(savedvals[*index].comm)->rank(status->MPI_SOURCE)
                          : savedvals[*index].src;
       TRACE_smpi_recv(rank_traced, src_traced, dst_traced, savedvals[*index].tag);
     }
@@ -1493,7 +1316,7 @@ int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
       if (is_wait_for_receive) {
         if(src_traced==MPI_ANY_SOURCE)
         src_traced = (status!=MPI_STATUSES_IGNORE) ?
-                          smpi_group_rank(smpi_comm_group(savedvals[i].comm), status[i].MPI_SOURCE) : savedvals[i].src;
+                          smpi_comm_group(savedvals[i].comm)->rank(status[i].MPI_SOURCE) : savedvals[i].src;
         TRACE_smpi_recv(rank_traced, src_traced, dst_traced,savedvals[i].tag);
       }
     }
@@ -1548,7 +1371,7 @@ int PMPI_Bcast(void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm c
     retval = MPI_ERR_ARG;
   } else {
     int rank        = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
-    int root_traced = smpi_group_index(smpi_comm_group(comm), root);
+    int root_traced = smpi_comm_group(comm)->index(root);
 
     instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
     extra->type            = TRACING_BCAST;
@@ -1618,7 +1441,7 @@ int PMPI_Gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,void *recvbu
       sendtmptype=recvtype;
     }
     int rank               = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
-    int root_traced        = smpi_group_index(smpi_comm_group(comm), root);
+    int root_traced        = smpi_comm_group(comm)->index(root);
     instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
     extra->type            = TRACING_GATHER;
     extra->root            = root_traced;
@@ -1672,7 +1495,7 @@ int PMPI_Gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recv
     }
 
     int rank               = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
-    int root_traced        = smpi_group_index(smpi_comm_group(comm), root);
+    int root_traced        = smpi_comm_group(comm)->index(root);
     int i                  = 0;
     int size               = smpi_comm_size(comm);
     instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
@@ -1826,7 +1649,7 @@ int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
       recvcount = sendcount;
     }
     int rank               = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
-    int root_traced        = smpi_group_index(smpi_comm_group(comm), root);
+    int root_traced        = smpi_comm_group(comm)->index(root);
     instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
     extra->type            = TRACING_SCATTER;
     extra->root            = root_traced;
@@ -1872,7 +1695,7 @@ int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
       recvcount = sendcounts[smpi_comm_rank(comm)];
     }
     int rank               = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
-    int root_traced        = smpi_group_index(smpi_comm_group(comm), root);
+    int root_traced        = smpi_comm_group(comm)->index(root);
     int i                  = 0;
     int size               = smpi_comm_size(comm);
     instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
@@ -1918,7 +1741,7 @@ int PMPI_Reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype,
     retval = MPI_ERR_ARG;
   } else {
     int rank               = comm != MPI_COMM_NULL ? smpi_process_index() : -1;
-    int root_traced        = smpi_group_index(smpi_comm_group(comm), root);
+    int root_traced        = smpi_comm_group(comm)->index(root);
     instr_extra_data extra = xbt_new0(s_instr_extra_data_t, 1);
     extra->type            = TRACING_REDUCE;
     int known              = 0;
@@ -2636,7 +2459,7 @@ int PMPI_Win_get_group(MPI_Win  win, MPI_Group * group){
     return MPI_ERR_WIN;
   }else {
     smpi_mpi_win_get_group(win, group);
-    smpi_group_use(*group);
+    (*group)->use();
     return MPI_SUCCESS;
   }
 }
@@ -2677,7 +2500,7 @@ int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype,
     int rank = smpi_process_index();
     MPI_Group group;
     smpi_mpi_win_get_group(win, &group);
-    int src_traced = smpi_group_index(group, target_rank);
+    int src_traced = group->index(target_rank);
     TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
 
     retval = smpi_mpi_get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
@@ -2710,7 +2533,7 @@ int PMPI_Put( void *origin_addr, int origin_count, MPI_Datatype origin_datatype,
     int rank = smpi_process_index();
     MPI_Group group;
     smpi_mpi_win_get_group(win, &group);
-    int dst_traced = smpi_group_index(group, target_rank);
+    int dst_traced = group->index(target_rank);
     TRACE_smpi_ptp_in(rank, rank, dst_traced, __FUNCTION__, nullptr);
     TRACE_smpi_send(rank, rank, dst_traced, SMPI_RMA_TAG, origin_count*smpi_datatype_size(origin_datatype));
 
@@ -2747,7 +2570,7 @@ int PMPI_Accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_da
     int rank = smpi_process_index();
     MPI_Group group;
     smpi_mpi_win_get_group(win, &group);
-    int src_traced = smpi_group_index(group, target_rank);
+    int src_traced = group->index(target_rank);
     TRACE_smpi_ptp_in(rank, src_traced, rank, __FUNCTION__, nullptr);
 
     retval = smpi_mpi_accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
index 1b6dd41..38def2b 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "private.h"
 #include "xbt/replay.h"
+#include "src/smpi/smpi_group.hpp"
 #include <unordered_map>
 #include <vector>
 
@@ -217,7 +218,7 @@ static void action_send(const char *const *action)
 
   int rank = smpi_process_index();
 
-  int dst_traced = smpi_group_rank(smpi_comm_group(MPI_COMM_WORLD), to);
+  int dst_traced = smpi_comm_group(MPI_COMM_WORLD)->rank(to);
   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
   extra->type = TRACING_SEND;
   extra->send_size = size;
@@ -248,7 +249,7 @@ static void action_Isend(const char *const *action)
     MPI_CURRENT_TYPE= MPI_DEFAULT_TYPE;
 
   int rank = smpi_process_index();
-  int dst_traced = smpi_group_rank(smpi_comm_group(MPI_COMM_WORLD), to);
+  int dst_traced = smpi_comm_group(MPI_COMM_WORLD)->rank(to);
   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
   extra->type = TRACING_ISEND;
   extra->send_size = size;
@@ -282,7 +283,7 @@ static void action_recv(const char *const *action) {
     MPI_CURRENT_TYPE= MPI_DEFAULT_TYPE;
 
   int rank = smpi_process_index();
-  int src_traced = smpi_group_rank(smpi_comm_group(MPI_COMM_WORLD), from);
+  int src_traced = smpi_comm_group(MPI_COMM_WORLD)->rank(from);
 
   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
   extra->type = TRACING_RECV;
@@ -321,7 +322,7 @@ static void action_Irecv(const char *const *action)
     MPI_CURRENT_TYPE= MPI_DEFAULT_TYPE;
 
   int rank = smpi_process_index();
-  int src_traced = smpi_group_rank(smpi_comm_group(MPI_COMM_WORLD), from);
+  int src_traced = smpi_comm_group(MPI_COMM_WORLD)->rank(from);
   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
   extra->type = TRACING_IRECV;
   extra->send_size = size;
@@ -390,8 +391,8 @@ static void action_wait(const char *const *action){
   int rank = request->comm != MPI_COMM_NULL ? smpi_comm_rank(request->comm) : -1;
 
   MPI_Group group = smpi_comm_group(request->comm);
-  int src_traced = smpi_group_rank(group, request->src);
-  int dst_traced = smpi_group_rank(group, request->dst);
+  int src_traced = group->rank(request->src);
+  int dst_traced = group->rank(request->dst);
   int is_wait_for_receive = request->recv;
   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
   extra->type = TRACING_WAIT;
@@ -469,7 +470,7 @@ static void action_bcast(const char *const *action)
   }
 
   int rank = smpi_process_index();
-  int root_traced = smpi_group_index(smpi_comm_group(MPI_COMM_WORLD), root);
+  int root_traced = smpi_comm_group(MPI_COMM_WORLD)->index(root);
 
   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
   extra->type = TRACING_BCAST;
@@ -501,7 +502,7 @@ static void action_reduce(const char *const *action)
   }
 
   int rank = smpi_process_index();
-  int root_traced = smpi_group_rank(smpi_comm_group(MPI_COMM_WORLD), root);
+  int root_traced = smpi_comm_group(MPI_COMM_WORLD)->rank(root);
   instr_extra_data extra = xbt_new0(s_instr_extra_data_t,1);
   extra->type = TRACING_REDUCE;
   extra->send_size = comm_size;
index 159bbc1..b91fd0f 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "private.h"
 #include <vector>
+#include "src/smpi/smpi_group.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_rma, smpi, "Logging specific to SMPI (RMA operations)");
 
@@ -159,11 +160,11 @@ int smpi_mpi_put( void *origin_addr, int origin_count, MPI_Datatype origin_datat
   if(target_rank != smpi_comm_rank(win->comm)){
     //prepare send_request
     MPI_Request sreq = smpi_rma_send_init(origin_addr, origin_count, origin_datatype, smpi_process_index(),
-        smpi_group_index(smpi_comm_group(win->comm),target_rank), SMPI_RMA_TAG+1, win->comm, MPI_OP_NULL);
+        smpi_comm_group(win->comm)->index(target_rank), SMPI_RMA_TAG+1, win->comm, MPI_OP_NULL);
 
     //prepare receiver request
     MPI_Request rreq = smpi_rma_recv_init(recv_addr, target_count, target_datatype, smpi_process_index(),
-        smpi_group_index(smpi_comm_group(win->comm),target_rank), SMPI_RMA_TAG+1, recv_win->comm, MPI_OP_NULL);
+        smpi_comm_group(win->comm)->index(target_rank), SMPI_RMA_TAG+1, recv_win->comm, MPI_OP_NULL);
 
     //push request to receiver's win
     xbt_mutex_acquire(recv_win->mut);
@@ -197,12 +198,12 @@ int smpi_mpi_get( void *origin_addr, int origin_count, MPI_Datatype origin_datat
   if(target_rank != smpi_comm_rank(win->comm)){
     //prepare send_request
     MPI_Request sreq = smpi_rma_send_init(send_addr, target_count, target_datatype,
-        smpi_group_index(smpi_comm_group(win->comm),target_rank), smpi_process_index(), SMPI_RMA_TAG+2, send_win->comm,
+        smpi_comm_group(win->comm)->index(target_rank), smpi_process_index(), SMPI_RMA_TAG+2, send_win->comm,
         MPI_OP_NULL);
 
     //prepare receiver request
     MPI_Request rreq = smpi_rma_recv_init(origin_addr, origin_count, origin_datatype,
-        smpi_group_index(smpi_comm_group(win->comm),target_rank), smpi_process_index(), SMPI_RMA_TAG+2, win->comm,
+        smpi_comm_group(win->comm)->index(target_rank), smpi_process_index(), SMPI_RMA_TAG+2, win->comm,
         MPI_OP_NULL);
 
     //start the send, with another process than us as sender. 
@@ -240,11 +241,11 @@ int smpi_mpi_accumulate( void *origin_addr, int origin_count, MPI_Datatype origi
     //As the tag will be used for ordering of the operations, add count to it
     //prepare send_request
     MPI_Request sreq = smpi_rma_send_init(origin_addr, origin_count, origin_datatype,
-        smpi_process_index(), smpi_group_index(smpi_comm_group(win->comm),target_rank), SMPI_RMA_TAG+3+win->count, win->comm, op);
+        smpi_process_index(), smpi_comm_group(win->comm)->index(target_rank), SMPI_RMA_TAG+3+win->count, win->comm, op);
 
     //prepare receiver request
     MPI_Request rreq = smpi_rma_recv_init(recv_addr, target_count, target_datatype,
-        smpi_process_index(), smpi_group_index(smpi_comm_group(win->comm),target_rank), SMPI_RMA_TAG+3+win->count, recv_win->comm, op);
+        smpi_process_index(), smpi_comm_group(win->comm)->index(target_rank), SMPI_RMA_TAG+3+win->count, recv_win->comm, op);
 
     win->count++;
     //push request to receiver's win
@@ -278,11 +279,11 @@ int smpi_mpi_win_start(MPI_Group group, int assert, MPI_Win win){
   //naive, blocking implementation.
     int i             = 0;
     int j             = 0;
-    int size          = smpi_group_size(group);
+    int size          = group->getsize();
     MPI_Request* reqs = xbt_new0(MPI_Request, size);
 
     while (j != size) {
-      int src = smpi_group_index(group, j);
+      int src = group->index(j);
       if (src != smpi_process_index() && src != MPI_UNDEFINED) {
         reqs[i] = smpi_irecv_init(nullptr, 0, MPI_CHAR, src, SMPI_RMA_TAG + 4, MPI_COMM_WORLD);
         i++;
@@ -298,7 +299,7 @@ int smpi_mpi_win_start(MPI_Group group, int assert, MPI_Win win){
   xbt_free(reqs);
   win->opened++; //we're open for business !
   win->group=group;
-  smpi_group_use(group);
+  group->use();
   return MPI_SUCCESS;
 }
 
@@ -306,11 +307,11 @@ int smpi_mpi_win_post(MPI_Group group, int assert, MPI_Win win){
   //let's make a synchronous send here
   int i             = 0;
   int j             = 0;
-  int size = smpi_group_size(group);
+  int size = group->getsize();
   MPI_Request* reqs = xbt_new0(MPI_Request, size);
 
   while(j!=size){
-    int dst=smpi_group_index(group,j);
+    int dst=group->index(j);
     if(dst!=smpi_process_index() && dst!=MPI_UNDEFINED){
       reqs[i]=smpi_mpi_send_init(nullptr, 0, MPI_CHAR, dst, SMPI_RMA_TAG+4, MPI_COMM_WORLD);
       i++;
@@ -327,7 +328,7 @@ int smpi_mpi_win_post(MPI_Group group, int assert, MPI_Win win){
   xbt_free(reqs);
   win->opened++; //we're open for business !
   win->group=group;
-  smpi_group_use(group);
+  group->use();
   return MPI_SUCCESS;
 }
 
@@ -338,11 +339,11 @@ int smpi_mpi_win_complete(MPI_Win win){
   XBT_DEBUG("Entering MPI_Win_Complete");
   int i             = 0;
   int j             = 0;
-  int size = smpi_group_size(win->group);
+  int size = win->group->getsize();
   MPI_Request* reqs = xbt_new0(MPI_Request, size);
 
   while(j!=size){
-    int dst=smpi_group_index(win->group,j);
+    int dst=win->group->index(j);
     if(dst!=smpi_process_index() && dst!=MPI_UNDEFINED){
       reqs[i]=smpi_mpi_send_init(nullptr, 0, MPI_CHAR, dst, SMPI_RMA_TAG+5, MPI_COMM_WORLD);
       i++;
@@ -378,7 +379,7 @@ int smpi_mpi_win_complete(MPI_Win win){
   }
   xbt_mutex_release(win->mut);
 
-  smpi_group_unuse(win->group);
+  win->group->unuse();
   win->opened--; //we're closed for business !
   return MPI_SUCCESS;
 }
@@ -387,11 +388,11 @@ int smpi_mpi_win_wait(MPI_Win win){
   //naive, blocking implementation.
   XBT_DEBUG("Entering MPI_Win_Wait");
   int i=0,j=0;
-  int size = smpi_group_size(win->group);
+  int size = win->group->getsize();
   MPI_Request* reqs = xbt_new0(MPI_Request, size);
 
   while(j!=size){
-    int src=smpi_group_index(win->group,j);
+    int src=win->group->index(j);
     if(src!=smpi_process_index() && src!=MPI_UNDEFINED){
       reqs[i]=smpi_irecv_init(nullptr, 0, MPI_CHAR, src,SMPI_RMA_TAG+5, MPI_COMM_WORLD);
       i++;
@@ -424,7 +425,7 @@ int smpi_mpi_win_wait(MPI_Win win){
   }
   xbt_mutex_release(win->mut);
 
-  smpi_group_unuse(win->group);
+  win->group->unuse();
   win->opened--; //we're opened for business !
   return MPI_SUCCESS;
 }
index 57b45a5..fc77a2e 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "xbt/sysdep.h"
 #include "smpi/smpi.h"
+#include "src/smpi/smpi_group.hpp"
 #include "private.h"
 #include <vector>
 #include <math.h>
@@ -137,9 +138,9 @@ int smpi_mpi_cart_create(MPI_Comm comm_old, int ndims, int dims[], int periods[]
     }
     newCart = smpi_cart_topo_create(ndims);
     oldGroup = smpi_comm_group(comm_old);
-    newGroup = smpi_group_new(newSize);
+    newGroup = new simgrid::SMPI::Group(newSize);
     for (int i = 0 ; i < newSize ; i++) {
-      smpi_group_set_mapping(newGroup, smpi_group_index(oldGroup, i), i);
+      newGroup->set_mapping(oldGroup->index(i), i);
     }
 
     newCart->topo.cart->nnodes = newSize;
@@ -159,7 +160,7 @@ int smpi_mpi_cart_create(MPI_Comm comm_old, int ndims, int dims[], int periods[]
   } else {
     if (rank == 0) {
       newCart = smpi_cart_topo_create(ndims);
-      *comm_cart = smpi_comm_new(smpi_group_copy(smpi_comm_group(MPI_COMM_SELF)), newCart);
+      *comm_cart = smpi_comm_new(new simgrid::SMPI::Group(smpi_comm_group(MPI_COMM_SELF)), newCart);
     } else {
       *comm_cart = MPI_COMM_NULL;
     }