From 19a4c35db5550b9b93e1d63b09ff18f5c10facdb Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 2 Jun 2021 14:55:46 +0200 Subject: [PATCH] Some int -> bool conversions (+ use of existing macro). --- src/smpi/bindings/smpi_pmpi_win.cpp | 8 ++++---- src/smpi/include/smpi_win.hpp | 11 ++++++----- src/smpi/mpi/smpi_win.cpp | 30 +++++++++-------------------- 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/src/smpi/bindings/smpi_pmpi_win.cpp b/src/smpi/bindings/smpi_pmpi_win.cpp index 16561b1456..c56066646f 100644 --- a/src/smpi/bindings/smpi_pmpi_win.cpp +++ b/src/smpi/bindings/smpi_pmpi_win.cpp @@ -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(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(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; } diff --git a/src/smpi/include/smpi_win.hpp b/src/smpi/include/smpi_win.hpp index cb5ab79f98..5a6f3a142d 100644 --- a/src/smpi/include/smpi_win.hpp +++ b/src/smpi/include/smpi_win.hpp @@ -39,16 +39,17 @@ class Win : public F2C, public Keyval { std::list 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 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(); diff --git a/src/smpi/mpi/smpi_win.cpp b/src/smpi/mpi/smpi_win.cpp index 7e8217c96d..8a7f57bf54 100644 --- a/src/smpi/mpi/smpi_win.cpp +++ b/src/smpi/mpi/smpi_win.cpp @@ -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 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(recv_win->base_) + target_disp * recv_win->disp_unit_; -- 2.20.1