Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce code duplication (and fix bug in Group::difference).
[simgrid.git] / src / smpi / mpi / smpi_win.cpp
index 2c7d83c..cfee3d9 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2021. 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. */
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_rma, smpi, "Logging specific to SMPI (RMA operations)");
 
+#define CHECK_RMA_REMOTE_WIN(fun, win)\
+  if(target_count*target_datatype->get_extent()>win->size_){\
+    XBT_WARN("%s: Trying to move %zd, which exceeds the window size on target process %d : %zd - Bailing out.",\
+    fun, target_count*target_datatype->get_extent(), target_rank, win->size_);\
+    simgrid::smpi::utils::set_current_buffer(1,"win_base",win->base_);\
+    return MPI_ERR_RMA_RANGE;\
+  }
+
+#define CHECK_WIN_LOCKED(win)\
+  if(opened_==0){ /*check that post/start has been done*/\
+    int locked=0;\
+    for (auto const& it : win->lockers_)\
+      if (it == comm_->rank())\
+        locked = 1;\
+    if(locked != 1)\
+      return MPI_ERR_WIN;\
+  }
 
 namespace simgrid{
 namespace smpi{
@@ -49,9 +66,10 @@ Win::Win(void* base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm,
   colls::allgather(&connected_wins_[rank_], sizeof(MPI_Win), MPI_BYTE, connected_wins_.data(), sizeof(MPI_Win),
                    MPI_BYTE, comm);
 
-  colls::bcast(&(bar_), sizeof(s4u::Barrier*), MPI_BYTE, 0, comm);
+  colls::bcast(&bar_, sizeof(s4u::Barrier*), MPI_BYTE, 0, comm);
 
   colls::barrier(comm);
+  this->add_f();
 }
 
 Win::~Win(){
@@ -77,6 +95,7 @@ Win::~Win(){
   if(allocated_ !=0)
     xbt_free(base_);
 
+  F2C::free_f(this->f2c_id());
   cleanup_attr<Win>();
 }
 
@@ -126,6 +145,11 @@ int Win::rank() const
   return rank_;
 }
 
+MPI_Comm Win::comm() const
+{
+  return comm_;
+}
+
 MPI_Aint Win::size() const
 {
   return size_;
@@ -209,8 +233,7 @@ int Win::put(const void *origin_addr, int origin_count, MPI_Datatype origin_data
       return MPI_ERR_WIN;
   }
 
-  if(target_count*target_datatype->get_extent()>recv_win->size_)
-    return MPI_ERR_ARG;
+  CHECK_RMA_REMOTE_WIN("MPI_Put", recv_win)
 
   void* recv_addr = static_cast<char*>(recv_win->base_) + target_disp * recv_win->disp_unit_;
 
@@ -259,18 +282,8 @@ int Win::get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype,
   //get sender pointer
   Win* send_win = connected_wins_[target_rank];
 
-  if(opened_==0){//check that post/start has been done
-    // no fence or start .. lock ok ?
-    int locked=0;
-    for (auto const& it : send_win->lockers_)
-      if (it == comm_->rank())
-        locked = 1;
-    if(locked != 1)
-      return MPI_ERR_WIN;
-  }
-
-  if(target_count*target_datatype->get_extent()>send_win->size_)
-    return MPI_ERR_ARG;
+  CHECK_WIN_LOCKED(send_win)
+  CHECK_RMA_REMOTE_WIN("MPI_Get", send_win)
 
   const void* send_addr = static_cast<void*>(static_cast<char*>(send_win->base_) + target_disp * send_win->disp_unit_);
   XBT_DEBUG("Entering MPI_Get from %d", target_rank);
@@ -318,19 +331,9 @@ int Win::accumulate(const void *origin_addr, int origin_count, MPI_Datatype orig
   //get receiver pointer
   Win* recv_win = connected_wins_[target_rank];
 
-  if(opened_==0){//check that post/start has been done
-    // no fence or start .. lock ok ?
-    int locked=0;
-    for (auto const& it : recv_win->lockers_)
-      if (it == comm_->rank())
-        locked = 1;
-    if(locked != 1)
-      return MPI_ERR_WIN;
-  }
   //FIXME: local version
-
-  if(target_count*target_datatype->get_extent()>recv_win->size_)
-    return MPI_ERR_ARG;
+  CHECK_WIN_LOCKED(recv_win)
+  CHECK_RMA_REMOTE_WIN("MPI_Accumulate", recv_win)
 
   void* recv_addr = static_cast<char*>(recv_win->base_) + target_disp * recv_win->disp_unit_;
   XBT_DEBUG("Entering MPI_Accumulate to %d", target_rank);
@@ -374,18 +377,8 @@ int Win::get_accumulate(const void* origin_addr, int origin_count, MPI_Datatype
   //get sender pointer
   const Win* send_win = connected_wins_[target_rank];
 
-  if(opened_==0){//check that post/start has been done
-    // no fence or start .. lock ok ?
-    int locked=0;
-    for (auto const& it : send_win->lockers_)
-      if (it == comm_->rank())
-        locked = 1;
-    if(locked != 1)
-      return MPI_ERR_WIN;
-  }
-
-  if(target_count*target_datatype->get_extent()>send_win->size_)
-    return MPI_ERR_ARG;
+  CHECK_WIN_LOCKED(send_win)
+  CHECK_RMA_REMOTE_WIN("MPI_Get_Accumulate", send_win)
 
   XBT_DEBUG("Entering MPI_Get_accumulate from %d", target_rank);
   //need to be sure ops are correctly ordered, so finish request here ? slow.
@@ -410,15 +403,7 @@ int Win::compare_and_swap(const void* origin_addr, const void* compare_addr, voi
   //get sender pointer
   const Win* send_win = connected_wins_[target_rank];
 
-  if(opened_==0){//check that post/start has been done
-    // no fence or start .. lock ok ?
-    int locked=0;
-    for (auto const& it : send_win->lockers_)
-      if (it == comm_->rank())
-        locked = 1;
-    if(locked != 1)
-      return MPI_ERR_WIN;
-  }
+  CHECK_WIN_LOCKED(send_win)
 
   XBT_DEBUG("Entering MPI_Compare_and_swap with %d", target_rank);
   MPI_Request req = MPI_REQUEST_NULL;
@@ -509,8 +494,7 @@ int Win::post(MPI_Group group, int /*assert*/)
 }
 
 int Win::complete(){
-  if(opened_==0)
-    xbt_die("Complete called on already opened MPI_Win");
+  xbt_assert(opened_ != 0, "Complete called on already opened MPI_Win");
 
   XBT_DEBUG("Entering MPI_Win_Complete");
   int i             = 0;