Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define class SmpiBenchGuard, and use RAII to handle smpi_bench_end()/smpi_bench_begin().
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 2 Jun 2021 08:15:28 +0000 (10:15 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 2 Jun 2021 09:37:14 +0000 (11:37 +0200)
src/smpi/bindings/smpi_pmpi.cpp
src/smpi/bindings/smpi_pmpi_coll.cpp
src/smpi/bindings/smpi_pmpi_comm.cpp
src/smpi/bindings/smpi_pmpi_file.cpp
src/smpi/bindings/smpi_pmpi_request.cpp
src/smpi/bindings/smpi_pmpi_win.cpp
src/smpi/include/private.hpp
src/smpi/internals/smpi_bench.cpp
src/smpi/plugins/ampi/ampi.cpp

index ffe62aa..400df13 100644 (file)
@@ -21,14 +21,13 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_pmpi, smpi, "Logging specific to SMPI (pmpi
 void TRACE_smpi_set_category(const char *category)
 {
   //need to end bench otherwise categories for execution tasks are wrong
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
+
   if (category != nullptr) {
     // declare category
     TRACE_category(category);
     smpi_process()->set_tracing_category(category);
   }
-  //begin bench after changing process's category
-  smpi_bench_begin();
 }
 
 /* PMPI User level calls */
index 85bdb60..534a94a 100644 (file)
@@ -38,7 +38,7 @@ int PMPI_Ibarrier(MPI_Comm comm, MPI_Request *request)
   CHECK_COMM(1)
   CHECK_REQUEST(2)
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t pid = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(pid, request == MPI_REQUEST_IGNORED ? "PMPI_Barrier" : "PMPI_Ibarrier",
                      new simgrid::instr::NoOpTIData(request == MPI_REQUEST_IGNORED ? "barrier" : "ibarrier"));
@@ -50,7 +50,6 @@ int PMPI_Ibarrier(MPI_Comm comm, MPI_Request *request)
     simgrid::smpi::colls::ibarrier(comm, request);
 
   TRACE_smpi_comm_out(pid);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -70,7 +69,7 @@ int PMPI_Ibcast(void *buf, int count, MPI_Datatype datatype,
   CHECK_ROOT(4)
   CHECK_REQUEST(6)
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t pid = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(pid, request == MPI_REQUEST_IGNORED ? "PMPI_Bcast" : "PMPI_Ibcast",
                      new simgrid::instr::CollTIData(request == MPI_REQUEST_IGNORED ? "bcast" : "ibcast", root, -1.0,
@@ -87,7 +86,6 @@ int PMPI_Ibcast(void *buf, int count, MPI_Datatype datatype,
   }
 
   TRACE_smpi_comm_out(pid);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -132,7 +130,7 @@ int PMPI_Igather(const void* sendbuf, int sendcount, MPI_Datatype sendtype, void
     }
   }
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
   aid_t pid = simgrid::s4u::this_actor::get_pid();
 
@@ -149,7 +147,6 @@ int PMPI_Igather(const void* sendbuf, int sendcount, MPI_Datatype sendtype, void
                                   request);
 
   TRACE_smpi_comm_out(pid);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -188,7 +185,7 @@ int PMPI_Igatherv(const void* sendbuf, int sendcount, MPI_Datatype sendtype, voi
     }
   }
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   const void* real_sendbuf   = sendbuf;
   int real_sendcount         = sendcount;
   MPI_Datatype real_sendtype = sendtype;
@@ -220,7 +217,6 @@ int PMPI_Igatherv(const void* sendbuf, int sendcount, MPI_Datatype sendtype, voi
                                    root, comm, request);
 
   TRACE_smpi_comm_out(pid);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -258,7 +254,7 @@ int PMPI_Iallgather(const void* sendbuf, int sendcount, MPI_Datatype sendtype, v
     return MPI_ERR_TRUNCATE;
   }
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
   aid_t pid = simgrid::s4u::this_actor::get_pid();
 
@@ -274,7 +270,6 @@ int PMPI_Iallgather(const void* sendbuf, int sendcount, MPI_Datatype sendtype, v
     simgrid::smpi::colls::iallgather(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm, request);
 
   TRACE_smpi_comm_out(pid);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -306,7 +301,7 @@ int PMPI_Iallgatherv(const void* sendbuf, int sendcount, MPI_Datatype sendtype,
     CHECK_BUFFER(4, recvbuf, recvcounts[i], recvtype)
   }
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   if (sendbuf == MPI_IN_PLACE) {
     sendbuf   = static_cast<char*>(recvbuf) + recvtype->get_extent() * displs[comm->rank()];
     sendcount = recvcounts[comm->rank()];
@@ -333,7 +328,6 @@ int PMPI_Iallgatherv(const void* sendbuf, int sendcount, MPI_Datatype sendtype,
                                       request);
 
   TRACE_smpi_comm_out(pid);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -375,7 +369,7 @@ int PMPI_Iscatter(const void* sendbuf, int sendcount, MPI_Datatype sendtype, voi
     return MPI_ERR_TRUNCATE;
   }
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
   aid_t pid = simgrid::s4u::this_actor::get_pid();
 
@@ -391,7 +385,6 @@ int PMPI_Iscatter(const void* sendbuf, int sendcount, MPI_Datatype sendtype, voi
     simgrid::smpi::colls::iscatter(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm, request);
 
   TRACE_smpi_comm_out(pid);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -431,7 +424,7 @@ int PMPI_Iscatterv(const void* sendbuf, const int* sendcounts, const int* displs
     CHECK_NOT_IN_PLACE_ROOT(4, recvbuf)
   }
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
   aid_t pid        = simgrid::s4u::this_actor::get_pid();
   int dt_size_send = sendtype->is_replayable() ? 1 : sendtype->size();
@@ -456,7 +449,6 @@ int PMPI_Iscatterv(const void* sendbuf, const int* sendcounts, const int* displs
                                     request);
 
   TRACE_smpi_comm_out(pid);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -482,7 +474,7 @@ int PMPI_Ireduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype dat
   CHECK_ROOT(7)
   CHECK_REQUEST(8)
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t pid = simgrid::s4u::this_actor::get_pid();
 
   TRACE_smpi_comm_in(pid, request == MPI_REQUEST_IGNORED ? "PMPI_Reduce" : "PMPI_Ireduce",
@@ -495,7 +487,6 @@ int PMPI_Ireduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype dat
     simgrid::smpi::colls::ireduce(sendbuf, recvbuf, count, datatype, op, root, comm, request);
 
   TRACE_smpi_comm_out(pid);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -509,9 +500,8 @@ int PMPI_Reduce_local(const void* inbuf, void* inoutbuf, int count, MPI_Datatype
   CHECK_BUFFER(2, inoutbuf, count, datatype)
   CHECK_OP(5, op, datatype)
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   op->apply(inbuf, inoutbuf, &count, datatype);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -534,7 +524,7 @@ int PMPI_Iallreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype
   CHECK_BUFFER(2, recvbuf, count, datatype)
   CHECK_REQUEST(7)
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   std::vector<unsigned char> tmp_sendbuf;
   const void* real_sendbuf = smpi_get_in_place_buf(sendbuf, recvbuf, tmp_sendbuf, count, datatype);
 
@@ -551,7 +541,6 @@ int PMPI_Iallreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype
     simgrid::smpi::colls::iallreduce(real_sendbuf, recvbuf, count, datatype, op, comm, request);
 
   TRACE_smpi_comm_out(pid);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -572,7 +561,7 @@ int PMPI_Iscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datat
   CHECK_REQUEST(7)
   CHECK_OP(5, op, datatype)
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t pid = simgrid::s4u::this_actor::get_pid();
   std::vector<unsigned char> tmp_sendbuf;
   const void* real_sendbuf = smpi_get_in_place_buf(sendbuf, recvbuf, tmp_sendbuf, count, datatype);
@@ -589,7 +578,6 @@ int PMPI_Iscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datat
     retval = simgrid::smpi::colls::iscan(real_sendbuf, recvbuf, count, datatype, op, comm, request);
 
   TRACE_smpi_comm_out(pid);
-  smpi_bench_begin();
   return retval;
 }
 
@@ -609,7 +597,7 @@ int PMPI_Iexscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype dat
   CHECK_REQUEST(7)
   CHECK_OP(5, op, datatype)
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t pid = simgrid::s4u::this_actor::get_pid();
   std::vector<unsigned char> tmp_sendbuf;
   const void* real_sendbuf = smpi_get_in_place_buf(sendbuf, recvbuf, tmp_sendbuf, count, datatype);
@@ -626,7 +614,6 @@ int PMPI_Iexscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype dat
     retval = simgrid::smpi::colls::iexscan(real_sendbuf, recvbuf, count, datatype, op, comm, request);
 
   TRACE_smpi_comm_out(pid);
-  smpi_bench_begin();
   return retval;
 }
 
@@ -652,7 +639,7 @@ int PMPI_Ireduce_scatter(const void *sendbuf, void *recvbuf, const int *recvcoun
     CHECK_BUFFER(2, recvbuf, recvcounts[i], datatype)
   }
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t pid                          = simgrid::s4u::this_actor::get_pid();
   auto trace_recvcounts              = std::make_shared<std::vector<int>>();
   int dt_send_size                   = datatype->is_replayable() ? 1 : datatype->size();
@@ -676,7 +663,6 @@ int PMPI_Ireduce_scatter(const void *sendbuf, void *recvbuf, const int *recvcoun
     simgrid::smpi::colls::ireduce_scatter(real_sendbuf, recvbuf, recvcounts, datatype, op, comm, request);
 
   TRACE_smpi_comm_out(pid);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -699,7 +685,7 @@ int PMPI_Ireduce_scatter_block(const void* sendbuf, void* recvbuf, int recvcount
   CHECK_REQUEST(7)
   CHECK_OP(5, op, datatype)
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   int count = comm->size();
 
   aid_t pid                          = simgrid::s4u::this_actor::get_pid();
@@ -722,7 +708,6 @@ int PMPI_Ireduce_scatter_block(const void* sendbuf, void* recvbuf, int recvcount
     simgrid::smpi::colls::ireduce_scatter(real_sendbuf, recvbuf, recvcounts.data(), datatype, op, comm, request);
 
   TRACE_smpi_comm_out(pid);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -765,7 +750,7 @@ int PMPI_Ialltoall(const void* sendbuf, int sendcount, MPI_Datatype sendtype, vo
     return MPI_ERR_TRUNCATE;
   }
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
   TRACE_smpi_comm_in(pid, request == MPI_REQUEST_IGNORED ? "PMPI_Alltoall" : "PMPI_Ialltoall",
                      new simgrid::instr::CollTIData(
@@ -782,7 +767,6 @@ int PMPI_Ialltoall(const void* sendbuf, int sendcount, MPI_Datatype sendtype, vo
                                              comm, request);
 
   TRACE_smpi_comm_out(pid);
-  smpi_bench_begin();
   return retval;
 }
 
@@ -819,7 +803,7 @@ int PMPI_Ialltoallv(const void* sendbuf, const int* sendcounts, const int* sendd
     CHECK_COUNT(6, recvcounts[i])
   }
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   int send_size                      = 0;
   int recv_size                      = 0;
   auto trace_sendcounts              = std::make_shared<std::vector<int>>();
@@ -851,7 +835,6 @@ int PMPI_Ialltoallv(const void* sendbuf, const int* sendcounts, const int* sendd
 
   if(recvtype->size() * recvcounts[comm->rank()] !=  real_sendtype->size() * real_sendcounts[comm->rank()]){
     XBT_WARN("MPI_(I)Alltoallv : receive size from me differs from sent size to me : %zu vs %zu", recvtype->size() * recvcounts[comm->rank()], real_sendtype->size() * real_sendcounts[comm->rank()]);
-    smpi_bench_begin();
     return MPI_ERR_TRUNCATE;
   }
 
@@ -877,7 +860,6 @@ int PMPI_Ialltoallv(const void* sendbuf, const int* sendcounts, const int* sendd
                                               recvcounts, recvdispls, recvtype, comm, request);
 
   TRACE_smpi_comm_out(pid);
-  smpi_bench_begin();
   return retval;
 }
 
@@ -915,7 +897,7 @@ int PMPI_Ialltoallw(const void* sendbuf, const int* sendcounts, const int* sendd
     CHECK_BUFFER(5, recvbuf, recvcounts[i], recvtypes[i])
   }
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
   int send_size                      = 0;
   int recv_size                      = 0;
@@ -927,10 +909,8 @@ int PMPI_Ialltoallw(const void* sendbuf, const int* sendcounts, const int* sendd
   const MPI_Datatype* real_sendtypes = sendtypes;
   unsigned long maxsize      = 0;
   for (int i = 0; i < size; i++) { // copy data to avoid bad free
-    if (recvtypes[i] == MPI_DATATYPE_NULL) {
-      smpi_bench_begin();
+    if (recvtypes[i] == MPI_DATATYPE_NULL)
       return MPI_ERR_TYPE;
-    }
     recv_size += recvcounts[i] * recvtypes[i]->size();
     trace_recvcounts->push_back(recvcounts[i] * recvtypes[i]->size());
     if ((recvdispls[i] + (recvcounts[i] * recvtypes[i]->size())) > maxsize)
@@ -954,7 +934,6 @@ int PMPI_Ialltoallw(const void* sendbuf, const int* sendcounts, const int* sendd
 
   if(recvtypes[comm->rank()]->size() * recvcounts[comm->rank()] !=  real_sendtypes[comm->rank()]->size() * real_sendcounts[comm->rank()]){
     XBT_WARN("MPI_(I)Alltoallw : receive size from me differs from sent size to me : %zu vs %zu", recvtypes[comm->rank()]->size() * recvcounts[comm->rank()],  real_sendtypes[comm->rank()]->size() * real_sendcounts[comm->rank()]);
-    smpi_bench_begin();
     return MPI_ERR_TRUNCATE;
   }
 
@@ -978,6 +957,5 @@ int PMPI_Ialltoallw(const void* sendbuf, const int* sendcounts, const int* sendd
                                               recvcounts, recvdispls, recvtypes, comm, request);
 
   TRACE_smpi_comm_out(pid);
-  smpi_bench_begin();
   return retval;
 }
index e000ee2..85309dd 100644 (file)
@@ -130,9 +130,8 @@ int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out)
   CHECK_COMM2(1, comm)
   if( color != MPI_UNDEFINED)//we use a negative value for MPI_UNDEFINED
     CHECK_NEGATIVE(3, MPI_ERR_ARG, color)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   *comm_out = comm->split(color, key);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -140,9 +139,8 @@ int PMPI_Comm_split_type(MPI_Comm comm, int split_type, int key, MPI_Info info,
 {
   CHECK_COMM(1)
   CHECK_NULL(5, MPI_ERR_ARG, newcomm)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   *newcomm = comm->split_type(split_type, key, info);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -151,9 +149,8 @@ int PMPI_Comm_create_group(MPI_Comm comm, MPI_Group group, int, MPI_Comm* comm_o
   CHECK_COMM(1)
   CHECK_GROUP(2, group)
   CHECK_NULL(5, MPI_ERR_ARG, comm_out)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   int retval = MPI_Comm_create(comm, group, comm_out);
-  smpi_bench_begin();
   return retval;
 }
 
index d4be5c6..38f6768 100644 (file)
@@ -41,9 +41,8 @@ int PMPI_File_open(MPI_Comm comm, const char *filename, int amode, MPI_Info info
   CHECK_NULL(2, MPI_ERR_FILE, filename)
   if (amode < 0)
     return MPI_ERR_AMODE;
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   *fh =  new simgrid::smpi::File(comm, filename, amode, info);
-  smpi_bench_begin();
   if ((*fh)->size() != 0 && (amode & MPI_MODE_EXCL)){
     delete fh;
     return MPI_ERR_AMODE;
@@ -55,44 +54,39 @@ int PMPI_File_open(MPI_Comm comm, const char *filename, int amode, MPI_Info info
 
 int PMPI_File_close(MPI_File *fh){
   CHECK_NULL(2, MPI_ERR_ARG, fh)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   int ret = simgrid::smpi::File::close(fh);
   *fh = MPI_FILE_NULL;
-  smpi_bench_begin();
   return ret;
 }
 
 int PMPI_File_seek(MPI_File fh, MPI_Offset offset, int whence){
   CHECK_FILE(1, fh)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   int ret = fh->seek(offset,whence);
-  smpi_bench_begin();
   return ret;
 }
 
 int PMPI_File_seek_shared(MPI_File fh, MPI_Offset offset, int whence){
   CHECK_FILE(1, fh)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   int ret = fh->seek_shared(offset,whence);
-  smpi_bench_begin();
   return ret;
 }
 
 int PMPI_File_get_position(MPI_File fh, MPI_Offset* offset){
   CHECK_FILE(1, fh)
   CHECK_NULL(2, MPI_ERR_DISP, offset)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   int ret = fh->get_position(offset);
-  smpi_bench_begin();
   return ret;
 }
 
 int PMPI_File_get_position_shared(MPI_File fh, MPI_Offset* offset){
   CHECK_FILE(1, fh)
   CHECK_NULL(2, MPI_ERR_DISP, offset)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   int ret = fh->get_position_shared(offset);
-  smpi_bench_begin();
   return ret;
 }
 
@@ -100,12 +94,11 @@ int PMPI_File_read(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_
   CHECK_FILE_INPUTS
   CHECK_WRONLY(fh)
   PASS_ZEROCOUNT(count)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read", count * datatype->size()));
   int ret = simgrid::smpi::File::read(fh, buf, count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
-  smpi_bench_begin();
   return ret;
 }
 
@@ -113,13 +106,12 @@ int PMPI_File_read_shared(MPI_File fh, void *buf, int count,MPI_Datatype datatyp
   CHECK_FILE_INPUTS
   CHECK_WRONLY(fh)
   PASS_ZEROCOUNT(count)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__,
                      new simgrid::instr::CpuTIData("IO - read_shared", count * datatype->size()));
   int ret = simgrid::smpi::File::read_shared(fh, buf, count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
-  smpi_bench_begin();
   return ret;
 }
 
@@ -127,12 +119,11 @@ int PMPI_File_write(MPI_File fh, const void *buf, int count,MPI_Datatype datatyp
   CHECK_FILE_INPUTS
   CHECK_RDONLY(fh)
   PASS_ZEROCOUNT(count)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write", count * datatype->size()));
   int ret = simgrid::smpi::File::write(fh, const_cast<void*>(buf), count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
-  smpi_bench_begin();
   return ret;
 }
 
@@ -140,63 +131,58 @@ int PMPI_File_write_shared(MPI_File fh, const void *buf, int count,MPI_Datatype
   CHECK_FILE_INPUTS
   CHECK_RDONLY(fh)
   PASS_ZEROCOUNT(count)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__,
                      new simgrid::instr::CpuTIData("IO - write_shared", count * datatype->size()));
   int ret = simgrid::smpi::File::write_shared(fh, buf, count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
-  smpi_bench_begin();
   return ret;
 }
 
 int PMPI_File_read_all(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE_INPUTS
   CHECK_WRONLY(fh)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read_all", count * datatype->size()));
   int ret = fh->op_all<simgrid::smpi::File::read>(buf, count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
-  smpi_bench_begin();
   return ret;
 }
 
 int PMPI_File_read_ordered(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE_INPUTS
   CHECK_WRONLY(fh)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__,
                      new simgrid::instr::CpuTIData("IO - read_ordered", count * datatype->size()));
   int ret = simgrid::smpi::File::read_ordered(fh, buf, count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
-  smpi_bench_begin();
   return ret;
 }
 
 int PMPI_File_write_all(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE_INPUTS
   CHECK_RDONLY(fh)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write_all", count * datatype->size()));
   int ret = fh->op_all<simgrid::smpi::File::write>(const_cast<void*>(buf), count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
-  smpi_bench_begin();
   return ret;
 }
 
 int PMPI_File_write_ordered(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE_INPUTS
   CHECK_RDONLY(fh)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__,
                      new simgrid::instr::CpuTIData("IO - write_ordered", count * datatype->size()));
   int ret = simgrid::smpi::File::write_ordered(fh, buf, count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
-  smpi_bench_begin();
   return ret;
 }
 
@@ -204,21 +190,20 @@ int PMPI_File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_D
   CHECK_FILE_INPUTS
   CHECK_WRONLY(fh)
   PASS_ZEROCOUNT(count)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - read", count * datatype->size()));
   int ret = fh->seek(offset,MPI_SEEK_SET);
   if (ret == MPI_SUCCESS)
     ret = simgrid::smpi::File::read(fh, buf, count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
-  smpi_bench_begin();
   return ret;
 }
 
 int PMPI_File_read_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE_INPUT_OFFSET
   CHECK_WRONLY(fh)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__,
                      new simgrid::instr::CpuTIData("IO - read_at_all", count * datatype->size()));
@@ -226,7 +211,6 @@ int PMPI_File_read_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count,M
   if (ret == MPI_SUCCESS)
     ret = fh->op_all<simgrid::smpi::File::read>(buf, count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
-  smpi_bench_begin();
   return ret;
 }
 
@@ -234,21 +218,20 @@ int PMPI_File_write_at(MPI_File fh, MPI_Offset offset, const void *buf, int coun
   CHECK_FILE_INPUT_OFFSET
   CHECK_RDONLY(fh)
   PASS_ZEROCOUNT(count)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__, new simgrid::instr::CpuTIData("IO - write", count * datatype->size()));
   int ret = fh->seek(offset,MPI_SEEK_SET);
   if (ret == MPI_SUCCESS)
     ret = simgrid::smpi::File::write(fh, const_cast<void*>(buf), count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
-  smpi_bench_begin();
   return ret;
 }
 
 int PMPI_File_write_at_all(MPI_File fh, MPI_Offset offset, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){
   CHECK_FILE_INPUT_OFFSET
   CHECK_RDONLY(fh)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t rank_traced = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(rank_traced, __func__,
                      new simgrid::instr::CpuTIData("IO - write_at_all", count * datatype->size()));
@@ -256,16 +239,14 @@ int PMPI_File_write_at_all(MPI_File fh, MPI_Offset offset, const void *buf, int
   if (ret == MPI_SUCCESS)
     ret = fh->op_all<simgrid::smpi::File::write>(const_cast<void*>(buf), count, datatype, status);
   TRACE_smpi_comm_out(rank_traced);
-  smpi_bench_begin();
   return ret;
 }
 
 int PMPI_File_delete(const char *filename, MPI_Info info){
   if (filename == nullptr)
     return MPI_ERR_FILE;
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   int ret = simgrid::smpi::File::del(filename, info);
-  smpi_bench_begin();
   return ret;
 }
 
@@ -275,9 +256,8 @@ int PMPI_File_set_view(MPI_File fh, MPI_Offset disp, MPI_Datatype etype, MPI_Dat
     CHECK_OFFSET(2, disp)
   CHECK_TYPE(3, etype)
   CHECK_TYPE(4, filetype)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   int ret = fh->set_view(disp, etype, filetype, datarep, info);
-  smpi_bench_begin();
   return ret;
 }
 
@@ -286,9 +266,8 @@ int PMPI_File_get_view(MPI_File fh, MPI_Offset *disp, MPI_Datatype *etype, MPI_D
   CHECK_NULL(2, MPI_ERR_ARG, disp)
   CHECK_NULL(3, MPI_ERR_ARG, etype)
   CHECK_NULL(4, MPI_ERR_ARG, filetype)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   int ret = fh->get_view(disp, etype, filetype, datarep);
-  smpi_bench_begin();
   return ret;
 }
 
index 44c748a..145187c 100644 (file)
@@ -48,9 +48,8 @@ int PMPI_Send_init(const void *buf, int count, MPI_Datatype datatype, int dst, i
 {
   CHECK_ISEND_INPUTS
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   *request = simgrid::smpi::Request::send_init(buf, count, datatype, dst, tag, comm);
-  smpi_bench_begin();
 
   return MPI_SUCCESS;
 }
@@ -59,9 +58,8 @@ int PMPI_Recv_init(void *buf, int count, MPI_Datatype datatype, int src, int tag
 {
   CHECK_IRECV_INPUTS
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   *request = simgrid::smpi::Request::recv_init(buf, count, datatype, src, tag, comm);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -76,11 +74,10 @@ int PMPI_Ssend_init(const void* buf, int count, MPI_Datatype datatype, int dst,
   CHECK_ISEND_INPUTS
 
   int retval = 0;
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   *request = simgrid::smpi::Request::ssend_init(buf, count, datatype, dst, tag, comm);
   retval = MPI_SUCCESS;
 
-  smpi_bench_begin();
   return retval;
 }
 
@@ -93,7 +90,7 @@ int PMPI_Start(MPI_Request * request)
 {
   int retval = 0;
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   CHECK_REQUEST_VALID(1)
   if ( *request == MPI_REQUEST_NULL) {
     retval = MPI_ERR_REQUEST;
@@ -115,14 +112,13 @@ int PMPI_Start(MPI_Request * request)
     retval = MPI_SUCCESS;
     TRACE_smpi_comm_out(my_proc_id);
   }
-  smpi_bench_begin();
   return retval;
 }
 
 int PMPI_Startall(int count, MPI_Request * requests)
 {
   int retval;
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   if (requests == nullptr) {
     retval = MPI_ERR_ARG;
   } else {
@@ -153,7 +149,6 @@ int PMPI_Startall(int count, MPI_Request * requests)
       TRACE_smpi_comm_out(my_proc_id);
     }
   }
-  smpi_bench_begin();
   return retval;
 }
 
@@ -161,14 +156,13 @@ int PMPI_Request_free(MPI_Request * request)
 {
   int retval = 0;
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   if (*request != MPI_REQUEST_NULL) {
     (*request)->mark_as_deleted();
     simgrid::smpi::Request::unref(request);
     *request = MPI_REQUEST_NULL;
     retval = MPI_SUCCESS;
   }
-  smpi_bench_begin();
   return retval;
 }
 
@@ -176,7 +170,7 @@ int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MP
 {
   CHECK_IRECV_INPUTS
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(my_proc_id, __func__,
                      new simgrid::instr::Pt2PtTIData("irecv", src,
@@ -184,7 +178,6 @@ int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MP
                                                      tag, simgrid::smpi::Datatype::encode(datatype)));
   *request = simgrid::smpi::Request::irecv(buf, count, datatype, src, tag, comm);
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -193,7 +186,7 @@ int PMPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dst, int t
 {
   CHECK_ISEND_INPUTS
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   int retval = 0;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   aid_t trace_dst  = getPid(comm, dst);
@@ -205,7 +198,6 @@ int PMPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dst, int t
   *request = simgrid::smpi::Request::isend(buf, count, datatype, dst, tag, comm);
   retval = MPI_SUCCESS;
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
 
   return retval;
 }
@@ -220,7 +212,7 @@ int PMPI_Issend(const void* buf, int count, MPI_Datatype datatype, int dst, int
 {
   CHECK_ISEND_INPUTS
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   aid_t trace_dst  = getPid(comm, dst);
   TRACE_smpi_comm_in(my_proc_id, __func__,
@@ -230,7 +222,6 @@ int PMPI_Issend(const void* buf, int count, MPI_Datatype datatype, int dst, int
   TRACE_smpi_send(my_proc_id, my_proc_id, trace_dst, tag, count * datatype->size());
   *request = simgrid::smpi::Request::issend(buf, count, datatype, dst, tag, comm);
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -244,7 +235,7 @@ int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI
   CHECK_TAG(5, tag)
   CHECK_COMM(6)
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   if (src == MPI_PROC_NULL) {
     if(status != MPI_STATUS_IGNORE){
       simgrid::smpi::Status::empty(status);
@@ -271,7 +262,6 @@ int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI
     TRACE_smpi_comm_out(my_proc_id);
   }
 
-  smpi_bench_begin();
   return retval;
 }
 
@@ -279,7 +269,7 @@ int PMPI_Send(const void *buf, int count, MPI_Datatype datatype, int dst, int ta
 {
   CHECK_SEND_INPUTS
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   aid_t dst_traced = getPid(comm, dst);
   TRACE_smpi_comm_in(my_proc_id, __func__,
@@ -291,7 +281,6 @@ int PMPI_Send(const void *buf, int count, MPI_Datatype datatype, int dst, int ta
   }
   simgrid::smpi::Request::send(buf, count, datatype, dst, tag, comm);
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -304,17 +293,15 @@ int PMPI_Bsend(const void* buf, int count, MPI_Datatype datatype, int dst, int t
 {
   CHECK_SEND_INPUTS
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id   = simgrid::s4u::this_actor::get_pid();
   aid_t dst_traced   = getPid(comm, dst);
   int bsend_buf_size = 0;
   void* bsend_buf = nullptr;
   smpi_process()->bsend_buffer(&bsend_buf, &bsend_buf_size);
   int size = datatype->get_extent() * count;
-  if (bsend_buf == nullptr || bsend_buf_size < size + MPI_BSEND_OVERHEAD) {
-    smpi_bench_begin();
+  if (bsend_buf == nullptr || bsend_buf_size < size + MPI_BSEND_OVERHEAD)
     return MPI_ERR_BUFFER;
-  }
   TRACE_smpi_comm_in(my_proc_id, __func__,
                      new simgrid::instr::Pt2PtTIData("bsend", dst,
                                                      datatype->is_replayable() ? count : count * datatype->size(),
@@ -324,7 +311,6 @@ int PMPI_Bsend(const void* buf, int count, MPI_Datatype datatype, int dst, int t
   }
   simgrid::smpi::Request::bsend(buf, count, datatype, dst, tag, comm);
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -332,17 +318,15 @@ int PMPI_Ibsend(const void* buf, int count, MPI_Datatype datatype, int dst, int
 {
   CHECK_ISEND_INPUTS
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id   = simgrid::s4u::this_actor::get_pid();
   aid_t trace_dst    = getPid(comm, dst);
   int bsend_buf_size = 0;
   void* bsend_buf = nullptr;
   smpi_process()->bsend_buffer(&bsend_buf, &bsend_buf_size);
   int size = datatype->get_extent() * count;
-  if (bsend_buf == nullptr || bsend_buf_size < size + MPI_BSEND_OVERHEAD) {
-    smpi_bench_begin();
+  if (bsend_buf == nullptr || bsend_buf_size < size + MPI_BSEND_OVERHEAD)
     return MPI_ERR_BUFFER;
-  }
   TRACE_smpi_comm_in(my_proc_id, __func__,
                      new simgrid::instr::Pt2PtTIData("ibsend", dst,
                                                      datatype->is_replayable() ? count : count * datatype->size(),
@@ -350,7 +334,6 @@ int PMPI_Ibsend(const void* buf, int count, MPI_Datatype datatype, int dst, int
   TRACE_smpi_send(my_proc_id, my_proc_id, trace_dst, tag, count * datatype->size());
   *request = simgrid::smpi::Request::ibsend(buf, count, datatype, dst, tag, comm);
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -358,7 +341,7 @@ int PMPI_Bsend_init(const void* buf, int count, MPI_Datatype datatype, int dst,
 {
   CHECK_ISEND_INPUTS
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   int retval = 0;
   int bsend_buf_size = 0;
   void* bsend_buf = nullptr;
@@ -369,7 +352,6 @@ int PMPI_Bsend_init(const void* buf, int count, MPI_Datatype datatype, int dst,
     *request = simgrid::smpi::Request::bsend_init(buf, count, datatype, dst, tag, comm);
     retval   = MPI_SUCCESS;
   }
-  smpi_bench_begin();
   return retval;
 }
 
@@ -377,7 +359,7 @@ int PMPI_Ssend(const void* buf, int count, MPI_Datatype datatype, int dst, int t
 {
   CHECK_SEND_INPUTS
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   aid_t dst_traced = getPid(comm, dst);
   TRACE_smpi_comm_in(my_proc_id, __func__,
@@ -387,7 +369,6 @@ int PMPI_Ssend(const void* buf, int count, MPI_Datatype datatype, int dst, int t
   TRACE_smpi_send(my_proc_id, my_proc_id, dst_traced, tag, count * datatype->size());
   simgrid::smpi::Request::ssend(buf, count, datatype, dst, tag, comm);
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -406,7 +387,7 @@ int PMPI_Sendrecv(const void* sendbuf, int sendcount, MPI_Datatype sendtype, int
   CHECK_BUFFER(6, recvbuf, recvcount, recvtype)
   CHECK_TAG(10, recvtag)
   CHECK_COMM(11)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
   if (src == MPI_PROC_NULL) {
     if(status!=MPI_STATUS_IGNORE){
@@ -447,7 +428,6 @@ int PMPI_Sendrecv(const void* sendbuf, int sendcount, MPI_Datatype sendtype, int
     TRACE_smpi_comm_out(my_proc_id);
   }
 
-  smpi_bench_begin();
   return retval;
 }
 
@@ -474,7 +454,7 @@ int PMPI_Sendrecv_replace(void* buf, int count, MPI_Datatype datatype, int dst,
 int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
 {
   int retval = 0;
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   if (request == nullptr || flag == nullptr) {
     retval = MPI_ERR_ARG;
   } else if (*request == MPI_REQUEST_NULL) {
@@ -491,7 +471,6 @@ int PMPI_Test(MPI_Request * request, int *flag, MPI_Status * status)
 
     TRACE_smpi_comm_out(my_proc_id);
   }
-  smpi_bench_begin();
   return retval;
 }
 
@@ -499,7 +478,7 @@ int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag, MPI_S
 {
   int retval = 0;
   CHECK_COUNT(1, count)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   if (index == nullptr || flag == nullptr) {
     retval = MPI_ERR_ARG;
   } else {
@@ -508,7 +487,6 @@ int PMPI_Testany(int count, MPI_Request requests[], int *index, int *flag, MPI_S
     retval = simgrid::smpi::Request::testany(count, requests, index, flag, status);
     TRACE_smpi_comm_out(my_proc_id);
   }
-  smpi_bench_begin();
   return retval;
 }
 
@@ -516,7 +494,7 @@ int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* status
 {
   int retval = 0;
   CHECK_COUNT(1, count)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   if (flag == nullptr) {
     retval = MPI_ERR_ARG;
   } else {
@@ -525,7 +503,6 @@ int PMPI_Testall(int count, MPI_Request* requests, int* flag, MPI_Status* status
     retval = simgrid::smpi::Request::testall(count, requests, flag, statuses);
     TRACE_smpi_comm_out(my_proc_id);
   }
-  smpi_bench_begin();
   return retval;
 }
 
@@ -533,7 +510,7 @@ int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount, int* indic
 {
   int retval = 0;
   CHECK_COUNT(1, incount)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   if (outcount == nullptr) {
     retval = MPI_ERR_ARG;
   } else {
@@ -542,13 +519,12 @@ int PMPI_Testsome(int incount, MPI_Request requests[], int* outcount, int* indic
     retval = simgrid::smpi::Request::testsome(incount, requests, outcount, indices, status);
     TRACE_smpi_comm_out(my_proc_id);
   }
-  smpi_bench_begin();
   return retval;
 }
 
 int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
   int retval = 0;
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
   CHECK_COMM(6)
   if(source!=MPI_ANY_SOURCE && source!=MPI_PROC_NULL)\
@@ -564,13 +540,12 @@ int PMPI_Probe(int source, int tag, MPI_Comm comm, MPI_Status* status) {
     simgrid::smpi::Request::probe(source, tag, comm, status);
     retval = MPI_SUCCESS;
   }
-  smpi_bench_begin();
   return retval;
 }
 
 int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* status) {
   int retval = 0;
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   CHECK_COMM(6)
   if(source!=MPI_ANY_SOURCE && source!=MPI_PROC_NULL)\
     CHECK_RANK(1, source, comm)
@@ -588,7 +563,6 @@ int PMPI_Iprobe(int source, int tag, MPI_Comm comm, int* flag, MPI_Status* statu
     simgrid::smpi::Request::iprobe(source, tag, comm, flag, status);
     retval = MPI_SUCCESS;
   }
-  smpi_bench_begin();
   return retval;
 }
 
@@ -611,7 +585,7 @@ int PMPI_Wait(MPI_Request * request, MPI_Status * status)
 {
   int retval = 0;
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
   simgrid::smpi::Status::empty(status);
 
@@ -639,7 +613,6 @@ int PMPI_Wait(MPI_Request * request, MPI_Status * status)
       simgrid::smpi::Request::unref(&savedreq);
   }
 
-  smpi_bench_begin();
   return retval;
 }
 
@@ -651,7 +624,7 @@ int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * sta
   if (count <= 0)
     return MPI_SUCCESS;
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   // for tracing, save the handles which might get overridden before we can use the helper on it
   std::vector<MPI_Request> savedreqs(requests, requests + count);
   for (MPI_Request& req : savedreqs) {
@@ -675,13 +648,12 @@ int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * sta
     if (req != MPI_REQUEST_NULL)
       simgrid::smpi::Request::unref(&req);
 
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
 int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
 {
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   CHECK_COUNT(1, count)
   // for tracing, save the handles which might get overridden before we can use the helper on it
   std::vector<MPI_Request> savedreqs(requests, requests + count);
@@ -706,7 +678,6 @@ int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
     if (req != MPI_REQUEST_NULL)
       simgrid::smpi::Request::unref(&req);
 
-  smpi_bench_begin();
   return retval;
 }
 
@@ -714,14 +685,13 @@ int PMPI_Waitsome(int incount, MPI_Request requests[], int *outcount, int *indic
 {
   int retval = 0;
   CHECK_COUNT(1, incount)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   if (outcount == nullptr) {
     retval = MPI_ERR_ARG;
   } else {
     *outcount = simgrid::smpi::Request::waitsome(incount, requests, indices, status);
     retval = MPI_SUCCESS;
   }
-  smpi_bench_begin();
   return retval;
 }
 
@@ -729,7 +699,7 @@ int PMPI_Cancel(MPI_Request* request)
 {
   int retval = 0;
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   CHECK_REQUEST_VALID(1)
   if (*request == MPI_REQUEST_NULL) {
     retval = MPI_ERR_REQUEST;
@@ -737,7 +707,6 @@ int PMPI_Cancel(MPI_Request* request)
     (*request)->cancel();
     retval = MPI_SUCCESS;
   }
-  smpi_bench_begin();
   return retval;
 }
 
index f3ff649..16561b1 100644 (file)
@@ -32,14 +32,13 @@ int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MP
   CHECK_COMM(5)
   CHECK_NEGATIVE(2, MPI_ERR_OTHER, size)
   CHECK_NEGATIVE(3, MPI_ERR_OTHER, disp_unit)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   if (base == nullptr && size != 0){
     retval= MPI_ERR_OTHER;
   }else{
     *win = new simgrid::smpi::Win( base, size, disp_unit, info, comm);
     retval = MPI_SUCCESS;
   }
-  smpi_bench_begin();
   return retval;
 }
 
@@ -48,10 +47,9 @@ int PMPI_Win_allocate( MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm com
   CHECK_NEGATIVE(2, MPI_ERR_OTHER, size)
   CHECK_NEGATIVE(3, MPI_ERR_OTHER, disp_unit)
   void* ptr = xbt_malloc(size);
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   *static_cast<void**>(base) = ptr;
   *win = new simgrid::smpi::Win( ptr, size, disp_unit, info, comm,1);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -64,20 +62,18 @@ int PMPI_Win_allocate_shared( MPI_Aint size, int disp_unit, MPI_Info info, MPI_C
   if(rank==0){
      ptr = xbt_malloc(size*comm->size());
   }
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   simgrid::smpi::colls::bcast(&ptr, sizeof(void*), MPI_BYTE, 0, comm);
   simgrid::smpi::colls::barrier(comm);
   *static_cast<void**>(base) = (char*)ptr+rank*size;
   *win = new simgrid::smpi::Win( ptr, size, disp_unit, info, comm,rank==0);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
 int PMPI_Win_create_dynamic( MPI_Info info, MPI_Comm comm, MPI_Win *win){
   CHECK_COMM(2)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   *win = new simgrid::smpi::Win(info, comm);
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -86,9 +82,8 @@ int PMPI_Win_attach(MPI_Win win, void *base, MPI_Aint size){
   CHECK_NEGATIVE(3, MPI_ERR_OTHER, size)
   if (base == nullptr && size != 0)
     return MPI_ERR_OTHER;
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   int retval = win->attach(base, size);
-  smpi_bench_begin();
   return retval;
 }
 
@@ -96,18 +91,16 @@ int PMPI_Win_detach(MPI_Win win, const void* base)
 {
   CHECK_WIN(1, win)
   CHECK_NULL(2, MPI_ERR_OTHER, base)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   int retval = win->detach(base);
-  smpi_bench_begin();
   return retval;
 }
 
 int PMPI_Win_free( MPI_Win* win){
   CHECK_NULL(1, MPI_ERR_WIN, win)
   CHECK_WIN(1, (*win))
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   delete *win;
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -152,12 +145,11 @@ int PMPI_Win_get_group(MPI_Win  win, MPI_Group * group){
 
 int PMPI_Win_fence( int assert,  MPI_Win win){
   CHECK_WIN(2, win)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_fence"));
   int retval = win->fence(assert);
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
   return retval;
 }
 
@@ -168,7 +160,7 @@ int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype,
   CHECK_TARGET_DISP(5)
 
   int retval = 0;
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   MPI_Group group;
@@ -182,7 +174,6 @@ int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype,
                          target_datatype);
   TRACE_smpi_comm_out(my_proc_id);
  
-  smpi_bench_begin();
   return retval;
 }
 
@@ -196,7 +187,7 @@ int PMPI_Rget( void *origin_addr, int origin_count, MPI_Datatype origin_datatype
   CHECK_NULL(9, MPI_ERR_ARG, request)
 
   int retval = 0;
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   MPI_Group group;
@@ -212,7 +203,6 @@ int PMPI_Rget( void *origin_addr, int origin_count, MPI_Datatype origin_datatype
 
   TRACE_smpi_comm_out(my_proc_id);
 
-  smpi_bench_begin();
   return retval;
 }
 
@@ -223,7 +213,7 @@ int PMPI_Put(const void *origin_addr, int origin_count, MPI_Datatype origin_data
   CHECK_TARGET_DISP(5)
 
   int retval = 0;
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   MPI_Group group;
@@ -241,7 +231,6 @@ int PMPI_Put(const void *origin_addr, int origin_count, MPI_Datatype origin_data
 
   TRACE_smpi_comm_out(my_proc_id);
 
-  smpi_bench_begin();
   return retval;
 }
 
@@ -254,7 +243,7 @@ int PMPI_Rput(const void *origin_addr, int origin_count, MPI_Datatype origin_dat
   CHECK_TARGET_DISP(5)
   CHECK_NULL(9, MPI_ERR_ARG, request)
   int retval = 0;
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   MPI_Group group;
@@ -272,7 +261,6 @@ int PMPI_Rput(const void *origin_addr, int origin_count, MPI_Datatype origin_dat
 
   TRACE_smpi_comm_out(my_proc_id);
 
-  smpi_bench_begin();
   return retval;
 }
 
@@ -285,7 +273,7 @@ int PMPI_Accumulate(const void *origin_addr, int origin_count, MPI_Datatype orig
 
   int retval = 0;
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   MPI_Group group;
   win->get_group(&group);
@@ -299,7 +287,6 @@ int PMPI_Accumulate(const void *origin_addr, int origin_count, MPI_Datatype orig
 
   TRACE_smpi_comm_out(my_proc_id);
 
-  smpi_bench_begin();
   return retval;
 }
 
@@ -315,7 +302,7 @@ int PMPI_Raccumulate(const void *origin_addr, int origin_count, MPI_Datatype ori
 
   int retval = 0;
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   MPI_Group group;
@@ -331,7 +318,6 @@ int PMPI_Raccumulate(const void *origin_addr, int origin_count, MPI_Datatype ori
 
   TRACE_smpi_comm_out(my_proc_id);
 
-  smpi_bench_begin();
   return retval;
 }
 
@@ -354,7 +340,7 @@ MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
   CHECK_TARGET_DISP(8)
 
   int retval = 0;
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   MPI_Group group;
@@ -371,7 +357,6 @@ MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
 
   TRACE_smpi_comm_out(my_proc_id);
 
-  smpi_bench_begin();
   return retval;
 }
 
@@ -395,7 +380,7 @@ MPI_Datatype target_datatype, MPI_Op op, MPI_Win win, MPI_Request* request){
   CHECK_TARGET_DISP(8)
   CHECK_NULL(10, MPI_ERR_ARG, request)
   int retval = 0;
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   MPI_Group group;
@@ -412,7 +397,6 @@ MPI_Datatype target_datatype, MPI_Op op, MPI_Win win, MPI_Request* request){
 
   TRACE_smpi_comm_out(my_proc_id);
 
-  smpi_bench_begin();
   return retval;
 }
 
@@ -433,7 +417,7 @@ int PMPI_Compare_and_swap(const void* origin_addr, void* compare_addr, void* res
 
   int retval = 0;
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   MPI_Group group;
@@ -447,53 +431,48 @@ int PMPI_Compare_and_swap(const void* origin_addr, void* compare_addr, void* res
 
   TRACE_smpi_comm_out(my_proc_id);
 
-  smpi_bench_begin();
   return retval;
 }
 
 int PMPI_Win_post(MPI_Group group, int assert, MPI_Win win){
   CHECK_GROUP(1, group)
   CHECK_WIN(2, win)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_post"));
   int retval = win->post(group,assert);
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
   return retval;
 }
 
 int PMPI_Win_start(MPI_Group group, int assert, MPI_Win win){
   CHECK_GROUP(1, group)
   CHECK_WIN(2, win)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_start"));
   int retval = win->start(group,assert);
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
   return retval;
 }
 
 int PMPI_Win_complete(MPI_Win win){
   CHECK_WIN(1, win)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_complete"));
   int retval = win->complete();
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
   return retval;
 }
 
 int PMPI_Win_wait(MPI_Win win){
   CHECK_WIN(1, win)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_wait"));
   int retval = win->wait();
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
   return retval;
 }
 
@@ -501,7 +480,7 @@ int PMPI_Win_lock(int lock_type, int rank, int assert, MPI_Win win){
   CHECK_WIN(4, win)
   CHECK_PROC_RMA(2, rank, win)
   int retval = 0;
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   if (lock_type != MPI_LOCK_EXCLUSIVE &&
       lock_type != MPI_LOCK_SHARED) {
     retval = MPI_ERR_LOCKTYPE;
@@ -511,87 +490,79 @@ int PMPI_Win_lock(int lock_type, int rank, int assert, MPI_Win win){
     retval = win->lock(lock_type,rank,assert);
     TRACE_smpi_comm_out(my_proc_id);
   }
-  smpi_bench_begin();
   return retval;
 }
 
 int PMPI_Win_unlock(int rank, MPI_Win win){
   CHECK_WIN(2, win)
   CHECK_PROC_RMA(1, rank, win)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_unlock"));
   int retval = win->unlock(rank);
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
   return retval;
 }
 
 int PMPI_Win_lock_all(int assert, MPI_Win win){
   CHECK_WIN(2, win)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_lock_all"));
   int retval = win->lock_all(assert);
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
   return retval;
 }
 
 int PMPI_Win_unlock_all(MPI_Win win){
   CHECK_WIN(1, win)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_unlock_all"));
   int retval = win->unlock_all();
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
   return retval;
 }
 
 int PMPI_Win_flush(int rank, MPI_Win win){
   CHECK_WIN(2, win)
   CHECK_PROC_RMA(1, rank, win)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_flush"));
   int retval = win->flush(rank);
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
   return retval;
 }
 
 int PMPI_Win_flush_local(int rank, MPI_Win win){
   CHECK_WIN(2, win)
   CHECK_PROC_RMA(1, rank, win)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_flush_local"));
   int retval = win->flush_local(rank);
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
   return retval;
 }
 
 int PMPI_Win_flush_all(MPI_Win win){
   CHECK_WIN(1, win)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_flush_all"));
   int retval = win->flush_all();
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
   return retval;
 }
 
 int PMPI_Win_flush_local_all(MPI_Win win){
   CHECK_WIN(1, win)
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_flush_local_all"));
   int retval = win->flush_local_all();
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
   return retval;
 }
 
index 5a2e5a8..4e56553 100644 (file)
@@ -129,6 +129,16 @@ XBT_PRIVATE void smpi_bench_end();
 XBT_PRIVATE void smpi_shared_destroy();
 XBT_PRIVATE double smpi_adjust_comp_speed();
 
+// This helper class uses RAII to call smpi_bench_end() when an object is built, and have smpi_bench_begin() be called
+// automatically when going out of scope.
+class XBT_PRIVATE SmpiBenchGuard {
+public:
+  SmpiBenchGuard() { smpi_bench_end(); }
+  SmpiBenchGuard(const SmpiBenchGuard&) = delete;
+  SmpiBenchGuard& operator=(const SmpiBenchGuard&) = delete;
+  ~SmpiBenchGuard() { smpi_bench_begin(); }
+};
+
 XBT_PRIVATE unsigned char* smpi_get_tmp_sendbuffer(size_t size);
 XBT_PRIVATE unsigned char* smpi_get_tmp_recvbuffer(size_t size);
 XBT_PRIVATE void smpi_free_tmp_buffer(const unsigned char* buf);
index d05db4d..a213c7f 100644 (file)
@@ -66,16 +66,14 @@ void smpi_execute(double duration)
 
 void smpi_execute_benched(double duration)
 {
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   double speed = sg_host_get_speed(sg_host_self());
   smpi_execute_flops(duration*speed);
-  smpi_bench_begin();
 }
 
 void smpi_execute_flops_benched(double flops) {
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   smpi_execute_flops(flops);
-  smpi_bench_begin();
 }
 
 void smpi_bench_begin()
@@ -168,7 +166,7 @@ void smpi_bench_end()
 /* Private sleep function used by smpi_sleep(), smpi_usleep() and friends */
 static unsigned int private_sleep(double secs)
 {
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
   XBT_DEBUG("Sleep for: %lf secs", secs);
   aid_t pid = simgrid::s4u::this_actor::get_pid();
@@ -178,7 +176,6 @@ static unsigned int private_sleep(double secs)
 
   TRACE_smpi_sleeping_out(pid);
 
-  smpi_bench_begin();
   return 0;
 }
 
@@ -210,7 +207,7 @@ int smpi_gettimeofday(struct timeval* tv, struct timezone* tz)
   if (not smpi_process()->initialized() || smpi_process()->finalized() || smpi_process()->sampling())
     return gettimeofday(tv, tz);
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   double now = simgrid::s4u::Engine::get_clock();
   if (tv) {
     tv->tv_sec = static_cast<time_t>(now);
@@ -222,7 +219,6 @@ int smpi_gettimeofday(struct timeval* tv, struct timezone* tz)
   }
   if (smpi_wtime_sleep > 0)
     simgrid::s4u::this_actor::sleep_for(smpi_wtime_sleep);
-  smpi_bench_begin();
   return 0;
 }
 
@@ -236,13 +232,12 @@ int smpi_clock_gettime(clockid_t clk_id, struct timespec* tp)
   if (not smpi_process()->initialized() || smpi_process()->finalized() || smpi_process()->sampling())
     return clock_gettime(clk_id, tp);
   //there is only one time in SMPI, so clk_id is ignored.
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   double now  = simgrid::s4u::Engine::get_clock();
   tp->tv_sec  = static_cast<time_t>(now);
   tp->tv_nsec = static_cast<long int>((now - tp->tv_sec) * 1e9);
   if (smpi_wtime_sleep > 0)
     simgrid::s4u::this_actor::sleep_for(smpi_wtime_sleep);
-  smpi_bench_begin();
   return 0;
 }
 #endif
@@ -251,11 +246,10 @@ double smpi_mpi_wtime()
 {
   double time;
   if (smpi_process()->initialized() && not smpi_process()->finalized() && not smpi_process()->sampling()) {
-    smpi_bench_end();
+    const SmpiBenchGuard suspend_bench;
     time = simgrid::s4u::Engine::get_clock();
     if (smpi_wtime_sleep > 0)
       simgrid::s4u::this_actor::sleep_for(smpi_wtime_sleep);
-    smpi_bench_begin();
   } else {
     time = simgrid::s4u::Engine::get_clock();
   }
@@ -265,20 +259,18 @@ double smpi_mpi_wtime()
 extern double sg_surf_precision;
 unsigned long long smpi_rastro_resolution ()
 {
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   double resolution = (1/sg_surf_precision);
-  smpi_bench_begin();
   return static_cast<unsigned long long>(resolution);
 }
 
 unsigned long long smpi_rastro_timestamp ()
 {
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   double now = simgrid::s4u::Engine::get_clock();
 
   auto sec               = static_cast<unsigned long long>(now);
   unsigned long long pre = (now - sec) * smpi_rastro_resolution();
-  smpi_bench_begin();
   return sec * smpi_rastro_resolution() + pre;
 }
 
index 4242dc5..10cf2a2 100644 (file)
@@ -74,26 +74,23 @@ xbt::signal<void(s4u::Actor const&)> on_iteration_out;
  */
 int APMPI_Iteration_in(MPI_Comm comm)
 {
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   TRACE_Iteration_in(comm->rank() + 1, new simgrid::instr::NoOpTIData("iteration_in")); // implemented on instr_smpi.c
-  smpi_bench_begin();
   return 1;
 }
 
 int APMPI_Iteration_out(MPI_Comm comm)
 {
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   TRACE_Iteration_out(comm->rank() + 1, new simgrid::instr::NoOpTIData("iteration_out"));
-  smpi_bench_begin();
   return 1;
 }
 
 void APMPI_Migrate(MPI_Comm comm)
 {
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
   aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   TRACE_migration_call(comm->rank() + 1, new simgrid::instr::AmpiMigrateTIData(memory_size[my_proc_id]));
-  smpi_bench_begin();
 }
 
 int AMPI_Iteration_in(MPI_Comm comm)