Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Save more std::string copies.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 23 Mar 2022 21:09:20 +0000 (22:09 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 24 Mar 2022 22:08:25 +0000 (23:08 +0100)
src/smpi/bindings/smpi_pmpi_coll.cpp
src/smpi/include/private.hpp
src/smpi/internals/smpi_utils.cpp

index 7df4731..5915270 100644 (file)
@@ -67,9 +67,8 @@ int PMPI_Ibcast(void* buf, int count, MPI_Datatype datatype, int root, MPI_Comm
   CHECK_BUFFER(1, buf, count, datatype)
   CHECK_ROOT(4)
   CHECK_REQUEST(6)
-  std::string name = (request == MPI_REQUEST_IGNORED ? "PMPI_Bcast" : "PMPI_Ibcast");
-  name += " with root " + std::to_string(root);
-  CHECK_COLLECTIVE(comm, name.c_str())
+  CHECK_COLLECTIVE(comm, std::string(request == MPI_REQUEST_IGNORED ? "PMPI_Bcast" : "PMPI_Ibcast") + " with root " +
+                             std::to_string(root))
 
   const SmpiBenchGuard suspend_bench;
   aid_t pid = simgrid::s4u::this_actor::get_pid();
@@ -118,9 +117,8 @@ int PMPI_Igather(const void* sendbuf, int sendcount, MPI_Datatype sendtype, void
   }
   CHECK_ROOT(7)
   CHECK_REQUEST(9)
-  std::string name = (request == MPI_REQUEST_IGNORED ? "PMPI_Gather" : "PMPI_Igather");
-  name += " with root " + std::to_string(root);
-  CHECK_COLLECTIVE(comm, name.c_str())
+  CHECK_COLLECTIVE(comm, std::string(request == MPI_REQUEST_IGNORED ? "PMPI_Gather" : "PMPI_Igather") + +" with root " +
+                             std::to_string(root))
 
   const void* real_sendbuf   = sendbuf;
   int real_sendcount         = sendcount;
@@ -181,9 +179,8 @@ int PMPI_Igatherv(const void* sendbuf, int sendcount, MPI_Datatype sendtype, voi
   }
   CHECK_ROOT(8)
   CHECK_REQUEST(10)
-  std::string name = (request == MPI_REQUEST_IGNORED ? "PMPI_Gatherv" : "PMPI_Igatherv");
-  name += " with root " + std::to_string(root);
-  CHECK_COLLECTIVE(comm, name.c_str())
+  CHECK_COLLECTIVE(comm, std::string(request == MPI_REQUEST_IGNORED ? "PMPI_Gatherv" : "PMPI_Igatherv") +
+                             " with root " + std::to_string(root))
 
   if (rank == root){
     for (int i = 0; i < comm->size(); i++) {
@@ -362,9 +359,8 @@ int PMPI_Iscatter(const void* sendbuf, int sendcount, MPI_Datatype sendtype, voi
   }
   CHECK_ROOT(8)
   CHECK_REQUEST(9)
-  std::string name = (request == MPI_REQUEST_IGNORED ? "PMPI_Scatter" : "PMPI_Iscatter");
-  name += " with root " + std::to_string(root);
-  CHECK_COLLECTIVE(comm, name.c_str())
+  CHECK_COLLECTIVE(comm, std::string(request == MPI_REQUEST_IGNORED ? "PMPI_Scatter" : "PMPI_Iscatter") +
+                             " with root " + std::to_string(root))
 
   if (recvbuf == MPI_IN_PLACE) {
     recvtype  = sendtype;
@@ -429,9 +425,8 @@ int PMPI_Iscatterv(const void* sendbuf, const int* sendcounts, const int* displs
   } else {
     CHECK_NOT_IN_PLACE_ROOT(4, recvbuf)
   }
-  std::string name = (request == MPI_REQUEST_IGNORED ? "PMPI_Scatterv" : "PMPI_Iscatterv");
-  name += " with root " + std::to_string(root);
-  CHECK_COLLECTIVE(comm, name.c_str())
+  CHECK_COLLECTIVE(comm, std::string(request == MPI_REQUEST_IGNORED ? "PMPI_Scatterv" : "PMPI_Iscatterv") +
+                             " with root " + std::to_string(root))
 
   const SmpiBenchGuard suspend_bench;
 
@@ -481,10 +476,8 @@ int PMPI_Ireduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype dat
   CHECK_OP(5, op, datatype)
   CHECK_ROOT(7)
   CHECK_REQUEST(8)
-  std::string name = (request == MPI_REQUEST_IGNORED ? "PMPI_Reduce" : "PMPI_Ireduce");
-  name += " with op " + op->name();
-  name += " and root " + std::to_string(root);
-  CHECK_COLLECTIVE(comm, name.c_str())
+  CHECK_COLLECTIVE(comm, std::string(request == MPI_REQUEST_IGNORED ? "PMPI_Reduce" : "PMPI_Ireduce") + " with op " +
+                             op->name() + " and root " + std::to_string(root))
 
   const SmpiBenchGuard suspend_bench;
   aid_t pid = simgrid::s4u::this_actor::get_pid();
@@ -535,9 +528,8 @@ int PMPI_Iallreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype
   CHECK_BUFFER(1, sendbuf, count, datatype)
   CHECK_BUFFER(2, recvbuf, count, datatype)
   CHECK_REQUEST(7)
-  std::string name = (request == MPI_REQUEST_IGNORED ? "PMPI_Alleduce" : "PMPI_Iallreduce");
-  name += " with op " + op->name();
-  CHECK_COLLECTIVE(comm, name.c_str())
+  CHECK_COLLECTIVE(comm, std::string(request == MPI_REQUEST_IGNORED ? "PMPI_Alleduce" : "PMPI_Iallreduce") +
+                             " with op " + op->name())
 
   const SmpiBenchGuard suspend_bench;
   std::vector<unsigned char> tmp_sendbuf;
@@ -575,9 +567,8 @@ int PMPI_Iscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datat
   CHECK_BUFFER(2,recvbuf,count, datatype)
   CHECK_REQUEST(7)
   CHECK_OP(5, op, datatype)
-  std::string name = (request == MPI_REQUEST_IGNORED ? "PMPI_Scan" : "PMPI_Iscan");
-  name += " with op " + op->name();
-  CHECK_COLLECTIVE(comm, name.c_str())
+  CHECK_COLLECTIVE(comm,
+                   std::string(request == MPI_REQUEST_IGNORED ? "PMPI_Scan" : "PMPI_Iscan") + " with op " + op->name())
 
   const SmpiBenchGuard suspend_bench;
   aid_t pid = simgrid::s4u::this_actor::get_pid();
@@ -613,9 +604,8 @@ int PMPI_Iexscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype dat
   CHECK_BUFFER(2, recvbuf, count, datatype)
   CHECK_REQUEST(7)
   CHECK_OP(5, op, datatype)
-  std::string name = (request == MPI_REQUEST_IGNORED ? "PMPI_Exscan" : "PMPI_Iexscan");
-  name += " with op " + op->name();
-  CHECK_COLLECTIVE(comm, name.c_str())
+  CHECK_COLLECTIVE(comm, std::string(request == MPI_REQUEST_IGNORED ? "PMPI_Exscan" : "PMPI_Iexscan") + " with op " +
+                             op->name())
 
   const SmpiBenchGuard suspend_bench;
   aid_t pid = simgrid::s4u::this_actor::get_pid();
@@ -657,9 +647,8 @@ int PMPI_Ireduce_scatter(const void *sendbuf, void *recvbuf, const int *recvcoun
     CHECK_BUFFER(1, sendbuf, recvcounts[i], datatype)
     CHECK_BUFFER(2, recvbuf, recvcounts[i], datatype)
   }
-  std::string name = (request == MPI_REQUEST_IGNORED ? "PMPI_Reduce_scatter" : "PMPI_Ireduce_scatter");
-  name += " with op " + op->name();
-  CHECK_COLLECTIVE(comm, name.c_str())
+  CHECK_COLLECTIVE(comm, std::string(request == MPI_REQUEST_IGNORED ? "PMPI_Reduce_scatter" : "PMPI_Ireduce_scatter") +
+                             " with op " + op->name())
 
   const SmpiBenchGuard suspend_bench;
   aid_t pid                          = simgrid::s4u::this_actor::get_pid();
@@ -706,9 +695,9 @@ int PMPI_Ireduce_scatter_block(const void* sendbuf, void* recvbuf, int recvcount
   CHECK_BUFFER(2, recvbuf, recvcount, datatype)
   CHECK_REQUEST(7)
   CHECK_OP(5, op, datatype)
-  std::string name = (request == MPI_REQUEST_IGNORED ? "PMPI_Reduce_scatter_block" : "PMPI_Ireduce_scatter_block");
-  name += " with op " + op->name();
-  CHECK_COLLECTIVE(comm, name.c_str())
+  CHECK_COLLECTIVE(
+      comm, std::string(request == MPI_REQUEST_IGNORED ? "PMPI_Reduce_scatter_block" : "PMPI_Ireduce_scatter_block") +
+                " with op " + op->name())
 
   const SmpiBenchGuard suspend_bench;
   int count = comm->size();
index 9b2a516..87cfe01 100644 (file)
@@ -582,9 +582,14 @@ XBT_PRIVATE void private_execute_flops(double flops);
 #define CHECK_COMM2(num, comm)\
   CHECK_MPI_NULL((num), MPI_COMM_NULL, MPI_ERR_COMM, (comm))
 
-#define CHECK_COLLECTIVE(comm, call)\
-  CHECK_ARGS((simgrid::smpi::utils::check_collectives_ordering((comm), std::string(call)) != MPI_SUCCESS), MPI_ERR_OTHER,\
-                   "%s: collective mismatch", call)
+#define CHECK_COLLECTIVE(comm, call)                                                                                   \
+  {                                                                                                                    \
+    if (_smpi_cfg_pedantic) {                                                                                          \
+      std::string call_string = (call);                                                                                \
+      CHECK_ARGS((simgrid::smpi::utils::check_collectives_ordering((comm), call_string) != MPI_SUCCESS),               \
+                 MPI_ERR_OTHER, "%s: collective mismatch", call_string.c_str())                                        \
+    }                                                                                                                  \
+  }
 
 #define CHECK_DELETED(num, err, obj)\
   CHECK_ARGS((obj)->deleted(), (err), "%s: param %d %s has already been freed", __func__, (num),\
index 04b6daa..77436cc 100644 (file)
@@ -350,24 +350,23 @@ void account_free(const void* ptr){
 
 int check_collectives_ordering(MPI_Comm comm, const std::string& call)
 {
-  if(_smpi_cfg_pedantic){
-    unsigned int count = comm->get_collectives_count();
-    comm->increment_collectives_count();
-    auto vec = collective_calls.find(comm->id());
-    if (vec == collective_calls.end()) {
-      collective_calls.emplace(comm->id(), std::vector<std::string>{call});
-    }else{
-      //are we the first ? add the call
-      if (vec->second.size() == count) {
-        vec->second.emplace_back(call);
-      } else if (vec->second.size() > count) {
-        if (vec->second[count] != call){
-          XBT_WARN("Collective operation mismatch. For process %ld, expected %s, got %s", simgrid::s4u::this_actor::get_pid(), vec->second[count].c_str(), call.c_str());
-          return MPI_ERR_OTHER;
-        }
-      } else {
-        THROW_IMPOSSIBLE;
+  unsigned int count = comm->get_collectives_count();
+  comm->increment_collectives_count();
+  auto vec = collective_calls.find(comm->id());
+  if (vec == collective_calls.end()) {
+    collective_calls.emplace(comm->id(), std::vector<std::string>{call});
+  } else {
+    // are we the first ? add the call
+    if (vec->second.size() == count) {
+      vec->second.emplace_back(call);
+    } else if (vec->second.size() > count) {
+      if (vec->second[count] != call) {
+        XBT_WARN("Collective operation mismatch. For process %ld, expected %s, got %s",
+                 simgrid::s4u::this_actor::get_pid(), vec->second[count].c_str(), call.c_str());
+        return MPI_ERR_OTHER;
       }
+    } else {
+      THROW_IMPOSSIBLE;
     }
   }
   return MPI_SUCCESS;