From: Arnaud Giersch Date: Thu, 5 Dec 2019 15:54:08 +0000 (+0100) Subject: Link Topo and Comm in both directions, and fix memory leak. X-Git-Tag: v3.25~286 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/15f804cfddebc4fe4b305acd1c66487f2405420d Link Topo and Comm in both directions, and fix memory leak. --- diff --git a/src/smpi/include/smpi_comm.hpp b/src/smpi/include/smpi_comm.hpp index dacb7e3bf9..3f57cfa260 100644 --- a/src/smpi/include/smpi_comm.hpp +++ b/src/smpi/include/smpi_comm.hpp @@ -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 diff --git a/src/smpi/include/smpi_topo.hpp b/src/smpi/include/smpi_topo.hpp index a0d55adc99..fe58401bb6 100644 --- a/src/smpi/include/smpi_topo.hpp +++ b/src/smpi/include/smpi_topo.hpp @@ -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 { diff --git a/src/smpi/mpi/smpi_comm.cpp b/src/smpi/mpi/smpi_comm.cpp index 6c2bacc133..d8ca45b523 100644 --- a/src/smpi/mpi/smpi_comm.cpp +++ b/src/smpi/mpi/smpi_comm.cpp @@ -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(); + delete comm->topo_; // there's no use count on topos delete comm; } } diff --git a/src/smpi/mpi/smpi_topo.cpp b/src/smpi/mpi/smpi_topo.cpp index 058b4bd42e..424e3496ea 100644 --- a/src/smpi/mpi/smpi_topo.cpp +++ b/src/smpi/mpi/smpi_topo.cpp @@ -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 ******************************************************************************/