Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill trailing whitespaces in source code files.
[simgrid.git] / src / smpi / bindings / smpi_pmpi_win.cpp
index b3bab89..f2af808 100644 (file)
@@ -21,8 +21,8 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi);
   CHECK_COUNT(6, target_count)\
   CHECK_TYPE(7, target_datatype)
 
-#define CHECK_TARGET_DISP(num)\
-  if(win->dynamic()==0)\
+#define CHECK_TARGET_DISP(num)                                                                                         \
+  if (not win->dynamic())                                                                                              \
     CHECK_NEGATIVE((num), MPI_ERR_RMA_RANGE, target_disp)
 
 /* PMPI User level calls */
@@ -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();
+  *win                       = new simgrid::smpi::Win(ptr, size, disp_unit, info, comm, true);
   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();
+  *win                       = new simgrid::smpi::Win(ptr, size, disp_unit, info, comm, rank == 0);
   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,20 @@ 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();
+  if (_smpi_cfg_pedantic && (*win)->opened() == 1){//only check in pedantic mode, as it's not clear this is illegal
+    XBT_WARN("Attempt to destroy a MPI_Win too early -missing MPI_Win_fence ?");
+    return MPI_ERR_WIN;
+  }
+  const SmpiBenchGuard suspend_bench;
   delete *win;
-  smpi_bench_begin();
   return MPI_SUCCESS;
 }
 
@@ -152,12 +149,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();
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  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,21 +164,18 @@ 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;
 
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   MPI_Group group;
   win->get_group(&group);
   TRACE_smpi_comm_in(my_proc_id, __func__,
-                     new simgrid::instr::Pt2PtTIData("Get", target_rank, origin_datatype->is_replayable()
-                                                                             ? origin_count
-                                                                             : origin_count * origin_datatype->size(),
+                     new simgrid::instr::Pt2PtTIData("Get", target_rank, origin_count,
                                                      simgrid::smpi::Datatype::encode(origin_datatype)));
    retval = win->get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
                          target_datatype);
   TRACE_smpi_comm_out(my_proc_id);
-  smpi_bench_begin();
+
   return retval;
 }
 
@@ -196,15 +189,14 @@ 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;
 
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   MPI_Group group;
   win->get_group(&group);
   TRACE_smpi_comm_in(my_proc_id, __func__,
                      new simgrid::instr::Pt2PtTIData(
-                         "Rget", target_rank,
-                         origin_datatype->is_replayable() ? origin_count : origin_count * origin_datatype->size(),
+                         "Rget", target_rank, origin_count,
                          simgrid::smpi::Datatype::encode(origin_datatype)));
 
   retval = win->get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
@@ -212,7 +204,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,16 +214,14 @@ 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;
 
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   MPI_Group group;
   win->get_group(&group);
-  int dst_traced = group->actor(target_rank);
+  aid_t dst_traced = group->actor(target_rank);
   TRACE_smpi_comm_in(my_proc_id, __func__,
-                     new simgrid::instr::Pt2PtTIData("Put", target_rank, origin_datatype->is_replayable()
-                                                                             ? origin_count
-                                                                             : origin_count * origin_datatype->size(),
+                     new simgrid::instr::Pt2PtTIData("Put", target_rank, origin_count,
                                                      simgrid::smpi::Datatype::encode(origin_datatype)));
   TRACE_smpi_send(my_proc_id, my_proc_id, dst_traced, SMPI_RMA_TAG, origin_count * origin_datatype->size());
 
@@ -241,7 +230,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,16 +242,15 @@ 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;
 
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   MPI_Group group;
   win->get_group(&group);
-  int dst_traced = group->actor(target_rank);
+  aid_t dst_traced = group->actor(target_rank);
   TRACE_smpi_comm_in(my_proc_id, __func__,
                      new simgrid::instr::Pt2PtTIData(
-                         "Rput", target_rank,
-                         origin_datatype->is_replayable() ? origin_count : origin_count * origin_datatype->size(),
+                         "Rput", target_rank, origin_count,
                          simgrid::smpi::Datatype::encode(origin_datatype)));
   TRACE_smpi_send(my_proc_id, my_proc_id, dst_traced, SMPI_RMA_TAG, origin_count * origin_datatype->size());
 
@@ -272,7 +259,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,21 +271,19 @@ int PMPI_Accumulate(const void *origin_addr, int origin_count, MPI_Datatype orig
 
   int retval = 0;
 
-  smpi_bench_end();
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  const SmpiBenchGuard suspend_bench;
+  aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   MPI_Group group;
   win->get_group(&group);
   TRACE_smpi_comm_in(my_proc_id, __func__,
                      new simgrid::instr::Pt2PtTIData(
-                         "Accumulate", target_rank,
-                         origin_datatype->is_replayable() ? origin_count : origin_count * origin_datatype->size(),
+                         "Accumulate", target_rank, origin_count,
                          simgrid::smpi::Datatype::encode(origin_datatype)));
   retval = win->accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
                                 target_datatype, op);
 
   TRACE_smpi_comm_out(my_proc_id);
 
-  smpi_bench_begin();
   return retval;
 }
 
@@ -315,15 +299,14 @@ int PMPI_Raccumulate(const void *origin_addr, int origin_count, MPI_Datatype ori
 
   int retval = 0;
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   MPI_Group group;
   win->get_group(&group);
   TRACE_smpi_comm_in(my_proc_id, __func__,
                      new simgrid::instr::Pt2PtTIData(
-                         "Raccumulate", target_rank,
-                         origin_datatype->is_replayable() ? origin_count : origin_count * origin_datatype->size(),
+                         "Raccumulate", target_rank, origin_count,
                          simgrid::smpi::Datatype::encode(origin_datatype)));
 
   retval = win->accumulate( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count,
@@ -331,18 +314,19 @@ 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;
 }
 
-int PMPI_Get_accumulate(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype, void *result_addr,
-int result_count, MPI_Datatype result_datatype, int target_rank, MPI_Aint target_disp, int target_count,
-MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
-  CHECK_COUNT(2, origin_count)
-  if(origin_count>0)
-    CHECK_TYPE(3, origin_datatype)
-  if (op != MPI_NO_OP)
+int PMPI_Get_accumulate(const void* origin_addr, int origin_count, MPI_Datatype origin_datatype, void* result_addr,
+                        int result_count, MPI_Datatype result_datatype, int target_rank, MPI_Aint target_disp,
+                        int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win)
+{
+  if (op != MPI_NO_OP){
     CHECK_BUFFER(1, origin_addr, origin_count, origin_datatype)
+    CHECK_COUNT(2, origin_count)
+    if(origin_count>0)
+      CHECK_TYPE(3, origin_datatype)
+  }
   CHECK_COUNT(5, result_count)
   CHECK_TYPE(6, result_datatype)
   CHECK_BUFFER(4, result_addr, result_count, result_datatype)
@@ -354,15 +338,14 @@ MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
   CHECK_TARGET_DISP(8)
 
   int retval = 0;
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   MPI_Group group;
   win->get_group(&group);
   TRACE_smpi_comm_in(my_proc_id, __func__,
                      new simgrid::instr::Pt2PtTIData(
-                         "Get_accumulate", target_rank,
-                         target_datatype->is_replayable() ? target_count : target_count * target_datatype->size(),
+                         "Get_accumulate", target_rank, target_count,
                          simgrid::smpi::Datatype::encode(target_datatype)));
 
   retval = win->get_accumulate( origin_addr, origin_count, origin_datatype, result_addr,
@@ -371,19 +354,21 @@ MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){
 
   TRACE_smpi_comm_out(my_proc_id);
 
-  smpi_bench_begin();
   return retval;
 }
 
-
-int PMPI_Rget_accumulate(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype, void *result_addr,
-int result_count, MPI_Datatype result_datatype, int target_rank, MPI_Aint target_disp, int target_count,
-MPI_Datatype target_datatype, MPI_Op op, MPI_Win win, MPI_Request* request){
+int PMPI_Rget_accumulate(const void* origin_addr, int origin_count, MPI_Datatype origin_datatype, void* result_addr,
+                         int result_count, MPI_Datatype result_datatype, int target_rank, MPI_Aint target_disp,
+                         int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win, MPI_Request* request)
+{
   if(target_rank==MPI_PROC_NULL)
     *request = MPI_REQUEST_NULL;
-  CHECK_COUNT(2, origin_count)
-  CHECK_TYPE(3, origin_datatype)
-  CHECK_BUFFER(1, origin_addr, origin_count, origin_datatype)
+  if (op != MPI_NO_OP){
+    CHECK_BUFFER(1, origin_addr, origin_count, origin_datatype)
+    CHECK_COUNT(2, origin_count)
+    if(origin_count>0)
+      CHECK_TYPE(3, origin_datatype)
+  }
   CHECK_COUNT(5, result_count)
   CHECK_TYPE(6, result_datatype)
   CHECK_BUFFER(4, result_addr, result_count, result_datatype)
@@ -395,15 +380,14 @@ 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;
 
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   MPI_Group group;
   win->get_group(&group);
   TRACE_smpi_comm_in(my_proc_id, __func__,
                      new simgrid::instr::Pt2PtTIData(
-                         "Rget_accumulate", target_rank,
-                         target_datatype->is_replayable() ? target_count : target_count * target_datatype->size(),
+                         "Rget_accumulate", target_rank, target_count,
                          simgrid::smpi::Datatype::encode(target_datatype)));
 
   retval = win->get_accumulate( origin_addr, origin_count, origin_datatype, result_addr,
@@ -412,7 +396,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,67 +416,61 @@ int PMPI_Compare_and_swap(const void* origin_addr, void* compare_addr, void* res
 
   int retval = 0;
 
-  smpi_bench_end();
+  const SmpiBenchGuard suspend_bench;
 
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
   MPI_Group group;
   win->get_group(&group);
   TRACE_smpi_comm_in(my_proc_id, __func__,
-                     new simgrid::instr::Pt2PtTIData("Compare_and_swap", target_rank,
-                                                     datatype->is_replayable() ? 1 : datatype->size(),
+                     new simgrid::instr::Pt2PtTIData("Compare_and_swap", target_rank, 1,
                                                      simgrid::smpi::Datatype::encode(datatype)));
 
   retval = win->compare_and_swap(origin_addr, compare_addr, result_addr, datatype, target_rank, target_disp);
 
   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();
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  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();
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  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();
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  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();
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  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,97 +478,89 @@ 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;
   } else {
-    int my_proc_id = simgrid::s4u::this_actor::get_pid();
+    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"));
     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();
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  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();
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  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();
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  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();
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  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();
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  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();
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  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();
-  int my_proc_id = simgrid::s4u::this_actor::get_pid();
+  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;
 }