Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[INSTR] Move vector* to shared_ptr<vector>.
authorChristian Heinrich <franz-christian.heinrich@inria.fr>
Tue, 13 Mar 2018 17:19:21 +0000 (18:19 +0100)
committerChristian Heinrich <franz-christian.heinrich@inria.fr>
Wed, 28 Mar 2018 15:31:39 +0000 (17:31 +0200)
By initializing an object, for instance of type VarCollTIData,
the vectors containing receive and send counts were deleted
when the TI object was deleted. This is unexpected by a 'normal'
user - by accepting shared_ptrs, this can be ameliorated.

The constructor that still accepts vector* should be removed once
all initializations use the constructor accepting the shared_ptr.

src/instr/instr_private.hpp

index 57413b0..0004fa9 100644 (file)
@@ -19,6 +19,7 @@
 #include "xbt/graph.h"
 #include <iomanip> /** std::setprecision **/
 #include <map>
 #include "xbt/graph.h"
 #include <iomanip> /** std::setprecision **/
 #include <map>
+#include <memory>
 #include <set>
 #include <sstream>
 #include <string>
 #include <set>
 #include <sstream>
 #include <string>
@@ -42,9 +43,9 @@ class TIData {
 public:
   int endpoint                 = 0;
   int send_size                = 0;
 public:
   int endpoint                 = 0;
   int send_size                = 0;
-  std::vector<int>* sendcounts = nullptr;
+  std::shared_ptr<std::vector<int>> sendcounts = nullptr;
   int recv_size                = 0;
   int recv_size                = 0;
-  std::vector<int>* recvcounts = nullptr;
+  std::shared_ptr<std::vector<int>> recvcounts = nullptr;
   std::string send_type        = "";
   std::string recv_type        = "";
 
   std::string send_type        = "";
   std::string recv_type        = "";
 
@@ -68,6 +69,12 @@ public:
   // VarCollTI: gatherV, scatterV, allGatherV, allToAllV (+ reduceScatter out of laziness)
   explicit TIData(std::string name, int root, int send_size, std::vector<int>* sendcounts, int recv_size,
                   std::vector<int>* recvcounts, std::string send_type, std::string recv_type)
   // VarCollTI: gatherV, scatterV, allGatherV, allToAllV (+ reduceScatter out of laziness)
   explicit TIData(std::string name, int root, int send_size, std::vector<int>* sendcounts, int recv_size,
                   std::vector<int>* recvcounts, std::string send_type, std::string recv_type)
+      : TIData(name, root, send_size, std::shared_ptr<std::vector<int>>(sendcounts), recv_size,
+               std::shared_ptr<std::vector<int>>(recvcounts), send_type, recv_type){};
+
+  explicit TIData(std::string name, int root, int send_size, std::shared_ptr<std::vector<int>> sendcounts,
+                  int recv_size, std::shared_ptr<std::vector<int>> recvcounts, std::string send_type,
+                  std::string recv_type)
       : name_(name)
       , endpoint(root)
       , send_size(send_size)
       : name_(name)
       , endpoint(root)
       , send_size(send_size)
@@ -77,11 +84,7 @@ public:
       , send_type(send_type)
       , recv_type(recv_type){};
 
       , send_type(send_type)
       , recv_type(recv_type){};
 
-  virtual ~TIData()
-  {
-    delete sendcounts;
-    delete recvcounts;
-  }
+  virtual ~TIData() {}
 
   std::string getName() { return name_; }
   double getAmount() { return amount_; }
 
   std::string getName() { return name_; }
   double getAmount() { return amount_; }
@@ -151,6 +154,12 @@ public:
   explicit VarCollTIData(std::string name, int root, int send_size, std::vector<int>* sendcounts, int recv_size,
                          std::vector<int>* recvcounts, std::string send_type, std::string recv_type)
       : TIData(name, root, send_size, sendcounts, recv_size, recvcounts, send_type, recv_type){};
   explicit VarCollTIData(std::string name, int root, int send_size, std::vector<int>* sendcounts, int recv_size,
                          std::vector<int>* recvcounts, std::string send_type, std::string recv_type)
       : TIData(name, root, send_size, sendcounts, recv_size, recvcounts, send_type, recv_type){};
+
+  explicit VarCollTIData(std::string name, int root, int send_size, std::shared_ptr<std::vector<int>> sendcounts,
+                         int recv_size, std::shared_ptr<std::vector<int>> recvcounts, std::string send_type,
+                         std::string recv_type)
+      : TIData(name, root, send_size, sendcounts, recv_size, recvcounts, send_type, recv_type){};
+
   std::string print() override
   {
     std::stringstream stream;
   std::string print() override
   {
     std::stringstream stream;