Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / src / smpi / mpi / smpi_win.cpp
index 39d4756..c0abd4d 100644 (file)
@@ -4,14 +4,15 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "smpi_win.hpp"
+
 #include "private.hpp"
 #include "smpi_coll.hpp"
 #include "smpi_comm.hpp"
 #include "smpi_datatype.hpp"
 #include "smpi_info.hpp"
 #include "smpi_keyvals.hpp"
-#include "smpi_process.hpp"
 #include "smpi_request.hpp"
+#include "src/smpi/include/smpi_actor.hpp"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_rma, smpi, "Logging specific to SMPI (RMA operations)");
 
@@ -39,7 +40,7 @@ Win::Win(void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm,
   connected_wins_[rank_] = this;
   count_                 = 0;
   if(rank_==0){
-    bar_ = MSG_barrier_init(comm_size);
+    bar_ = new simgrid::s4u::Barrier(comm_size);
   }
   mode_=0;
 
@@ -49,14 +50,14 @@ 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_, sizeof(MPI_Win),
                          MPI_BYTE, comm);
 
-  Colls::bcast(&(bar_), sizeof(msg_bar_t), MPI_BYTE, 0, comm);
+  Colls::bcast(&(bar_), sizeof(simgrid::s4u::Barrier*), MPI_BYTE, 0, comm);
 
   Colls::barrier(comm);
 }
 
 Win::~Win(){
   //As per the standard, perform a barrier to ensure every async comm is finished
-  MSG_barrier_wait(bar_);
+  bar_->wait();
 
   int finished = finish_comms();
   XBT_DEBUG("Win destructor - Finished %d RMA calls", finished);
@@ -76,7 +77,7 @@ Win::~Win(){
   Comm::unref(comm_);
   
   if (rank_ == 0)
-    MSG_barrier_destroy(bar_);
+    delete bar_;
   xbt_mutex_destroy(mut_);
   xbt_mutex_destroy(lock_mut_);
   xbt_mutex_destroy(atomic_mut_);
@@ -163,7 +164,7 @@ int Win::fence(int assert)
     opened_=1;
   if (assert != MPI_MODE_NOPRECEDE) {
     // This is not the first fence => finalize what came before
-    MSG_barrier_wait(bar_);
+    bar_->wait();
     xbt_mutex_acquire(mut_);
     // This (simulated) mutex ensures that no process pushes to the vector of requests during the waitall.
     // Without this, the vector could get redimensionned when another process pushes.
@@ -184,7 +185,7 @@ int Win::fence(int assert)
     opened_=0;
   assert_ = assert;
 
-  MSG_barrier_wait(bar_);
+  bar_->wait();
   XBT_DEBUG("Leaving fence");
 
   return MPI_SUCCESS;
@@ -629,9 +630,9 @@ int Win::unlock_all(){
   int i=0;
   int retval = MPI_SUCCESS;
   for (i=0; i<comm_->size();i++){
-      int ret = this->unlock(i);
-      if(ret != MPI_SUCCESS)
-        retval = ret;
+    int ret = this->unlock(i);
+    if (ret != MPI_SUCCESS)
+      retval = ret;
   }
   return retval;
 }
@@ -652,11 +653,9 @@ int Win::flush_local(int rank){
 }
 
 int Win::flush_all(){
-  int i=0;
-  int finished = 0;
-  finished = finish_comms();
+  int finished = finish_comms();
   XBT_DEBUG("Win_flush_all on local - Finished %d RMA calls", finished);
-  for (i=0; i<comm_->size();i++){
+  for (int i = 0; i < comm_->size(); i++) {
     finished = connected_wins_[i]->finish_comms(rank_);
     XBT_DEBUG("Win_flush_all on %d - Finished %d RMA calls", i, finished);
   }
@@ -673,7 +672,6 @@ Win* Win::f2c(int id){
   return static_cast<Win*>(F2C::f2c(id));
 }
 
-
 int Win::finish_comms(){
   xbt_mutex_acquire(mut_);
   //Finish own requests
@@ -721,28 +719,22 @@ int Win::finish_comms(int rank){
   return size;
 }
 
-
-int Win::shared_query(int rank, MPI_Aint* size, int* disp_unit, void* baseptr){
-
-  if(rank!=MPI_PROC_NULL){
-    MPI_Win target_win = connected_wins_[rank];
-    *size=target_win->size_;
-    *disp_unit=target_win->disp_unit_;
-    *static_cast<void**>(baseptr)=target_win->base_;
-  }else{
-    for(int i=0; i<comm_->size();i++){
-      MPI_Win target_win = connected_wins_[i];
-      if(target_win->size_>0){
-        *size=target_win->size_;
-        *disp_unit=target_win->disp_unit_;
-        *static_cast<void**>(baseptr)=target_win->base_;
-        return MPI_SUCCESS;
-      }
-    }
-    *size=0;
-    *static_cast<void**>(baseptr)=xbt_malloc(0);
+int Win::shared_query(int rank, MPI_Aint* size, int* disp_unit, void* baseptr)
+{
+  MPI_Win target_win = rank != MPI_PROC_NULL ? connected_wins_[rank] : nullptr;
+  for (int i = 0; not target_win && i < comm_->size(); i++) {
+    if (connected_wins_[i]->size_ > 0)
+      target_win = connected_wins_[i];
   }
-  return MPI_SUCCESS;
+  if (target_win) {
+    *size                         = target_win->size_;
+    *disp_unit                    = target_win->disp_unit_;
+    *static_cast<void**>(baseptr) = target_win->base_;
+  } else {
+    *size                         = 0;
+    *static_cast<void**>(baseptr) = xbt_malloc(0);
   }
+  return MPI_SUCCESS;
+}
 }
 }