Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
smpi: many classes died tonight, but that will save kitten on the long term.
[simgrid.git] / src / smpi / colls / barrier / barrier-ompi.cpp
index b49a519..802481f 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2017. The SimGrid Team.
+/* Copyright (c) 2013-2019. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
  * Additional copyrights may follow
  */
 
-#include "../colls_private.h"
-#include "../coll_tuned_topo.h"
-
+#include "../coll_tuned_topo.hpp"
+#include "../colls_private.hpp"
 
 /*
- * Barrier is ment to be a synchronous operation, as some BTLs can mark 
- * a request done before its passed to the NIC and progress might not be made 
- * elsewhere we cannot allow a process to exit the barrier until its last 
+ * Barrier is ment to be a synchronous operation, as some BTLs can mark
+ * a request done before its passed to the NIC and progress might not be made
+ * elsewhere we cannot allow a process to exit the barrier until its last
  * [round of] sends are completed.
  *
- * It is last round of sends rather than 'last' individual send as each pair of 
- * peers can use different channels/devices/btls and the receiver of one of 
+ * It is last round of sends rather than 'last' individual send as each pair of
+ * peers can use different channels/devices/btls and the receiver of one of
  * these sends might be forced to wait as the sender
- * leaves the collective and does not make progress until the next mpi call 
+ * leaves the collective and does not make progress until the next mpi call
  *
  */
 
 /*
  * Simple double ring version of barrier
  *
- * synchronous gurantee made by last ring of sends are synchronous
+ * synchronous guarantee made by last ring of sends are synchronous
  *
  */
-namespace simgrid{
-namespace smpi{
-int Coll_barrier_ompi_doublering::barrier(MPI_Comm comm
-                                            )
+namespace simgrid {
+namespace smpi {
+int barrier__ompi_doublering(MPI_Comm comm)
 {
     int rank, size;
     int left, right;
@@ -61,38 +59,38 @@ int Coll_barrier_ompi_doublering::barrier(MPI_Comm comm
     right = ((rank+1)%size);
 
     if (rank > 0) { /* receive message from the left */
-        Request::recv((void*)NULL, 0, MPI_BYTE, left, 
+        Request::recv((void*)NULL, 0, MPI_BYTE, left,
                                 COLL_TAG_BARRIER, comm,
                                 MPI_STATUS_IGNORE);
     }
 
     /* Send message to the right */
-    Request::send((void*)NULL, 0, MPI_BYTE, right, 
+    Request::send((void*)NULL, 0, MPI_BYTE, right,
                             COLL_TAG_BARRIER,
                              comm);
 
     /* root needs to receive from the last node */
     if (rank == 0) {
-        Request::recv((void*)NULL, 0, MPI_BYTE, left, 
+        Request::recv((void*)NULL, 0, MPI_BYTE, left,
                                 COLL_TAG_BARRIER, comm,
                                 MPI_STATUS_IGNORE);
     }
 
     /* Allow nodes to exit */
     if (rank > 0) { /* post Receive from left */
-        Request::recv((void*)NULL, 0, MPI_BYTE, left, 
+        Request::recv((void*)NULL, 0, MPI_BYTE, left,
                                 COLL_TAG_BARRIER, comm,
                                 MPI_STATUS_IGNORE);
     }
 
     /* send message to the right one */
-    Request::send((void*)NULL, 0, MPI_BYTE, right, 
+    Request::send((void*)NULL, 0, MPI_BYTE, right,
                             COLL_TAG_BARRIER,
                              comm);
+
     /* rank 0 post receive from the last node */
     if (rank == 0) {
-        Request::recv((void*)NULL, 0, MPI_BYTE, left, 
+        Request::recv((void*)NULL, 0, MPI_BYTE, left,
                                 COLL_TAG_BARRIER, comm,
                                 MPI_STATUS_IGNORE);
     }
@@ -106,8 +104,7 @@ int Coll_barrier_ompi_doublering::barrier(MPI_Comm comm
  * To make synchronous, uses sync sends and sync sendrecvs
  */
 
-int Coll_barrier_ompi_recursivedoubling::barrier(MPI_Comm comm
-                                                   )
+int barrier__ompi_recursivedoubling(MPI_Comm comm)
 {
     int rank, size, adjsize;
     int mask, remote;
@@ -115,7 +112,7 @@ int Coll_barrier_ompi_recursivedoubling::barrier(MPI_Comm comm
     rank = comm->rank();
     size = comm->size();
     XBT_DEBUG(
-                 "ompi_coll_tuned_barrier_ompi_recursivedoubling rank %d", 
+                 "ompi_coll_tuned_barrier_ompi_recursivedoubling rank %d",
                  rank);
 
     /* do nearest power of 2 less than size calc */
@@ -165,7 +162,7 @@ int Coll_barrier_ompi_recursivedoubling::barrier(MPI_Comm comm
         if (rank < (size - adjsize)) {
             /* send enter message to higher ranked node */
             remote = rank + adjsize;
-            Request::send((void*)NULL, 0, MPI_BYTE, remote, 
+            Request::send((void*)NULL, 0, MPI_BYTE, remote,
                                     COLL_TAG_BARRIER,
                                      comm);
 
@@ -181,8 +178,7 @@ int Coll_barrier_ompi_recursivedoubling::barrier(MPI_Comm comm
  * To make synchronous, uses sync sends and sync sendrecvs
  */
 
-int Coll_barrier_ompi_bruck::barrier(MPI_Comm comm
-                                       )
+int barrier__ompi_bruck(MPI_Comm comm)
 {
     int rank, size;
     int distance, to, from;
@@ -193,14 +189,14 @@ int Coll_barrier_ompi_bruck::barrier(MPI_Comm comm
                  "ompi_coll_tuned_barrier_ompi_bruck rank %d", rank);
 
     /* exchange data with rank-2^k and rank+2^k */
-    for (distance = 1; distance < size; distance <<= 1) { 
+    for (distance = 1; distance < size; distance <<= 1) {
         from = (rank + size - distance) % size;
         to   = (rank + distance) % size;
 
         /* send message to lower ranked node */
-        Request::sendrecv(NULL, 0, MPI_BYTE, to, 
+        Request::sendrecv(NULL, 0, MPI_BYTE, to,
                                               COLL_TAG_BARRIER,
-                                              NULL, 0, MPI_BYTE, from, 
+                                              NULL, 0, MPI_BYTE, from,
                                               COLL_TAG_BARRIER,
                                               comm, MPI_STATUS_IGNORE);
     }
@@ -214,8 +210,7 @@ int Coll_barrier_ompi_bruck::barrier(MPI_Comm comm
  * To make synchronous, uses sync sends and sync sendrecvs
  */
 /* special case for two processes */
-int Coll_barrier_ompi_two_procs::barrier(MPI_Comm comm
-                                           )
+int barrier__ompi_two_procs(MPI_Comm comm)
 {
     int remote;
 
@@ -224,9 +219,9 @@ int Coll_barrier_ompi_two_procs::barrier(MPI_Comm comm
                  "ompi_coll_tuned_barrier_ompi_two_procs rank %d", remote);
     remote = (remote + 1) & 0x1;
 
-    Request::sendrecv(NULL, 0, MPI_BYTE, remote, 
+    Request::sendrecv(NULL, 0, MPI_BYTE, remote,
                                           COLL_TAG_BARRIER,
-                                          NULL, 0, MPI_BYTE, remote, 
+                                          NULL, 0, MPI_BYTE, remote,
                                           COLL_TAG_BARRIER,
                                           comm, MPI_STATUS_IGNORE);
     return (MPI_SUCCESS);
@@ -247,7 +242,7 @@ int Coll_barrier_ompi_two_procs::barrier(MPI_Comm comm
 
 /* copied function (with appropriate renaming) starts here */
 
-int Coll_barrier_ompi_basic_linear::barrier(MPI_Comm comm)
+int barrier__ompi_basic_linear(MPI_Comm comm)
 {
     int i;
     int size = comm->size();
@@ -256,11 +251,11 @@ int Coll_barrier_ompi_basic_linear::barrier(MPI_Comm comm)
     /* All non-root send & receive zero-length message. */
 
     if (rank > 0) {
-        Request::send (NULL, 0, MPI_BYTE, 0, 
+        Request::send (NULL, 0, MPI_BYTE, 0,
                                  COLL_TAG_BARRIER,
                                   comm);
 
-        Request::recv (NULL, 0, MPI_BYTE, 0, 
+        Request::recv (NULL, 0, MPI_BYTE, 0,
                                  COLL_TAG_BARRIER,
                                  comm, MPI_STATUS_IGNORE);
     }
@@ -270,11 +265,9 @@ int Coll_barrier_ompi_basic_linear::barrier(MPI_Comm comm)
     else {
         MPI_Request* requests;
 
-        requests = (MPI_Request*)malloc( size * sizeof(MPI_Request) );
+        requests = new MPI_Request[size];
         for (i = 1; i < size; ++i) {
-            requests[i] = Request::irecv(NULL, 0, MPI_BYTE, MPI_ANY_SOURCE,
-                                     COLL_TAG_BARRIER, comm
-                                     );
+          requests[i] = Request::irecv(NULL, 0, MPI_BYTE, i, COLL_TAG_BARRIER, comm);
         }
         Request::waitall( size-1, requests+1, MPI_STATUSES_IGNORE );
 
@@ -285,7 +278,7 @@ int Coll_barrier_ompi_basic_linear::barrier(MPI_Comm comm)
                                      );
         }
         Request::waitall( size-1, requests+1, MPI_STATUSES_IGNORE );
-        free( requests );
+        delete[] requests;
     }
 
     /* All done */
@@ -297,9 +290,9 @@ int Coll_barrier_ompi_basic_linear::barrier(MPI_Comm comm)
 
 /*
  * Another recursive doubling type algorithm, but in this case
- * we go up the tree and back down the tree.  
+ * we go up the tree and back down the tree.
  */
-int Coll_barrier_ompi_tree::barrier(MPI_Comm comm)
+int barrier__ompi_tree(MPI_Comm comm)
 {
     int rank, size, depth;
     int jump, partner;
@@ -307,7 +300,7 @@ int Coll_barrier_ompi_tree::barrier(MPI_Comm comm)
     rank = comm->rank();
     size = comm->size();
     XBT_DEBUG(
-                 "ompi_coll_tuned_barrier_ompi_tree %d", 
+                 "ompi_coll_tuned_barrier_ompi_tree %d",
                  rank);
 
     /* Find the nearest power of 2 of the communicator size. */
@@ -317,7 +310,7 @@ int Coll_barrier_ompi_tree::barrier(MPI_Comm comm)
         partner = rank ^ jump;
         if (!(partner & (jump-1)) && partner < size) {
             if (partner > rank) {
-                Request::recv (NULL, 0, MPI_BYTE, partner, 
+                Request::recv (NULL, 0, MPI_BYTE, partner,
                                          COLL_TAG_BARRIER, comm,
                                          MPI_STATUS_IGNORE);
             } else if (partner < rank) {
@@ -327,7 +320,7 @@ int Coll_barrier_ompi_tree::barrier(MPI_Comm comm)
             }
         }
     }
-    
+
     depth>>=1;
     for (jump = depth; jump>0; jump>>=1) {
         partner = rank ^ jump;
@@ -337,7 +330,7 @@ int Coll_barrier_ompi_tree::barrier(MPI_Comm comm)
                                          COLL_TAG_BARRIER,
                                           comm);
             } else if (partner < rank) {
-                Request::recv (NULL, 0, MPI_BYTE, partner, 
+                Request::recv (NULL, 0, MPI_BYTE, partner,
                                          COLL_TAG_BARRIER, comm,
                                          MPI_STATUS_IGNORE);
             }