Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Some int -> bool conversions (+ use of existing macro).
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 2 Jun 2021 12:55:46 +0000 (14:55 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 2 Jun 2021 13:05:18 +0000 (15:05 +0200)
src/smpi/bindings/smpi_pmpi_win.cpp
src/smpi/include/smpi_win.hpp
src/smpi/mpi/smpi_win.cpp

index 16561b1..c560666 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 */
@@ -49,7 +49,7 @@ int PMPI_Win_allocate( MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm com
   void* ptr = xbt_malloc(size);
   const SmpiBenchGuard suspend_bench;
   *static_cast<void**>(base) = ptr;
-  *win = new simgrid::smpi::Win( ptr, size, disp_unit, info, comm,1);
+  *win                       = new simgrid::smpi::Win(ptr, size, disp_unit, info, comm, true);
   return MPI_SUCCESS;
 }
 
@@ -66,7 +66,7 @@ int PMPI_Win_allocate_shared( MPI_Aint size, int disp_unit, MPI_Info info, MPI_C
   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);
+  *win                       = new simgrid::smpi::Win(ptr, size, disp_unit, info, comm, rank == 0);
   return MPI_SUCCESS;
 }
 
index cb5ab79..5a6f3a1 100644 (file)
@@ -39,16 +39,17 @@ class Win : public F2C, public Keyval {
   std::list<int> lockers_;
   int rank_; // to identify owner for barriers in MPI_COMM_WORLD
   int mode_ = 0; // exclusive or shared lock
-  int allocated_;
-  int dynamic_;
+  bool allocated_;
+  bool dynamic_;
   MPI_Errhandler errhandler_ = MPI_ERRORS_ARE_FATAL;
 
 public:
   static std::unordered_map<int, smpi_key_elem> keyvals_;
   static int keyval_id_;
 
-  Win(void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, int allocated = 0, int dynamic = 0);
-  Win(MPI_Info info, MPI_Comm comm) : Win(MPI_BOTTOM, 0, 1, info, comm, 0, 1) {};
+  Win(void* base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, bool allocated = false,
+      bool dynamic = false);
+  Win(MPI_Info info, MPI_Comm comm) : Win(MPI_BOTTOM, 0, 1, info, comm, false, true){};
   Win(const Win&) = delete;
   Win& operator=(const Win&) = delete;
   ~Win() override;
@@ -60,7 +61,7 @@ public:
   void set_name(const char* name);
   int rank() const;
   MPI_Comm comm() const;
-  int dynamic() const;
+  bool dynamic() const;
   int start(MPI_Group group, int assert);
   int post(MPI_Group group, int assert);
   int complete();
index 7e8217c..8a7f57b 100644 (file)
@@ -26,14 +26,11 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_rma, smpi, "Logging specific to SMPI (RMA o
     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;\
+#define CHECK_WIN_LOCKED(win)                                                                                          \
+  if (opened_ == 0) { /*check that post/start has been done*/                                                          \
+    bool locked = std::any_of(begin(win->lockers_), end(win->lockers_), [this](int it) { return it == this->rank_; }); \
+    if (not locked)                                                                                                    \
+      return MPI_ERR_WIN;                                                                                              \
   }
 
 namespace simgrid{
@@ -41,7 +38,7 @@ namespace smpi{
 std::unordered_map<int, smpi_key_elem> Win::keyvals_;
 int Win::keyval_id_=0;
 
-Win::Win(void* base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, int allocated, int dynamic)
+Win::Win(void* base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, bool allocated, bool dynamic)
     : base_(base)
     , size_(size)
     , disp_unit_(disp_unit)
@@ -92,7 +89,7 @@ Win::~Win(){
   if (rank_ == 0)
     delete bar_;
 
-  if(allocated_ !=0)
+  if (allocated_)
     xbt_free(base_);
 
   F2C::free_f(this->f2c_id());
@@ -165,7 +162,7 @@ int Win::disp_unit() const
   return disp_unit_;
 }
 
-int Win::dynamic() const
+bool Win::dynamic() const
 {
   return dynamic_;
 }
@@ -223,16 +220,7 @@ int Win::put(const void *origin_addr, int origin_count, MPI_Datatype origin_data
   //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;
-  }
-
+  CHECK_WIN_LOCKED(recv_win)
   CHECK_RMA_REMOTE_WIN("MPI_Put", recv_win)
 
   void* recv_addr = static_cast<char*>(recv_win->base_) + target_disp * recv_win->disp_unit_;