Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
please codacy: use long form of negation in C++
[simgrid.git] / src / smpi / colls / gather / gather-mvapich.cpp
index 97e1411..407a3b3 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2014. The SimGrid Team.
+/* Copyright (c) 2013-2017. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
 
 #include "../colls_private.h"
 
-#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
-#define MPIR_Gather_intra smpi_coll_tuned_gather_mpich
+
+
+
+
+#define MPIR_Gather_MV2_Direct Coll_gather_ompi_basic_linear::gather
+#define MPIR_Gather_MV2_two_level_Direct Coll_gather_ompi_basic_linear::gather
+#define MPIR_Gather_intra Coll_gather_mpich::gather
 typedef int (*MV2_Gather_function_ptr) (void *sendbuf,
     int sendcnt,
     MPI_Datatype sendtype,
@@ -54,6 +58,10 @@ extern MV2_Gather_function_ptr MV2_Gather_intra_node_function;
 #define TEMP_BUF_HAS_NO_DATA (0)
 #define TEMP_BUF_HAS_DATA (1)
 
+
+namespace simgrid{
+namespace smpi{
+
 /* sendbuf           - (in) sender's buffer
  * sendcnt           - (in) sender's element count
  * sendtype          - (in) sender's data type
@@ -121,7 +129,8 @@ static int MPIR_pt_pt_intra_gather( void *sendbuf, int sendcnt, MPI_Datatype sen
 }
 
 
-int smpi_coll_tuned_gather_mvapich2_two_level(void *sendbuf,
+
+int Coll_gather_mvapich2_two_level::gather(void *sendbuf,
                                             int sendcnt,
                                             MPI_Datatype sendtype,
                                             void *recvbuf,
@@ -146,7 +155,7 @@ int smpi_coll_tuned_gather_mvapich2_two_level(void *sendbuf,
 
     //if not set (use of the algo directly, without mvapich2 selector)
     if(MV2_Gather_intra_node_function==NULL)
-      MV2_Gather_intra_node_function=smpi_coll_tuned_gather_mpich;
+      MV2_Gather_intra_node_function= Coll_gather_mpich::gather;
     
     if(comm->get_leaders_comm()==MPI_COMM_NULL){
       comm->init_smp();
@@ -269,89 +278,80 @@ int smpi_coll_tuned_gather_mvapich2_two_level(void *sendbuf,
     /* 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 
      */
-    if (!comm->is_uniform()) {
-        if (local_rank == 0) {
-            int *displs = NULL;
-            int *recvcnts = NULL;
-            int *node_sizes;
-            int i = 0;
-            /* Node leaders have all the data. But, different nodes can have
-             * different number of processes. Do a Gather first to get the 
-             * buffer lengths at each leader, followed by a Gatherv to move
-             * the actual data */
+    if (not comm->is_uniform()) {
+      if (local_rank == 0) {
+        int* displs   = NULL;
+        int* recvcnts = NULL;
+        int* node_sizes;
+        int i = 0;
+        /* Node leaders have all the data. But, different nodes can have
+         * different number of processes. Do a Gather first to get the
+         * buffer lengths at each leader, followed by a Gatherv to move
+         * the actual data */
+
+        if (leader_comm_rank == leader_root && root != leader_of_root) {
+          /* The root of the Gather operation is not a node-level
+           * leader and this process's rank in the leader_comm
+           * is the same as leader_root */
+          if (rank == root) {
+            leader_gather_buf =
+                smpi_get_tmp_recvbuffer(recvcnt * MAX(recvtype_extent, recvtype_true_extent) * comm_size);
+          } else {
+            leader_gather_buf =
+                smpi_get_tmp_sendbuffer(sendcnt * MAX(sendtype_extent, sendtype_true_extent) * comm_size);
+          }
+          if (leader_gather_buf == NULL) {
+            mpi_errno = MPI_ERR_OTHER;
+            return mpi_errno;
+          }
+        }
 
-            if (leader_comm_rank == leader_root && root != leader_of_root) {
-                /* The root of the Gather operation is not a node-level 
-                 * leader and this process's rank in the leader_comm 
-                 * is the same as leader_root */
-                if(rank == root) { 
-                    leader_gather_buf = smpi_get_tmp_recvbuffer(recvcnt *
-                                                MAX(recvtype_extent,
-                                                recvtype_true_extent) *
-                                                comm_size);
-                } else { 
-                    leader_gather_buf = smpi_get_tmp_sendbuffer(sendcnt *
-                                                MAX(sendtype_extent,
-                                                sendtype_true_extent) *
-                                                comm_size);
-                } 
-                if (leader_gather_buf == NULL) {
-                    mpi_errno =  MPI_ERR_OTHER;
-                    return mpi_errno;
-                }
-            }
+        node_sizes = comm->get_non_uniform_map();
 
-            node_sizes = comm->get_non_uniform_map();
+        if (leader_comm_rank == leader_root) {
+          displs   = static_cast<int*>(xbt_malloc(sizeof(int) * leader_comm_size));
+          recvcnts = static_cast<int*>(xbt_malloc(sizeof(int) * leader_comm_size));
+          if (not displs || not recvcnts) {
+            mpi_errno = MPI_ERR_OTHER;
+            return mpi_errno;
+          }
+        }
 
-            if (leader_comm_rank == leader_root) {
-                displs =  static_cast<int *>(xbt_malloc(sizeof (int) * leader_comm_size));
-                recvcnts =  static_cast<int *>(xbt_malloc(sizeof (int) * leader_comm_size));
-                if (!displs || !recvcnts) {
-                    mpi_errno = MPI_ERR_OTHER;
-                    return mpi_errno;
-                }
-            }
+        if (root == leader_of_root) {
+          /* The root of the gather operation is also the node
+           * leader. Receive into recvbuf and we are done */
+          if (leader_comm_rank == leader_root) {
+            recvcnts[0] = node_sizes[0] * recvcnt;
+            displs[0]   = 0;
 
-            if (root == leader_of_root) {
-                /* The root of the gather operation is also the node 
-                 * leader. Receive into recvbuf and we are done */
-                if (leader_comm_rank == leader_root) {
-                    recvcnts[0] = node_sizes[0] * recvcnt;
-                    displs[0] = 0;
-
-                    for (i = 1; i < leader_comm_size; i++) {
-                        displs[i] = displs[i - 1] + node_sizes[i - 1] * recvcnt;
-                        recvcnts[i] = node_sizes[i] * recvcnt;
-                    }
-                } 
-                smpi_mpi_gatherv(tmp_buf,
-                                         local_size * nbytes,
-                                         MPI_BYTE, recvbuf, recvcnts,
-                                         displs, recvtype,
-                                         leader_root, leader_comm);
-            } else {
-                /* The root of the gather operation is not the node leader. 
-                 * Receive into leader_gather_buf and then send 
-                 * to the root */
-                if (leader_comm_rank == leader_root) {
-                    recvcnts[0] = node_sizes[0] * nbytes;
-                    displs[0] = 0;
-
-                    for (i = 1; i < leader_comm_size; i++) {
-                        displs[i] = displs[i - 1] + node_sizes[i - 1] * nbytes;
-                        recvcnts[i] = node_sizes[i] * nbytes;
-                    }
-                } 
-                smpi_mpi_gatherv(tmp_buf, local_size * nbytes,
-                                         MPI_BYTE, leader_gather_buf,
-                                         recvcnts, displs, MPI_BYTE,
-                                         leader_root, leader_comm);
+            for (i = 1; i < leader_comm_size; i++) {
+              displs[i]   = displs[i - 1] + node_sizes[i - 1] * recvcnt;
+              recvcnts[i] = node_sizes[i] * recvcnt;
             }
-            if (leader_comm_rank == leader_root) {
-                xbt_free(displs);
-                xbt_free(recvcnts);
+          }
+          Colls::gatherv(tmp_buf, local_size * nbytes, MPI_BYTE, recvbuf, recvcnts, displs, recvtype, leader_root,
+                         leader_comm);
+        } else {
+          /* The root of the gather operation is not the node leader.
+           * Receive into leader_gather_buf and then send
+           * to the root */
+          if (leader_comm_rank == leader_root) {
+            recvcnts[0] = node_sizes[0] * nbytes;
+            displs[0]   = 0;
+
+            for (i = 1; i < leader_comm_size; i++) {
+              displs[i]   = displs[i - 1] + node_sizes[i - 1] * nbytes;
+              recvcnts[i] = node_sizes[i] * nbytes;
             }
+          }
+          Colls::gatherv(tmp_buf, local_size * nbytes, MPI_BYTE, leader_gather_buf, recvcnts, displs, MPI_BYTE,
+                         leader_root, leader_comm);
         }
+        if (leader_comm_rank == leader_root) {
+          xbt_free(displs);
+          xbt_free(recvcnts);
+        }
+      }
     } else {
         /* All nodes have the same number of processes. 
          * Just do one Gather to get all 
@@ -410,4 +410,6 @@ int smpi_coll_tuned_gather_mvapich2_two_level(void *sendbuf,
 
     return (mpi_errno);
 }
+}
+}