[cig-commits] r14922 - in short/3D/PyLith/trunk: . libsrc/topology modulesrc/topology playpen/memcheck pylith pylith/apps pylith/materials pylith/problems pylith/topology pylith/utils

knepley at geodynamics.org knepley at geodynamics.org
Thu May 7 18:26:59 PDT 2009


Author: knepley
Date: 2009-05-07 18:26:58 -0700 (Thu, 07 May 2009)
New Revision: 14922

Modified:
   short/3D/PyLith/trunk/TODO
   short/3D/PyLith/trunk/libsrc/topology/Mesh.hh
   short/3D/PyLith/trunk/libsrc/topology/Mesh.icc
   short/3D/PyLith/trunk/libsrc/topology/MeshOps.cc
   short/3D/PyLith/trunk/libsrc/topology/MeshOps.hh
   short/3D/PyLith/trunk/modulesrc/topology/Mesh.i
   short/3D/PyLith/trunk/modulesrc/topology/MeshOps.i
   short/3D/PyLith/trunk/playpen/memcheck/memory_usage.py
   short/3D/PyLith/trunk/pylith/Makefile.am
   short/3D/PyLith/trunk/pylith/apps/PetscApplication.py
   short/3D/PyLith/trunk/pylith/apps/PyLithApp.py
   short/3D/PyLith/trunk/pylith/materials/Material.py
   short/3D/PyLith/trunk/pylith/problems/Problem.py
   short/3D/PyLith/trunk/pylith/topology/Mesh.py
   short/3D/PyLith/trunk/pylith/utils/PetscComponent.py
Log:
Added memory logging


Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO	2009-05-08 00:00:03 UTC (rev 14921)
+++ short/3D/PyLith/trunk/TODO	2009-05-08 01:26:58 UTC (rev 14922)
@@ -19,11 +19,9 @@
 
   DataWriteVTK needs dimensionalizer
 
-    Not working
-      coordinates in output (nondimensional instead of dimensioned)
-        create dimensionalized copy (NAME_dimensioned)
-      solution in output (nondimensional instead of dimensioned)
-      const slip rate in output (slip rate not slip)          
+  Done coordinates in output (nondimensional instead of dimensioned) create dimensionalized copy (NAME_dimensioned)
+  solution in output (nondimensional instead of dimensioned)
+  const slip rate in output (slip rate not slip)          
 
   Add ability to use symmetric matrix, set block size (default is 1)
 
@@ -94,6 +92,18 @@
       Integrator::normalizer()
       DataWriter::normalizer()
 
+      Mesh::coneSize()
+      Mesh::numVertices()
+      Mesh::numCells()
+
+      MeshOps::numMaterialCells()
+
+      PetscApplication.compilePerformanceLog()
+      PetscComponent.compilePerformanceLog()
+      Material.ncells
+      MemoryLogger.logMesh()
+      MemoryLogger.logMaterial()
+
 5. Tidy up
 
     How do we determine the orientation for a fault in a 1-D mesh? We

Modified: short/3D/PyLith/trunk/libsrc/topology/Mesh.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Mesh.hh	2009-05-08 00:00:03 UTC (rev 14921)
+++ short/3D/PyLith/trunk/libsrc/topology/Mesh.hh	2009-05-08 01:26:58 UTC (rev 14922)
@@ -119,6 +119,24 @@
    */
   int dimension(void) const;
 
+  /** Get representative cone size for mesh.
+   *
+   * @returns Representative cone size for mesh.
+   */
+  int coneSize(void) const;
+  
+  /** Get number of vertices in mesh.
+   *
+   * @returns Number of vertices in mesh.
+   */
+  int numVertices(void) const;
+  
+  /** Get number of cells in mesh.
+   *
+   * @returns Number of cells in mesh.
+   */
+  int numCells(void) const;
+
   /** Set MPI communicator associated with mesh.
    *
    * @param value MPI communicator.

Modified: short/3D/PyLith/trunk/libsrc/topology/Mesh.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Mesh.icc	2009-05-08 00:00:03 UTC (rev 14921)
+++ short/3D/PyLith/trunk/libsrc/topology/Mesh.icc	2009-05-08 01:26:58 UTC (rev 14922)
@@ -58,6 +58,27 @@
   return (!_mesh.isNull()) ? _mesh->getDimension() : 0;
 }
 
+// Get representative cone size for mesh.
+inline
+int
+pylith::topology::Mesh::coneSize(void) const {
+  return (!_mesh.isNull()) ? _mesh->getSieve()->getConeSize(*_mesh->heightStratum(0)->begin()) : 0;
+}
+
+// Get number of vertices in mesh.
+inline
+int
+pylith::topology::Mesh::numVertices(void) const {
+  return (!_mesh.isNull()) ? _mesh->depthStratum(0)->size() : 0;
+}
+
+// Get number of cells in mesh.
+inline
+int
+pylith::topology::Mesh::numCells(void) const {
+  return (!_mesh.isNull()) ? _mesh->heightStratum(0)->size() : 0;
+}
+
 // Set MPI communicator associated with mesh.
 inline
 void

Modified: short/3D/PyLith/trunk/libsrc/topology/MeshOps.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/MeshOps.cc	2009-05-08 00:00:03 UTC (rev 14921)
+++ short/3D/PyLith/trunk/libsrc/topology/MeshOps.cc	2009-05-08 01:26:58 UTC (rev 14922)
@@ -26,6 +26,11 @@
 
 
 // ----------------------------------------------------------------------
+int
+pylith::topology::MeshOps::numMaterialCells(const Mesh& mesh, int materialId)
+{ // numMaterialCells
+  return mesh.sieveMesh()->getLabelStratum("material-id", materialId)->size();
+} // numMaterialCells
 void
 pylith::topology::MeshOps::checkMaterialIds(const Mesh& mesh,
 					    int* const materialIds,

Modified: short/3D/PyLith/trunk/libsrc/topology/MeshOps.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/MeshOps.hh	2009-05-08 00:00:03 UTC (rev 14921)
+++ short/3D/PyLith/trunk/libsrc/topology/MeshOps.hh	2009-05-08 01:26:58 UTC (rev 14922)
@@ -43,7 +43,10 @@
 			int* const materialIds,
 			const int numMaterials);
 
+  static
+  int numMaterialCells(const Mesh& mesh, int materialId);
 
+
 // NOT IMPLEMENTED //////////////////////////////////////////////////////
 private :
 

Modified: short/3D/PyLith/trunk/modulesrc/topology/Mesh.i
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/Mesh.i	2009-05-08 00:00:03 UTC (rev 14921)
+++ short/3D/PyLith/trunk/modulesrc/topology/Mesh.i	2009-05-08 01:26:58 UTC (rev 14922)
@@ -75,7 +75,25 @@
        * @returns Dimension of mesh.
        */
       int dimension(void) const;
+
+      /** Get representative cone size of mesh.
+       *
+       * @returns Representative cone size of mesh.
+       */
+      int coneSize(void) const;
       
+      /** Get number of vertices in mesh.
+       *
+       * @returns Number of vertices in mesh.
+       */
+      int numVertices(void) const;
+      
+      /** Get number of cells in mesh.
+       *
+       * @returns Number of cells in mesh.
+       */
+      int numCells(void) const;
+      
       /** Set MPI communicator associated with mesh.
        *
        * @param value MPI communicator.

Modified: short/3D/PyLith/trunk/modulesrc/topology/MeshOps.i
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/MeshOps.i	2009-05-08 00:00:03 UTC (rev 14921)
+++ short/3D/PyLith/trunk/modulesrc/topology/MeshOps.i	2009-05-08 01:26:58 UTC (rev 14922)
@@ -38,5 +38,11 @@
 %}
 %clear(int* const materialIds, const int numMaterials);
 
+%inline %{
+  int
+  MeshOps_numMaterialCells(const pylith::topology::Mesh& mesh, int materialId) {
+    pylith::topology::MeshOps::numMaterialCells(mesh,materialId);
+  } // numMaterialCells
+%}
 
 // End of file 

Modified: short/3D/PyLith/trunk/playpen/memcheck/memory_usage.py
===================================================================
--- short/3D/PyLith/trunk/playpen/memcheck/memory_usage.py	2009-05-08 00:00:03 UTC (rev 14921)
+++ short/3D/PyLith/trunk/playpen/memcheck/memory_usage.py	2009-05-08 01:26:58 UTC (rev 14922)
@@ -45,7 +45,8 @@
 
 # ----------------------------------------------------------------------
 # Mesh class
-class Mesh(Component):
+import pylith.perf.Mesh
+class Mesh(Component,pylith.perf.Mesh.Mesh):
   """
   Mesh object for holding mesh size information.
   """
@@ -92,67 +93,7 @@
     Constructor.
     """
     Component.__init__(self, name)
-    self.cellType = None
-    self.nvertices = 0
-    self.ncells = 0
-    self.coneSize = 0
-    self.dimension = 0
     return
-
-
-  def initialize(self):
-    """
-    Initialize application.
-    """
-    coneSize = {'tri3': 3,
-                'quad4': 4,
-                'tet4': 4,
-                'hex8': 8,
-                }
-    dimension = {'tri3': 2,
-                 'quad4': 2,
-                 'tet4': 3,
-                 'hex8': 3,
-                 }
-    
-    try:
-      self.coneSize = coneSize[self.cellType]
-      self.dimension = dimension[self.cellType]
-    except:
-      raise ValueError("Unknown cell type '%'." % self.cellType)
-    return
-
-
-  def tabulate(self):
-    """
-    Tabulate memory use.
-    """
-    memory = {'mesh': 0,
-              'stratification': 0,
-              'coordinates': 0,
-              'materials': 0}
-    ncells = self.ncells
-    nvertices = self.nvertices
-    coneSize = self.coneSize
-    dimension = self.dimension
-
-    # mesh
-    nbytes = sizeInt * ( 2 * (coneSize*ncells + nvertices + ncells) + \
-                         coneSize*ncells )
-    memory['mesh'] = nbytes
-
-    # stratification
-    nbytes = 2 * sizeArrow * (nvertices + ncells)
-    memory['stratification'] = nbytes
-
-    # coordinates
-    nbytes = sizeDouble * dimension * nvertices
-    memory['coordinates'] = nbytes
-
-    # materials
-    nbytes = 2 * sizeArrow * ncells
-    memory['materials'] = nbytes
-    return memory
   
 
   # PRIVATE METHODS ////////////////////////////////////////////////////
@@ -162,10 +103,8 @@
     Setup members using inventory.
     """
     Component._configure(self)
-    self.cellType = self.inventory.cellType
-    self.nvertices = self.inventory.nvertices
-    self.ncells = self.inventory.ncells
-
+    dim, coneSize = pylith.perf.Mesh.Mesh.cellTypeInfo(self.inventory.cellType)
+    pylith.perf.Mesh.Mesh.__init__(self, dim, coneSize, self.inventory.nvertices, self.inventory.ncells)
     return
 
 
@@ -236,7 +175,8 @@
 
 # ----------------------------------------------------------------------
 # Material class
-class Material(Component):
+import pylith.perf.Material
+class Material(Component,pylith.perf.Material.Material):
   """
   Mesh object for holding material size information.
   """
@@ -274,16 +214,7 @@
     Constructor.
     """
     Component.__init__(self, name)
-    self.size = 0
     return
-
-
-  def tabulate(self, mesh):
-    """
-    Tabulate memory use.
-    """
-    nbytes = 2 * sizeArrow * self.size
-    return nbytes
   
 
   # PRIVATE METHODS ////////////////////////////////////////////////////
@@ -293,8 +224,7 @@
     Setup members using inventory.
     """
     Component._configure(self)
-    self.label = self.inventory.label
-    self.size = self.inventory.size
+    pylith.perf.Material.Material.__init__(self, self.inventory.label, self.inventory.size)
     return
 
 
@@ -438,7 +368,7 @@
     # materials
     memory['materials'] = {}
     for material in self.materials.components():
-      nbytes = material.tabulate(self.mesh)
+      nbytes = material.tabulate()
       total += nbytes
       memory['materials'][material.label] = nbytes
 

Modified: short/3D/PyLith/trunk/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/pylith/Makefile.am	2009-05-08 00:00:03 UTC (rev 14921)
+++ short/3D/PyLith/trunk/pylith/Makefile.am	2009-05-08 01:26:58 UTC (rev 14922)
@@ -83,6 +83,12 @@
 	meshio/VertexFilterVecNormSubMesh.py \
 	mpi/__init__.py \
 	mpi/Communicator.py \
+	perf/__init__.py \
+	perf/Memory.py \
+	perf/Logger.py \
+	perf/MemoryLogger.py \
+	perf/Mesh.py \
+	perf/Material.py \
 	problems/__init__.py \
 	problems/Explicit.py \
 	problems/Formulation.py \

Modified: short/3D/PyLith/trunk/pylith/apps/PetscApplication.py
===================================================================
--- short/3D/PyLith/trunk/pylith/apps/PetscApplication.py	2009-05-08 00:00:03 UTC (rev 14921)
+++ short/3D/PyLith/trunk/pylith/apps/PetscApplication.py	2009-05-08 01:26:58 UTC (rev 14922)
@@ -59,6 +59,19 @@
     return
   
 
+  def compilePerformanceLog(self):
+    """
+    Compile performance and memory information.
+    """
+    from pylith.utils.PetscComponent import PetscComponent
+    for component in self.components():
+      if isinstance(component, PetscComponent):
+        component.compilePerformanceLog()
+        if hasattr(component, 'perfLogger'):
+          self.perfLogger.join(component.perfLogger)
+    return
+
+
   def cleanup(self):
     """
     Deallocate data structures.

Modified: short/3D/PyLith/trunk/pylith/apps/PyLithApp.py
===================================================================
--- short/3D/PyLith/trunk/pylith/apps/PyLithApp.py	2009-05-08 00:00:03 UTC (rev 14921)
+++ short/3D/PyLith/trunk/pylith/apps/PyLithApp.py	2009-05-08 01:26:58 UTC (rev 14922)
@@ -52,7 +52,12 @@
                                       factory=TimeDependent)
     problem.meta['tip'] = "Computational problem to solve."
 
+    from pylith.perf.MemoryLogger import MemoryLogger
+    perfLogger = pyre.inventory.facility("perf_logger", family="perf_logger",
+                                         factory=MemoryLogger)
+    perfLogger.meta['tip'] = "Performance and memory logging."
 
+
   # PUBLIC METHODS /////////////////////////////////////////////////////
 
   def __init__(self, name="pylithapp"):
@@ -81,6 +86,7 @@
     if "interfaces" in dir(self.problem):
       interfaces = self.problem.interfaces.components()
     mesh = self.mesher.create(self.problem.normalizer, interfaces)
+    self.perfLogger.logMesh("Meshing", mesh)
     del interfaces
     del self.mesher
     self._debug.log(resourceUsageString())
@@ -112,6 +118,8 @@
     del mesh
     del self.problem
 
+    self.compilePerformanceLog()
+    self.perfLogger.show()
     self._logger.eventEnd("PyLith main")
     return
   
@@ -125,6 +133,7 @@
     PetscApplication._configure(self)
     self.mesher = self.inventory.mesher
     self.problem = self.inventory.problem
+    self.perfLogger = self.inventory.perfLogger
 
     import journal
     self._debug = journal.debug(self.name)

Modified: short/3D/PyLith/trunk/pylith/materials/Material.py
===================================================================
--- short/3D/PyLith/trunk/pylith/materials/Material.py	2009-05-08 00:00:03 UTC (rev 14921)
+++ short/3D/PyLith/trunk/pylith/materials/Material.py	2009-05-08 01:26:58 UTC (rev 14922)
@@ -104,6 +104,8 @@
     self._setupLogging()
     self.mesh = mesh
     self.quadrature.preinitialize(self.mesh.coordsys().spaceDim())
+    from pylith.topology.topology import MeshOps_numMaterialCells
+    self.ncells = MeshOps_numMaterialCells(mesh, self.id())
     return
 
 

Modified: short/3D/PyLith/trunk/pylith/problems/Problem.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/Problem.py	2009-05-08 00:00:03 UTC (rev 14921)
+++ short/3D/PyLith/trunk/pylith/problems/Problem.py	2009-05-08 01:26:58 UTC (rev 14922)
@@ -116,6 +116,11 @@
                                           family="spatial_database")
     gravityField.meta['tip'] = "Database used for gravity field."
 
+    from pylith.perf.MemoryLogger import MemoryLogger
+    perfLogger = pyre.inventory.facility("perf_logger", family="perf_logger",
+                                         factory=MemoryLogger)
+    perfLogger.meta['tip'] = "Performance and memory logging."
+
   
 
   # PUBLIC METHODS /////////////////////////////////////////////////////
@@ -166,6 +171,7 @@
             "Material id values must be unique." % \
             (material.label(), materialIds[material.id()], material.id())
       materialIds[material.id()] = material.label()
+      self.perfLogger.logMaterial("Problem Verification", material)
     
     for interface in self.interfaces.components():
       if interface.id() in materialIds.keys():
@@ -233,6 +239,7 @@
       self.gravityField = self.inventory.gravityField
     else:
       self.gravityField = None
+    self.perfLogger = self.inventory.perfLogger
     return
 
 

Modified: short/3D/PyLith/trunk/pylith/topology/Mesh.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/Mesh.py	2009-05-08 00:00:03 UTC (rev 14921)
+++ short/3D/PyLith/trunk/pylith/topology/Mesh.py	2009-05-08 01:26:58 UTC (rev 14922)
@@ -62,6 +62,34 @@
     from topology import MeshOps_checkMaterialIds
     MeshOps_checkMaterialIds(self, materialIds)
     return
+
+
+  def dimension(self):
+    """
+    Return the topological mesh dimension
+    """
+    return ModuleMesh.dimension(self)
+
+
+  def coneSize(self):
+    """
+    Return the representative cone size, or number of vertices on a cell
+    """
+    return ModuleMesh.coneSize(self)
+
+
+  def numVertices(self):
+    """
+    Return the number of vertices.
+    """
+    return ModuleMesh.numVertices(self)
+
+
+  def numCells(self):
+    """
+    Return the number of cells.
+    """
+    return ModuleMesh.numCells(self)
   
 
 # End of file

Modified: short/3D/PyLith/trunk/pylith/utils/PetscComponent.py
===================================================================
--- short/3D/PyLith/trunk/pylith/utils/PetscComponent.py	2009-05-08 00:00:03 UTC (rev 14921)
+++ short/3D/PyLith/trunk/pylith/utils/PetscComponent.py	2009-05-08 01:26:58 UTC (rev 14922)
@@ -32,8 +32,20 @@
     """
     Component.__init__(self, name, facility)
     return
+  
 
+  def compilePerformanceLog(self):
+    """
+    Compile performance and memory information.
+    """
+    for component in self.components():
+      if isinstance(component, PetscComponent):
+        component.compilePerformanceLog()
+        if hasattr(component, 'perfLogger'):
+          self.perfLogger.join(component.perfLogger)
+    return
 
+
   def cleanup(self):
     """
     Deallocate data structures.



More information about the CIG-COMMITS mailing list