Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Link Topo and Comm in both directions, and fix memory leak.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 5 Dec 2019 15:54:08 +0000 (16:54 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 12 Dec 2019 12:35:45 +0000 (13:35 +0100)
src/smpi/include/smpi_comm.hpp
src/smpi/include/smpi_topo.hpp
src/smpi/mpi/smpi_comm.cpp
src/smpi/mpi/smpi_topo.cpp

index dacb7e3..3f57cfa 100644 (file)
@@ -17,6 +17,7 @@ namespace simgrid{
 namespace smpi{
 
 class Comm : public F2C, public Keyval{
+  friend Topo;
   MPI_Group group_;
   SMPI_Topo_type topoType_;
   MPI_Topology topo_; // to be replaced by an union
index a0d55ad..fe58401 100644 (file)
@@ -15,12 +15,12 @@ namespace simgrid{
 namespace smpi{
 
 class Topo {
-  MPI_Comm comm_;
+  MPI_Comm comm_ = MPI_COMM_NULL;
 
 public:
   virtual ~Topo() = default;
   MPI_Comm getComm() const { return comm_; }
-  void setComm(MPI_Comm comm) { comm_ = comm; }
+  void setComm(MPI_Comm comm);
 };
 
 class Topo_Cart: public Topo {
index 6c2bacc..d8ca45b 100644 (file)
@@ -61,7 +61,6 @@ void Comm::destroy(Comm* comm)
     Comm::destroy(smpi_process()->comm_world());
     return;
   }
-  delete comm->topo_; // there's no use count on topos
   Comm::unref(comm);
 }
 
@@ -334,6 +333,7 @@ void Comm::unref(Comm* comm){
   if(comm->refcount_==0){
     comm->cleanup_smp();
     comm->cleanup_attr<Comm>();
+    delete comm->topo_; // there's no use count on topos
     delete comm;
   }
 }
index 058b4bd..424e349 100644 (file)
@@ -19,6 +19,14 @@ static int getfactors(int num, int *nfators, int **factors);
 namespace simgrid{
 namespace smpi{
 
+void Topo::setComm(MPI_Comm comm)
+{
+  xbt_assert(not comm_);
+  comm_ = comm;
+  if (comm_)
+    comm_->topo_ = this;
+}
+
 /*******************************************************************************
  * Cartesian topologies
  ******************************************************************************/