]> SALOME platform Git repositories - modules/med.git/commitdiff
Salome HOME
Memory leak fix on DisjointDEC. union_comm was not freed properly.
authorabn <adrien.bruneton@cea.fr>
Wed, 21 Oct 2015 12:56:11 +0000 (14:56 +0200)
committerabn <adrien.bruneton@cea.fr>
Wed, 21 Oct 2015 13:54:35 +0000 (15:54 +0200)
src/ParaMEDMEM/DisjointDEC.cxx
src/ParaMEDMEM/DisjointDEC.hxx
src/ParaMEDMEM/MPIProcessorGroup.cxx
src/ParaMEDMEM/MPIProcessorGroup.hxx
src/ParaMEDMEMTest/ParaMEDMEMTest_ICoco.cxx

index e8ee329e96f013574d471d7e986c016619942df2..57e67fd2c93721871b57a49232740f8d0e8c55f6 100644 (file)
@@ -72,16 +72,28 @@ namespace ParaMEDMEM
   */
 
 
-  DisjointDEC::DisjointDEC(ProcessorGroup& source_group, ProcessorGroup& target_group):_local_field(0), 
-                                                                                       _source_group(&source_group),
-                                                                                       _target_group(&target_group),
-                                                                                       _owns_field(false),
-                                                                                       _owns_groups(false)
+  DisjointDEC::DisjointDEC(ProcessorGroup& source_group, ProcessorGroup& target_group):
+      _local_field(0),
+      _source_group(&source_group),
+      _target_group(&target_group),
+      _comm_interface(0),
+      _owns_field(false),
+      _owns_groups(false),
+      _union_comm(MPI_COMM_NULL)
   {
     _union_group = source_group.fuse(target_group);  
   }
   
-  DisjointDEC::DisjointDEC(const DisjointDEC& s):DEC(s),_local_field(0),_union_group(0),_source_group(0),_target_group(0),_owns_field(false),_owns_groups(false)
+  DisjointDEC::DisjointDEC(const DisjointDEC& s):
+      DEC(s),
+      _local_field(0),
+      _union_group(0),
+      _source_group(0),
+      _target_group(0),
+      _comm_interface(0),
+      _owns_field(false),
+      _owns_groups(false),
+      _union_comm(MPI_COMM_NULL)
   {
     copyInstance(s);
   }
@@ -111,9 +123,14 @@ namespace ParaMEDMEM
       _union_group = _source_group->fuse(*_target_group);
   }
 
-  DisjointDEC::DisjointDEC(const std::set<int>& source_ids, const std::set<int>& target_ids, const MPI_Comm& world_comm):_local_field(0), 
-                                                                                                                         _owns_field(false),
-                                                                                                                         _owns_groups(true)
+  DisjointDEC::DisjointDEC(const std::set<int>& source_ids,
+                           const std::set<int>& target_ids,
+                           const MPI_Comm& world_comm):
+     _local_field(0),
+     _owns_field(false),
+     _owns_groups(true),
+     _comm_interface(0),
+     _union_comm(MPI_COMM_NULL)
   {
     ParaMEDMEM::CommInterface comm;
     // Create the list of procs including source and target
@@ -129,15 +146,15 @@ namespace ParaMEDMEM
     MPI_Group union_group,world_group;
     comm.commGroup(world_comm,&world_group);
     comm.groupIncl(world_group,union_ids.size(),union_ranks_world,&union_group);
-    MPI_Comm union_comm;
-    comm.commCreate(world_comm,union_group,&union_comm);
+    comm.commCreate(world_comm,union_group,&_union_comm);
     delete[] union_ranks_world;
-
-    if (union_comm==MPI_COMM_NULL)
+    if (_union_comm==MPI_COMM_NULL)
       { // This process is not in union
         _source_group=0;
         _target_group=0;
         _union_group=0;
+        comm.groupFree(&union_group);
+        comm.groupFree(&world_group);
         return;
       }
 
@@ -162,10 +179,11 @@ namespace ParaMEDMEM
     delete [] target_ranks_union;
 
     // Create the MPIProcessorGroups
-    _source_group = new MPIProcessorGroup(comm,source_ids_union,union_comm);
-    _target_group = new MPIProcessorGroup(comm,target_ids_union,union_comm);
+    _source_group = new MPIProcessorGroup(comm,source_ids_union,_union_comm);
+    _target_group = new MPIProcessorGroup(comm,target_ids_union,_union_comm);
     _union_group = _source_group->fuse(*_target_group);
-
+    comm.groupFree(&union_group);
+    comm.groupFree(&world_group);
   }
 
   DisjointDEC::~DisjointDEC()
@@ -191,6 +209,8 @@ namespace ParaMEDMEM
     _target_group=0;
     delete _union_group;
     _union_group=0;
+    if (_union_comm != MPI_COMM_NULL)
+      _comm_interface->commFree(&_union_comm);
   }
 
   void DisjointDEC::setNature(NatureOfField nature)
index 521353f5ed5d5ee4f28ee55ed09873c3671023dc..aec6bb901c1b14faca452d897253437257689555 100644 (file)
@@ -40,7 +40,10 @@ namespace ParaMEDMEM
   class DisjointDEC : public DEC
   {
   public:
-    DisjointDEC():_local_field(0),_union_group(0),_source_group(0),_target_group(0),_owns_field(false),_owns_groups(false) { }
+    DisjointDEC():_local_field(0),_union_group(0),_source_group(0),_target_group(0),
+      _owns_field(false),_owns_groups(false),
+      _comm_interface(0), _union_comm(MPI_COMM_NULL)
+    { }
     DisjointDEC(ProcessorGroup& source_group, ProcessorGroup& target_group);
     DisjointDEC(const DisjointDEC&);
     DisjointDEC &operator=(const DisjointDEC& s);
@@ -80,6 +83,7 @@ namespace ParaMEDMEM
     const CommInterface* _comm_interface;
     bool _owns_field;
     bool _owns_groups;
+    MPI_Comm _union_comm;
   };
 }
 
index 5b7c2405526b2483c4307b487565372ac77f1f05..922f209201bc8f05b9c44960d1cd306bf8e7ca8e 100644 (file)
@@ -85,7 +85,7 @@ namespace ParaMEDMEM
   */
 
   MPIProcessorGroup::MPIProcessorGroup(const CommInterface& interface, set<int> proc_ids, const MPI_Comm& world_comm):
-    ProcessorGroup(interface, proc_ids),_world_comm(world_comm)
+    ProcessorGroup(interface, proc_ids), _world_comm(world_comm)
   {
     updateMPISpecificAttributes();
   }
index d4f25eed4d951f601443b979e3b9eec1a602085e..7c39ed26dfdad4edf539f69afcd7a36b065db8fa 100644 (file)
@@ -51,7 +51,7 @@ namespace ParaMEDMEM
   private:
     void updateMPISpecificAttributes();
   private:
-    const MPI_Comm _world_comm;
+    const MPI_Comm _world_comm;  // just an observer - current instance is not responsible for the management of this comm
     MPI_Group _group;
     MPI_Comm _comm;
   };
index a4624005ddf5f1df505d98397dfe6badd4734b9b..f46c7674982d18c85e6a67934c321aefa68720c5 100644 (file)
@@ -102,7 +102,7 @@ void ParaMEDMEMTest::testICoco1()
   MPI_Comm_size(MPI_COMM_WORLD,&size);
   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
 
-  //the test is meant to run on five processors
+  //the test is meant to run on 2 processors
   if (size !=2) return ;
   
   CommInterface comm;