[cig-commits] r17972 - in short/3D/PyLith/trunk: libsrc/topology pylith/perf pylith/topology tests/topology

brad at geodynamics.org brad at geodynamics.org
Thu Feb 24 13:25:33 PST 2011


Author: brad
Date: 2011-02-24 13:25:33 -0800 (Thu, 24 Feb 2011)
New Revision: 17972

Modified:
   short/3D/PyLith/trunk/libsrc/topology/Mesh.cc
   short/3D/PyLith/trunk/libsrc/topology/MeshOps.cc
   short/3D/PyLith/trunk/pylith/perf/MemoryLogger.py
   short/3D/PyLith/trunk/pylith/topology/RefineUniform.py
   short/3D/PyLith/trunk/tests/topology/test_meshmem.py
Log:
Improve memory logging and output. Allow memory logging of deallocated meshes.

Modified: short/3D/PyLith/trunk/libsrc/topology/Mesh.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Mesh.cc	2011-02-24 17:22:51 UTC (rev 17971)
+++ short/3D/PyLith/trunk/libsrc/topology/Mesh.cc	2011-02-24 21:25:33 UTC (rev 17972)
@@ -65,7 +65,7 @@
 pylith::topology::Mesh::deallocate(void)
 { // deallocate
   delete _coordsys; _coordsys = 0;
-  _mesh.destroy(); // check refCnt, ALE::setVerbosity()
+  _mesh.destroy();
 } // deallocate
   
 // ----------------------------------------------------------------------
@@ -155,31 +155,37 @@
 pylith::topology::Mesh::groups(int* numNames, 
 			       char*** names) const
 { // groups
-  assert(!_mesh.isNull());
-  const ALE::Obj<std::set<std::string> >& sectionNames =  
-    _mesh->getIntSections();
-  assert(!sectionNames.isNull());
-  
-  *numNames = sectionNames->size();
-  *names = new char*[sectionNames->size()];
-  assert(*names);
+  if (!_mesh.isNull()) {
+    assert(!_mesh.isNull());
+    const ALE::Obj<std::set<std::string> >& sectionNames =  
+      _mesh->getIntSections();
+    assert(!sectionNames.isNull());
+    
+    *numNames = sectionNames->size();
+    *names = new char*[sectionNames->size()];
+    assert(*names);
+    
+    const std::set<std::string>::const_iterator namesEnd = sectionNames->end();
+    int i = 0;
+    for (std::set<std::string>::const_iterator n_iter=sectionNames->begin(); 
+	 n_iter != namesEnd;
+	 ++n_iter) {
+      const char len = n_iter->length();
+      char* newName = 0;
+      if (len > 0) {
+	newName = new char[len+1];
+	strncpy(newName, n_iter->c_str(), len+1);
+      } else {
+	newName = new char[1];
+	newName[0] ='\0';
+      } // if/else
+      (*names)[i++] = newName;
+    } // for
 
-  const std::set<std::string>::const_iterator namesEnd = sectionNames->end();
-  int i = 0;
-  for (std::set<std::string>::const_iterator n_iter=sectionNames->begin(); 
-       n_iter != namesEnd;
-       ++n_iter) {
-    const char len = n_iter->length();
-    char* newName = 0;
-    if (len > 0) {
-      newName = new char[len+1];
-      strncpy(newName, n_iter->c_str(), len+1);
-    } else {
-      newName = new char[1];
-      newName[0] ='\0';
-    } // if/else
-    (*names)[i++] = newName;
-  } // for
+  } else {
+    *numNames = 0;
+    *names = 0;
+  } // if/else
 } // groups
 
 // ----------------------------------------------------------------------

Modified: short/3D/PyLith/trunk/libsrc/topology/MeshOps.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/MeshOps.cc	2011-02-24 17:22:51 UTC (rev 17971)
+++ short/3D/PyLith/trunk/libsrc/topology/MeshOps.cc	2011-02-24 21:25:33 UTC (rev 17972)
@@ -35,8 +35,18 @@
 int
 pylith::topology::MeshOps::numMaterialCells(const Mesh& mesh, int materialId)
 { // numMaterialCells
-  return mesh.sieveMesh()->getLabelStratum("material-id", materialId)->size();
+  int ncells = 0;
+
+  const ALE::Obj<Mesh::SieveMesh>& sieveMesh = mesh.sieveMesh();
+  if (!sieveMesh.isNull()) {
+    const ALE::Obj<Mesh::SieveMesh::label_sequence>& cells = 
+      sieveMesh->getLabelStratum("material-id", materialId);
+    if (!cells.isNull())
+      ncells = cells->size();
+  } // if
 } // numMaterialCells
+
+
 void
 pylith::topology::MeshOps::checkMaterialIds(const Mesh& mesh,
 					    int* const materialIds,

Modified: short/3D/PyLith/trunk/pylith/perf/MemoryLogger.py
===================================================================
--- short/3D/PyLith/trunk/pylith/perf/MemoryLogger.py	2011-02-24 17:22:51 UTC (rev 17971)
+++ short/3D/PyLith/trunk/pylith/perf/MemoryLogger.py	2011-02-24 21:25:33 UTC (rev 17972)
@@ -64,13 +64,14 @@
     return
 
 
-  def logMesh(self, stage, mesh):
+  def logMesh(self, stage, mesh, reset=True):
     """
     Read mesh parameters to determine memory from our model.
     """
     import pylith.perf.Mesh
 
-    if not stage in self.memory: self.memory[stage] = {}
+    if not stage in self.memory or reset:
+      self.memory[stage] = {}
     meshModel = pylith.perf.Mesh.Mesh(mesh.dimension(), mesh.coneSize(), 
                                       mesh.numVertices(), mesh.numCells())
     meshModel.tabulate(self.memory[stage])
@@ -256,6 +257,7 @@
         mem -= logger.getDeallocationTotal()
     if mem == 0:
       mem = codeTotal
+    output.append(self.prefix(indent)+'-'*(60-indent))
     output.append(self.memLine('Model', 'Total', total, indent))
     output.append(self.memLine('Code',  'Total', mem, indent))
     if mem:

Modified: short/3D/PyLith/trunk/pylith/topology/RefineUniform.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/RefineUniform.py	2011-02-24 17:22:51 UTC (rev 17971)
+++ short/3D/PyLith/trunk/pylith/topology/RefineUniform.py	2011-02-24 21:25:33 UTC (rev 17972)
@@ -68,7 +68,12 @@
     newMesh.coordsys(mesh.coordsys())
     ModuleRefineUniform.refine(self, newMesh, mesh, self.levels)
     if not newMesh == mesh:
+      from pylith.utils.petsc import MemoryLogger
+      sieveLogger =  MemoryLogger.singleton()
+
+      sieveLogger.stagePush("Mesh")      
       mesh.deallocate()
+      sieveLogger.stagePop()
 
     self._eventLogger.eventEnd(logEvent)
     return newMesh

Modified: short/3D/PyLith/trunk/tests/topology/test_meshmem.py
===================================================================
--- short/3D/PyLith/trunk/tests/topology/test_meshmem.py	2011-02-24 17:22:51 UTC (rev 17971)
+++ short/3D/PyLith/trunk/tests/topology/test_meshmem.py	2011-02-24 21:25:33 UTC (rev 17972)
@@ -66,6 +66,10 @@
     from pylith.perf.MemoryLogger import MemoryLogger
     self.logger = MemoryLogger()
     self.logger._configure()
+
+    from pylith.utils.petsc import MemoryLogger
+    sieveLogger =  MemoryLogger.singleton()
+
     from pylith.topology.topology import MeshOps_numMaterialCells
 
     from pylith.mpi.Communicator import petsc_comm_world
@@ -95,9 +99,8 @@
     self.logger.logMaterial("Mesh", material)
     
 
-    self._showStatus("After reading mesh")
+    self._showStatus("After reading mesh")    
 
-
     # ------------------------------------------------------------
     # Reorder mesh
     from pylith.topology.ReverseCuthillMcKee import ReverseCuthillMcKee
@@ -110,6 +113,7 @@
 
     self._showStatus("After reordering mesh")
 
+
     # ------------------------------------------------------------
     # Distribute mesh
     if comm.size > 1:
@@ -142,12 +146,13 @@
 
     self._showStatus("After refining mesh")
 
-    if mesh != rmesh:
-      mesh.deallocate()
-    mesh = rmesh
-    self._showStatus("After refining mesh and deallocation")
-      
+    self.logger.logMesh("Mesh", mesh)
+    material.ncells = MeshOps_numMaterialCells(mesh, material.id())
+    self.logger.logMaterial("Mesh", material)
 
+    self._showStatus("After deallocating original mesh")
+
+
     return
 
 



More information about the CIG-COMMITS mailing list