Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use a std::unique_ptr, and avoid explicit new/delete.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 24 Mar 2022 13:16:17 +0000 (14:16 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 24 Mar 2022 22:08:25 +0000 (23:08 +0100)
src/smpi/include/smpi_comm.hpp
src/smpi/mpi/smpi_comm.cpp

index 7132522..9310454 100644 (file)
@@ -43,8 +43,7 @@ class Comm : public F2C, public Keyval{
   std::unordered_map<std::string, unsigned int> sent_messages_;
   std::unordered_map<std::string, unsigned int> recv_messages_;
   unsigned int collectives_count_ = 0;
-  unsigned int* collectives_counts_ = nullptr; //for MPI_COMM_WORLD only
-
+  std::unique_ptr<unsigned int[]> collectives_counts_; // for MPI_COMM_WORLD only
 
 public:
   static std::unordered_map<int, smpi_key_elem> keyvals_;
index 7e19385..83d6612 100644 (file)
@@ -364,8 +364,6 @@ void Comm::unref(Comm* comm){
       delete[] comm->errhandlers_;
     } else if (comm->errhandler_ != MPI_ERRHANDLER_NULL)
       simgrid::smpi::Errhandler::unref(comm->errhandler_);
-    if(comm->collectives_counts_!=nullptr)
-      delete[] comm->collectives_counts_;
   }
   Group::unref(comm->group_);
   if(comm->refcount_==0)
@@ -656,8 +654,8 @@ unsigned int Comm::get_collectives_count()
   if (this==MPI_COMM_UNINITIALIZED){
     return smpi_process()->comm_world()->get_collectives_count();
   }else if(this == MPI_COMM_WORLD || this == smpi_process()->comm_world()){
-    if(collectives_counts_==nullptr)
-      collectives_counts_=new unsigned int[this->size()]{0};
+    if (not collectives_counts_)
+      collectives_counts_ = std::make_unique<unsigned int[]>(this->size());
     return collectives_counts_[this->rank()];
   }else{
     return collectives_count_;
@@ -669,8 +667,8 @@ void Comm::increment_collectives_count()
    if (this==MPI_COMM_UNINITIALIZED){
     smpi_process()->comm_world()->increment_collectives_count();
   }else if (this == MPI_COMM_WORLD || this == smpi_process()->comm_world()){
-    if(collectives_counts_==nullptr)
-      collectives_counts_=new unsigned int[this->size()]{0};
+    if (not collectives_counts_)
+      collectives_counts_ = std::make_unique<unsigned int[]>(this->size());
     collectives_counts_[this->rank()]++;
   }else{
     collectives_count_++;