Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make Datatype::name_ and Win::name_ a std::string.
[simgrid.git] / src / smpi / mpi / smpi_win.cpp
index f62ab4e..73bd32d 100644 (file)
@@ -36,7 +36,6 @@ Win::Win(void* base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm,
   if(info!=MPI_INFO_NULL)
     info->ref();
   int comm_size          = comm->size();
-  name_                  = nullptr;
   opened_                = 0;
   group_                 = MPI_GROUP_NULL;
   requests_              = new std::vector<MPI_Request>();
@@ -72,9 +71,6 @@ Win::~Win(){
 
   delete requests_;
   delete[] connected_wins_;
-  if (name_ != nullptr){
-    xbt_free(name_);
-  }
   if (info_ != MPI_INFO_NULL)
     simgrid::smpi::Info::unref(info_);
   if (errhandler_ != MPI_ERRHANDLER_NULL)
@@ -96,9 +92,9 @@ Win::~Win(){
 
 int Win::attach(void* /*base*/, MPI_Aint size)
 {
-  if (not(base_ == MPI_BOTTOM || base_ == 0))
+  if (not(base_ == MPI_BOTTOM || base_ == nullptr))
     return MPI_ERR_ARG;
-  base_=0;//actually the address will be given in the RMA calls, as being the disp.
+  base_ = nullptr; // actually the address will be given in the RMA calls, as being the disp.
   size_+=size;
   return MPI_SUCCESS;
 }
@@ -112,13 +108,11 @@ int Win::detach(const void* /*base*/)
 
 void Win::get_name(char* name, int* length) const
 {
-  if(name_==nullptr){
-    *length=0;
-    name=nullptr;
-    return;
+  *length = name_.length();
+  if (not name_.empty()) {
+    name_.copy(name, *length);
+    name[*length] = '\0';
   }
-  *length = strlen(name_);
-  strncpy(name, name_, *length+1);
 }
 
 void Win::get_group(MPI_Group* group){
@@ -172,7 +166,7 @@ void Win::set_info(MPI_Info info)
 }
 
 void Win::set_name(const char* name){
-  name_ = xbt_strdup(name);
+  name_ = name;
 }
 
 int Win::fence(int assert)
@@ -228,7 +222,7 @@ int Win::put(const void *origin_addr, int origin_count, MPI_Datatype origin_data
   if(target_count*target_datatype->get_extent()>recv_win->size_)
     return MPI_ERR_ARG;
 
-  void* recv_addr = static_cast<void*> ( static_cast<char*>(recv_win->base_) + target_disp * recv_win->disp_unit_);
+  void* recv_addr = static_cast<char*>(recv_win->base_) + target_disp * recv_win->disp_unit_;
 
   if (target_rank != comm_->rank()) { // This is not for myself, so we need to send messages
     XBT_DEBUG("Entering MPI_Put to remote rank %d", target_rank);
@@ -348,7 +342,7 @@ int Win::accumulate(const void *origin_addr, int origin_count, MPI_Datatype orig
   if(target_count*target_datatype->get_extent()>recv_win->size_)
     return MPI_ERR_ARG;
 
-  void* recv_addr = static_cast<void*>(static_cast<char*>(recv_win->base_) + target_disp * recv_win->disp_unit_);
+  void* recv_addr = static_cast<char*>(recv_win->base_) + target_disp * recv_win->disp_unit_;
   XBT_DEBUG("Entering MPI_Accumulate to %d", target_rank);
   // As the tag will be used for ordering of the operations, subtract count from it (to avoid collisions with other
   // SMPI tags, SMPI_RMA_TAG is set below all the other ones we use)
@@ -469,7 +463,7 @@ int Win::start(MPI_Group group, int /*assert*/)
   int i             = 0;
   int j             = 0;
   int size          = group->size();
-  MPI_Request* reqs = xbt_new0(MPI_Request, size);
+  std::vector<MPI_Request> reqs(size);
 
   XBT_DEBUG("Entering MPI_Win_Start");
   while (j != size) {
@@ -481,12 +475,11 @@ int Win::start(MPI_Group group, int /*assert*/)
     j++;
   }
   size = i;
-  Request::startall(size, reqs);
-  Request::waitall(size, reqs, MPI_STATUSES_IGNORE);
+  Request::startall(size, reqs.data());
+  Request::waitall(size, reqs.data(), MPI_STATUSES_IGNORE);
   for (i = 0; i < size; i++) {
     Request::unref(&reqs[i]);
   }
-  xbt_free(reqs);
   opened_++; //we're open for business !
   group_=group;
   group->ref();
@@ -500,7 +493,7 @@ int Win::post(MPI_Group group, int /*assert*/)
   int i             = 0;
   int j             = 0;
   int size = group->size();
-  MPI_Request* reqs = xbt_new0(MPI_Request, size);
+  std::vector<MPI_Request> reqs(size);
 
   XBT_DEBUG("Entering MPI_Win_Post");
   while(j!=size){
@@ -513,12 +506,11 @@ int Win::post(MPI_Group group, int /*assert*/)
   }
   size=i;
 
-  Request::startall(size, reqs);
-  Request::waitall(size, reqs, MPI_STATUSES_IGNORE);
+  Request::startall(size, reqs.data());
+  Request::waitall(size, reqs.data(), MPI_STATUSES_IGNORE);
   for(i=0;i<size;i++){
     Request::unref(&reqs[i]);
   }
-  xbt_free(reqs);
   opened_++; //we're open for business !
   group_=group;
   group->ref();
@@ -534,7 +526,7 @@ int Win::complete(){
   int i             = 0;
   int j             = 0;
   int size          = group_->size();
-  MPI_Request* reqs = xbt_new0(MPI_Request, size);
+  std::vector<MPI_Request> reqs(size);
 
   while(j!=size){
     int dst = comm_->group()->rank(group_->actor(j));
@@ -546,13 +538,12 @@ int Win::complete(){
   }
   size=i;
   XBT_DEBUG("Win_complete - Sending sync messages to %d processes", size);
-  Request::startall(size, reqs);
-  Request::waitall(size, reqs, MPI_STATUSES_IGNORE);
+  Request::startall(size, reqs.data());
+  Request::waitall(size, reqs.data(), MPI_STATUSES_IGNORE);
 
   for(i=0;i<size;i++){
     Request::unref(&reqs[i]);
   }
-  xbt_free(reqs);
 
   int finished = finish_comms();
   XBT_DEBUG("Win_complete - Finished %d RMA calls", finished);
@@ -568,7 +559,7 @@ int Win::wait(){
   int i             = 0;
   int j             = 0;
   int size          = group_->size();
-  MPI_Request* reqs = xbt_new0(MPI_Request, size);
+  std::vector<MPI_Request> reqs(size);
 
   while(j!=size){
     int src = comm_->group()->rank(group_->actor(j));
@@ -580,12 +571,11 @@ int Win::wait(){
   }
   size=i;
   XBT_DEBUG("Win_wait - Receiving sync messages from %d processes", size);
-  Request::startall(size, reqs);
-  Request::waitall(size, reqs, MPI_STATUSES_IGNORE);
+  Request::startall(size, reqs.data());
+  Request::waitall(size, reqs.data(), MPI_STATUSES_IGNORE);
   for(i=0;i<size;i++){
     Request::unref(&reqs[i]);
   }
-  xbt_free(reqs);
   int finished = finish_comms();
   XBT_DEBUG("Win_wait - Finished %d RMA calls", finished);
 
@@ -617,12 +607,11 @@ int Win::lock(int lock_type, int rank, int /*assert*/)
 }
 
 int Win::lock_all(int assert){
-  int i=0;
   int retval = MPI_SUCCESS;
-  for (i=0; i<comm_->size();i++){
-      int ret = this->lock(MPI_LOCK_SHARED, i, assert);
-      if(ret != MPI_SUCCESS)
-        retval = ret;
+  for (int i = 0; i < comm_->size(); i++) {
+    int ret = this->lock(MPI_LOCK_SHARED, i, assert);
+    if (ret != MPI_SUCCESS)
+      retval = ret;
   }
   return retval;
 }
@@ -644,9 +633,8 @@ int Win::unlock(int rank){
 }
 
 int Win::unlock_all(){
-  int i=0;
   int retval = MPI_SUCCESS;
-  for (i=0; i<comm_->size();i++){
+  for (int i = 0; i < comm_->size(); i++) {
     int ret = this->unlock(i);
     if (ret != MPI_SUCCESS)
       retval = ret;
@@ -711,7 +699,7 @@ int Win::finish_comms(int rank){
   if (size > 0) {
     size = 0;
     std::vector<MPI_Request> myreqqs;
-    std::vector<MPI_Request>::iterator iter = reqqs->begin();
+    auto iter                               = reqqs->begin();
     int proc_id                             = comm_->group()->actor(rank)->get_pid();
     while (iter != reqqs->end()){
       // Let's see if we're either the destination or the sender of this request