Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
please sonar on recent SMPI++ code
[simgrid.git] / src / smpi / smpi_base.cpp
index 6efaa9b..141d8e9 100644 (file)
@@ -1,5 +1,4 @@
-/* Copyright (c) 2007-2015. The SimGrid Team.
- * All rights reserved.                                                     */
+/* Copyright (c) 2007-2017. 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. */
@@ -79,9 +78,9 @@ void smpi_mpi_gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
     // Send buffer to root
     Request::send(sendbuf, sendcount, sendtype, root, system_tag, comm);
   } else {
-    smpi_datatype_extent(recvtype, &lb, &recvext);
+    recvtype->extent(&lb, &recvext);
     // Local copy from root
-    smpi_datatype_copy(sendbuf, sendcount, sendtype, static_cast<char*>(recvbuf) + root * recvcount * recvext,
+    Datatype::copy(sendbuf, sendcount, sendtype, static_cast<char*>(recvbuf) + root * recvcount * recvext,
                        recvcount, recvtype);
     // Receive buffers from senders
     MPI_Request *requests = xbt_new(MPI_Request, size - 1);
@@ -97,7 +96,7 @@ void smpi_mpi_gather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
     Request::startall(size - 1, requests);
     Request::waitall(size - 1, requests, MPI_STATUS_IGNORE);
     for (int src = 0; src < size-1; src++) {
-      Request::unuse(&requests[src]);
+      Request::unref(&requests[src]);
     }
     xbt_free(requests);
   }
@@ -116,7 +115,7 @@ void smpi_mpi_reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_
     displs[i] = count;
     count += recvcounts[i];
   }
-  void *tmpbuf = static_cast<void*>(smpi_get_tmp_sendbuffer(count*smpi_datatype_get_extent(datatype)));
+  void *tmpbuf = static_cast<void*>(smpi_get_tmp_sendbuffer(count*datatype->get_extent()));
 
   mpi_coll_reduce_fun(sendbuf, tmpbuf, count, datatype, op, 0, comm);
   smpi_mpi_scatterv(tmpbuf, recvcounts, displs, datatype, recvbuf, recvcounts[rank], datatype, 0, comm);
@@ -137,9 +136,9 @@ void smpi_mpi_gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void
     // Send buffer to root
     Request::send(sendbuf, sendcount, sendtype, root, system_tag, comm);
   } else {
-    smpi_datatype_extent(recvtype, &lb, &recvext);
+    recvtype->extent(&lb, &recvext);
     // Local copy from root
-    smpi_datatype_copy(sendbuf, sendcount, sendtype, static_cast<char*>(recvbuf) + displs[root] * recvext,
+    Datatype::copy(sendbuf, sendcount, sendtype, static_cast<char*>(recvbuf) + displs[root] * recvext,
                        recvcounts[root], recvtype);
     // Receive buffers from senders
     MPI_Request *requests = xbt_new(MPI_Request, size - 1);
@@ -155,7 +154,7 @@ void smpi_mpi_gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, void
     Request::startall(size - 1, requests);
     Request::waitall(size - 1, requests, MPI_STATUS_IGNORE);
     for (int src = 0; src < size-1; src++) {
-      Request::unuse(&requests[src]);
+      Request::unref(&requests[src]);
     }
     xbt_free(requests);
   }
@@ -172,9 +171,9 @@ void smpi_mpi_allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
   int rank = comm->rank();
   int size = comm->size();
   // FIXME: check for errors
-  smpi_datatype_extent(recvtype, &lb, &recvext);
+  recvtype->extent(&lb, &recvext);
   // Local copy from self
-  smpi_datatype_copy(sendbuf, sendcount, sendtype, static_cast<char *>(recvbuf) + rank * recvcount * recvext, recvcount,
+  Datatype::copy(sendbuf, sendcount, sendtype, static_cast<char *>(recvbuf) + rank * recvcount * recvext, recvcount,
                      recvtype);
   // Send/Recv buffers to/from others;
   requests = xbt_new(MPI_Request, 2 * (size - 1));
@@ -192,7 +191,7 @@ void smpi_mpi_allgather(void *sendbuf, int sendcount, MPI_Datatype sendtype,
   Request::startall(2 * (size - 1), requests);
   Request::waitall(2 * (size - 1), requests, MPI_STATUS_IGNORE);
   for (int other = 0; other < 2*(size-1); other++) {
-    Request::unuse(&requests[other]);
+    Request::unref(&requests[other]);
   }
   xbt_free(requests);
 }
@@ -206,9 +205,9 @@ void smpi_mpi_allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, vo
 
   int rank = comm->rank();
   int size = comm->size();
-  smpi_datatype_extent(recvtype, &lb, &recvext);
+  recvtype->extent(&lb, &recvext);
   // Local copy from self
-  smpi_datatype_copy(sendbuf, sendcount, sendtype,
+  Datatype::copy(sendbuf, sendcount, sendtype,
                      static_cast<char *>(recvbuf) + displs[rank] * recvext,recvcounts[rank], recvtype);
   // Send buffers to others;
   MPI_Request *requests = xbt_new(MPI_Request, 2 * (size - 1));
@@ -227,7 +226,7 @@ void smpi_mpi_allgatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype, vo
   Request::startall(2 * (size - 1), requests);
   Request::waitall(2 * (size - 1), requests, MPI_STATUS_IGNORE);
   for (int other = 0; other < 2*(size-1); other++) {
-    Request::unuse(&requests[other]);
+    Request::unref(&requests[other]);
   }
   xbt_free(requests);
 }
@@ -246,10 +245,10 @@ void smpi_mpi_scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
     // Recv buffer from root
     Request::recv(recvbuf, recvcount, recvtype, root, system_tag, comm, MPI_STATUS_IGNORE);
   } else {
-    smpi_datatype_extent(sendtype, &lb, &sendext);
+    sendtype->extent(&lb, &sendext);
     // Local copy from root
     if(recvbuf!=MPI_IN_PLACE){
-        smpi_datatype_copy(static_cast<char *>(sendbuf) + root * sendcount * sendext,
+        Datatype::copy(static_cast<char *>(sendbuf) + root * sendcount * sendext,
                            sendcount, sendtype, recvbuf, recvcount, recvtype);
     }
     // Send buffers to receivers
@@ -266,7 +265,7 @@ void smpi_mpi_scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
     Request::startall(size - 1, requests);
     Request::waitall(size - 1, requests, MPI_STATUS_IGNORE);
     for (int dst = 0; dst < size-1; dst++) {
-      Request::unuse(&requests[dst]);
+      Request::unref(&requests[dst]);
     }
     xbt_free(requests);
   }
@@ -285,10 +284,10 @@ void smpi_mpi_scatterv(void *sendbuf, int *sendcounts, int *displs, MPI_Datatype
     // Recv buffer from root
     Request::recv(recvbuf, recvcount, recvtype, root, system_tag, comm, MPI_STATUS_IGNORE);
   } else {
-    smpi_datatype_extent(sendtype, &lb, &sendext);
+    sendtype->extent(&lb, &sendext);
     // Local copy from root
     if(recvbuf!=MPI_IN_PLACE){
-      smpi_datatype_copy(static_cast<char *>(sendbuf) + displs[root] * sendext, sendcounts[root],
+      Datatype::copy(static_cast<char *>(sendbuf) + displs[root] * sendext, sendcounts[root],
                        sendtype, recvbuf, recvcount, recvtype);
     }
     // Send buffers to receivers
@@ -305,7 +304,7 @@ void smpi_mpi_scatterv(void *sendbuf, int *sendcounts, int *displs, MPI_Datatype
     Request::startall(size - 1, requests);
     Request::waitall(size - 1, requests, MPI_STATUS_IGNORE);
     for (int dst = 0; dst < size-1; dst++) {
-      Request::unuse(&requests[dst]);
+      Request::unref(&requests[dst]);
     }
     xbt_free(requests);
   }
@@ -323,24 +322,24 @@ void smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datat
   int rank = comm->rank();
   int size = comm->size();
   //non commutative case, use a working algo from openmpi
-  if(!smpi_op_is_commute(op)){
+  if(op != MPI_OP_NULL && !op->is_commutative()){
     smpi_coll_tuned_reduce_ompi_basic_linear(sendtmpbuf, recvbuf, count, datatype, op, root, comm);
     return;
   }
 
   if( sendbuf == MPI_IN_PLACE ) {
-    sendtmpbuf = static_cast<char *>(smpi_get_tmp_sendbuffer(count*smpi_datatype_get_extent(datatype)));
-    smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
+    sendtmpbuf = static_cast<char *>(smpi_get_tmp_sendbuffer(count*datatype->get_extent()));
+    Datatype::copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
   }
   
   if(rank != root) {
     // Send buffer to root
     Request::send(sendtmpbuf, count, datatype, root, system_tag, comm);
   } else {
-    smpi_datatype_extent(datatype, &lb, &dataext);
+    datatype->extent(&lb, &dataext);
     // Local copy from root
     if (sendtmpbuf != nullptr && recvbuf != nullptr)
-      smpi_datatype_copy(sendtmpbuf, count, datatype, recvbuf, count, datatype);
+      Datatype::copy(sendtmpbuf, count, datatype, recvbuf, count, datatype);
     // Receive buffers from senders
     MPI_Request *requests = xbt_new(MPI_Request, size - 1);
     void **tmpbufs = xbt_new(void *, size - 1);
@@ -364,10 +363,10 @@ void smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count, MPI_Datatype datat
       if(index == MPI_UNDEFINED) {
         break;
       }else{
-        Request::unuse(&requests[index]);
+        Request::unref(&requests[index]);
       }
-      if(op) /* op can be MPI_OP_NULL that does nothing */
-        smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype);
+      if (op != MPI_OP_NULL) /* op can be MPI_OP_NULL that does nothing */
+        op->apply(tmpbufs[index], recvbuf, &count, datatype);
     }
       for(index = 0; index < size - 1; index++) {
         smpi_free_tmp_buffer(tmpbufs[index]);
@@ -396,10 +395,10 @@ void smpi_mpi_scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatyp
   int rank = comm->rank();
   int size = comm->size();
 
-  smpi_datatype_extent(datatype, &lb, &dataext);
+  datatype->extent(&lb, &dataext);
 
   // Local copy from self
-  smpi_datatype_copy(sendbuf, count, datatype, recvbuf, count, datatype);
+  Datatype::copy(sendbuf, count, datatype, recvbuf, count, datatype);
 
   // Send/Recv buffers to/from others;
   MPI_Request *requests = xbt_new(MPI_Request, size - 1);
@@ -417,31 +416,29 @@ void smpi_mpi_scan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datatyp
   // Wait for completion of all comms.
   Request::startall(size - 1, requests);
 
-  if(smpi_op_is_commute(op)){
+  if(op != MPI_OP_NULL && op->is_commutative()){
     for (int other = 0; other < size - 1; other++) {
       index = Request::waitany(size - 1, requests, MPI_STATUS_IGNORE);
       if(index == MPI_UNDEFINED) {
         break;
       }
-      if(index < rank) {
-        // #Request is below rank: it's a irecv
-        smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype);
-      }
+      if (index < rank)
+        // #Request is below rank: it's a irecv.
+        op->apply(tmpbufs[index], recvbuf, &count, datatype);
     }
   }else{
     //non commutative case, wait in order
     for (int other = 0; other < size - 1; other++) {
       Request::wait(&(requests[other]), MPI_STATUS_IGNORE);
-      if(index < rank) {
-        smpi_op_apply(op, tmpbufs[other], recvbuf, &count, &datatype);
-      }
+      if (index < rank && op != MPI_OP_NULL)
+        op->apply(tmpbufs[other], recvbuf, &count, datatype);
     }
   }
   for(index = 0; index < rank; index++) {
     smpi_free_tmp_buffer(tmpbufs[index]);
   }
   for(index = 0; index < size-1; index++) {
-    Request::unuse(&requests[index]);
+    Request::unref(&requests[index]);
   }
   xbt_free(tmpbufs);
   xbt_free(requests);
@@ -456,7 +453,7 @@ void smpi_mpi_exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datat
   int rank = comm->rank();
   int size = comm->size();
 
-  smpi_datatype_extent(datatype, &lb, &dataext);
+  datatype->extent(&lb, &dataext);
 
   // Send/Recv buffers to/from others;
   MPI_Request *requests = xbt_new(MPI_Request, size - 1);
@@ -474,7 +471,7 @@ void smpi_mpi_exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datat
   // Wait for completion of all comms.
   Request::startall(size - 1, requests);
 
-  if(smpi_op_is_commute(op)){
+  if(op != MPI_OP_NULL && op->is_commutative()){
     for (int other = 0; other < size - 1; other++) {
       index = Request::waitany(size - 1, requests, MPI_STATUS_IGNORE);
       if(index == MPI_UNDEFINED) {
@@ -482,11 +479,11 @@ void smpi_mpi_exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datat
       }
       if(index < rank) {
         if(recvbuf_is_empty){
-          smpi_datatype_copy(tmpbufs[index], count, datatype, recvbuf, count, datatype);
+          Datatype::copy(tmpbufs[index], count, datatype, recvbuf, count, datatype);
           recvbuf_is_empty=0;
         } else
           // #Request is below rank: it's a irecv
-          smpi_op_apply(op, tmpbufs[index], recvbuf, &count, &datatype);
+          if(op!=MPI_OP_NULL) op->apply( tmpbufs[index], recvbuf, &count, datatype);
       }
     }
   }else{
@@ -495,10 +492,10 @@ void smpi_mpi_exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datat
      Request::wait(&(requests[other]), MPI_STATUS_IGNORE);
       if(index < rank) {
         if (recvbuf_is_empty) {
-          smpi_datatype_copy(tmpbufs[other], count, datatype, recvbuf, count, datatype);
+          Datatype::copy(tmpbufs[other], count, datatype, recvbuf, count, datatype);
           recvbuf_is_empty = 0;
         } else
-          smpi_op_apply(op, tmpbufs[other], recvbuf, &count, &datatype);
+          if(op!=MPI_OP_NULL) op->apply( tmpbufs[other], recvbuf, &count, datatype);
       }
     }
   }
@@ -506,7 +503,7 @@ void smpi_mpi_exscan(void *sendbuf, void *recvbuf, int count, MPI_Datatype datat
     smpi_free_tmp_buffer(tmpbufs[index]);
   }
   for(index = 0; index < size-1; index++) {
-    Request::unuse(&requests[index]);
+    Request::unref(&requests[index]);
   }
   xbt_free(tmpbufs);
   xbt_free(requests);
@@ -524,7 +521,7 @@ void smpi_empty_status(MPI_Status * status)
 
 int smpi_mpi_get_count(MPI_Status * status, MPI_Datatype datatype)
 {
-  return status->count / smpi_datatype_size(datatype);
+  return status->count / datatype->size();
 }