[cig-commits] r14937 - in short/3D/PyLith/trunk: . libsrc/meshio playpen/memcheck pylith/apps pylith/perf

knepley at geodynamics.org knepley at geodynamics.org
Fri May 8 19:14:34 PDT 2009


Author: knepley
Date: 2009-05-08 19:14:34 -0700 (Fri, 08 May 2009)
New Revision: 14937

Modified:
   short/3D/PyLith/trunk/TODO
   short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc
   short/3D/PyLith/trunk/playpen/memcheck/memoryUsage.tex
   short/3D/PyLith/trunk/pylith/apps/PyLithApp.py
   short/3D/PyLith/trunk/pylith/perf/Material.py
   short/3D/PyLith/trunk/pylith/perf/MemoryLogger.py
   short/3D/PyLith/trunk/pylith/perf/Mesh.py
   short/3D/PyLith/trunk/pylith/perf/VertexGroup.py
Log:
More memory logging


Modified: short/3D/PyLith/trunk/TODO
===================================================================
--- short/3D/PyLith/trunk/TODO	2009-05-09 00:38:09 UTC (rev 14936)
+++ short/3D/PyLith/trunk/TODO	2009-05-09 02:14:34 UTC (rev 14937)
@@ -148,6 +148,8 @@
 6. Memory model [Matt]
    playpen/memcheck/*
 
+   Must add nested stages so that logging totals are correct
+
 7. 2-D Plane strain Maxwell viscoelastic rheology [Charles]
 
 8. 2-D Plane strain Generalized Maxwell viscoelastic rheology [Charles]

Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc	2009-05-09 00:38:09 UTC (rev 14936)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc	2009-05-09 02:14:34 UTC (rev 14937)
@@ -309,6 +309,8 @@
   assert(!sieveMesh.isNull());
 
   ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
+  logger.setDebug(1);
+  std::cout << "Building Vertex Group " << name << std::endl;
   logger.stagePush("VertexGroups");
   const ALE::Obj<IntSection>& groupField = sieveMesh->getIntSection(name);
   assert(!groupField.isNull());
@@ -328,6 +330,7 @@
   } // if/else
   sieveMesh->allocate(groupField);
   logger.stagePop();
+  logger.setDebug(0);
 
 #if defined(ALE_MEM_LOGGING)
   std::cout

Modified: short/3D/PyLith/trunk/playpen/memcheck/memoryUsage.tex
===================================================================
--- short/3D/PyLith/trunk/playpen/memcheck/memoryUsage.tex	2009-05-09 00:38:09 UTC (rev 14936)
+++ short/3D/PyLith/trunk/playpen/memcheck/memoryUsage.tex	2009-05-09 02:14:34 UTC (rev 14937)
@@ -18,9 +18,10 @@
 where $A$ is the size of an arrow in bytes. Materials are also stored this way, but in PyLith are mapped only to cells.
 
     For an IGeneralSection, the data take up only the minimum size. The atlas is an IUniformSection so that the data
-take up $2 max(V, C)$ integers, and its atlas is an IConstantSection. Thus, for a group we expect
+take up $2 max(V, C)$ integers, and its atlas is an IConstantSection. We also have a BC ISection, which has an
+IUniformSection Atlas. Thus, for a group we expect
 $$
-  2 max(V, C) + max(V, C)
+  2 max(V, C) + 2 max(V, C) + max(V, C)
 $$
 
 \subsection{Savings}

Modified: short/3D/PyLith/trunk/pylith/apps/PyLithApp.py
===================================================================
--- short/3D/PyLith/trunk/pylith/apps/PyLithApp.py	2009-05-09 00:38:09 UTC (rev 14936)
+++ short/3D/PyLith/trunk/pylith/apps/PyLithApp.py	2009-05-09 02:14:34 UTC (rev 14937)
@@ -120,7 +120,6 @@
 
     self.compilePerformanceLog()
     self.perfLogger.show()
-    self.perfLogger.showNew()
     self._logger.eventEnd("PyLith main")
     return
   

Modified: short/3D/PyLith/trunk/pylith/perf/Material.py
===================================================================
--- short/3D/PyLith/trunk/pylith/perf/Material.py	2009-05-09 00:38:09 UTC (rev 14936)
+++ short/3D/PyLith/trunk/pylith/perf/Material.py	2009-05-09 02:14:34 UTC (rev 14937)
@@ -14,18 +14,12 @@
     self.ncells = numCells
     return
 
-  def tabulateNew(self, memDict):
+  def tabulate(self, memDict):
     """
     Tabulate memory use.
     """
-    memDict[self.label] = 2 * self.sizeArrow * self.ncells
+    memDict[self.label] = self.sizeArrow * self.ncells
     return
 
-  def tabulate(self):
-    """
-    Tabulate memory use.
-    """
-    return 2 * self.sizeArrow * self.ncells
-
 if __name__ == '__main__':
   print 'Memory:',Material('rock', 35).tabulate()

Modified: short/3D/PyLith/trunk/pylith/perf/MemoryLogger.py
===================================================================
--- short/3D/PyLith/trunk/pylith/perf/MemoryLogger.py	2009-05-09 00:38:09 UTC (rev 14936)
+++ short/3D/PyLith/trunk/pylith/perf/MemoryLogger.py	2009-05-09 02:14:34 UTC (rev 14937)
@@ -51,10 +51,8 @@
     Constructor.
     """
     Logger.__init__(self, name)
-    self.megabyte     = float(2**20)
-    self.memoryNew    = {}
-    self.materials    = {}
-    self.vertexGroups = {}
+    self.megabyte = float(2**20)
+    self.memory   = {}
     return
 
   def logMesh(self, stage, mesh):
@@ -62,27 +60,25 @@
     Read mesh parameters to determine memory from our model.
     """
     import pylith.perf.Mesh
-    self.mesh = pylith.perf.Mesh.Mesh(mesh.dimension(), mesh.coneSize(), mesh.numVertices(), mesh.numCells())
-    if not 'Mesh' in self.memoryNew: self.memoryNew['Mesh'] = {}
-    self.mesh.tabulateNew(self.memoryNew['Mesh'])
+
+    if not 'Mesh' in self.memory: self.memory['Mesh'] = {}
+    meshModel = pylith.perf.Mesh.Mesh(mesh.dimension(), mesh.coneSize(), mesh.numVertices(), mesh.numCells())
+    meshModel.tabulate(self.memory['Mesh'])
     for group, nvertices in mesh.groupSizes():
-      self.logVertexGroup(stage, group, nvertices)
-    if self.verbose:
-      self.tabulate()
-      self.show()
+      self.logVertexGroup(stage, group, nvertices, mesh.numVertices())
+    if self.verbose: self.show()
     return
 
-  def logVertexGroup(self, stage, label, nvertices):
+  def logVertexGroup(self, stage, label, nvertices, nMeshVertices):
     """
     Read vertex group parameters to determine memory from our model.
     """
     import pylith.perf.VertexGroup
-    self.vertexGroups[label] = pylith.perf.VertexGroup.VertexGroup(label, nvertices)
-    if not 'VertexGroups' in self.memoryNew: self.memoryNew['VertexGroups'] = {}
-    self.vertexGroups[label].tabulateNew(self.memoryNew['VertexGroups'])
-    if self.verbose:
-      self.tabulate()
-      self.show()
+
+    if not 'VertexGroups' in self.memory: self.memory['VertexGroups'] = {}
+    group = pylith.perf.VertexGroup.VertexGroup(label, nvertices, nMeshVertices)
+    group.tabulate(self.memory['VertexGroups'])
+    if self.verbose: self.show()
     return
 
   def logMaterial(self, stage, material):
@@ -90,42 +86,11 @@
     Read material parameters to determine memory from our model.
     """
     import pylith.perf.Material
-    self.materials[material.id()] = pylith.perf.Material.Material(material.label(), material.ncells)
-    if not 'Materials' in self.memoryNew: self.memoryNew['Materials'] = {}
-    self.materials[material.id()].tabulateNew(self.memoryNew['Materials'])
-    if self.verbose:
-      self.tabulate()
-      self.show()
-    return
 
-  def tabulate(self):
-    """
-    Tabulate expected memory usage.
-    """
-    total = 0
-    memory = {}
-    # mesh
-    if hasattr(self, 'mesh'):
-      info = self.mesh.tabulate()
-      memory['mesh'] = info
-      total += sum(info.values())
-    # groups
-    if hasattr(self, 'vertexGroups'):
-      memory['groups'] = {}
-      for label,group in self.vertexGroups.iteritems():
-        nbytes = group.tabulate()
-        total += nbytes
-        memory['groups'][label] = nbytes
-    # materials
-    if hasattr(self, 'materials'):
-      memory['materials'] = {}
-      for id, material in self.materials.iteritems():
-        nbytes = material.tabulate()
-        total += nbytes
-        memory['materials'][material.label] = nbytes
-    # Total
-    memory['total'] = total
-    self.memory = memory
+    if not 'Materials' in self.memory: self.memory['Materials'] = {}
+    material = pylith.perf.Material.Material(material.label(), material.ncells)
+    material.tabulate(self.memory['Materials'])
+    if self.verbose: self.show()
     return
 
   def mergeMemDict(self, memDictTarget, memDictSource):
@@ -140,48 +105,11 @@
         memDictTarget[key] += memDictSource[key]
     return
 
-  def joinNew(self, logger):
-    """
-    Incorporate information from another logger.
-    """
-    self.mergeMemDict(self.memoryNew, logger.memoryNew)
-    return
-
   def join(self, logger):
     """
     Incorporate information from another logger.
     """
-    self.joinNew(logger)
-    # mesh
-    memory = logger.memory
-    if 'mesh' in memory:
-      if not 'mesh' in self.memory:
-        self.memory['mesh'] = memory['mesh']
-      else:
-        for key in self.memory['mesh']:
-          self.memory['mesh'][key] += memory['mesh'][key]
-    # groups
-    if 'groups' in memory:
-      if not 'groups' in self.memory:
-        self.memory['groups'] = memory['groups']
-      else:
-        for key in memory['groups']:
-          if not key in self.memory['groups']:
-            self.memory['groups'][key]  = memory['groups'][key]
-          else:
-            self.memory['groups'][key] += memory['groups'][key]
-    # materials
-    if 'materials' in memory:
-      if not 'materials' in self.memory:
-        self.memory['materials'] = memory['materials']
-      else:
-        for key in memory['materials']:
-          if not key in self.memory['materials']:
-            self.memory['materials'][key]  = memory['materials'][key]
-          else:
-            self.memory['materials'][key] += memory['materials'][key]
-    # Total
-    self.memory['total'] += memory['total']
+    self.mergeMemDict(self.memory, logger.memory)
     return
 
   def prefix(self, indent):
@@ -226,47 +154,15 @@
     output.append('%sPercentage memory modeled: %.2f%%' % (self.prefix(indent), total*100.0/mem))
     return output, total, codeTotal
 
-  def showNew(self):
+  def show(self):
     """
     Print memory usage.
     """
     output = ["MEMORY USAGE"]
-    output.extend(self.processMemDict(self.memoryNew)[0])
+    output.extend(self.processMemDict(self.memory)[0])
     print '\n'.join(output)
     return
 
-  def show(self):
-    """
-    Print memory usage.
-    """
-    from pylith.utils.petsc import MemoryLogger
-    logger   = MemoryLogger.singleton()
-    megabyte = self.megabyte
-    print "MEMORY USAGE"
-    if 'mesh' in self.memory:
-      print "  Finite-element mesh"
-      memory = self.memory['mesh']
-      print "    Mesh:           %d bytes (%.3f MB)" % (memory['mesh'], memory['mesh'] / megabyte)
-      print "    Stratification: %d bytes (%.3f MB)" % (memory['stratification'], memory['stratification'] / megabyte)
-      print "    Coordinates:    %d bytes (%.3f MB)" % (memory['coordinates'], memory['coordinates'] / megabyte)
-      print "    Materials:      %d bytes (%.3f MB)" % (memory['materials'], memory['materials'] / megabyte)
-      stage  = "MeshCreation"
-      mem    = logger.getAllocationTotal(stage) - logger.getDeallocationTotal(stage)
-      print "    Mesh (Code):    %d bytes (%.3f MB)" % (mem, mem / megabyte)
-    if 'groups' in self.memory:
-      print "    Groups"
-      for (label, nbytes) in self.memory['groups'].items():
-        print "      %s: %d bytes (%.3f MB)" % (label, nbytes, nbytes / megabyte)
-    if 'materials' in self.memory:
-      print "  Materials"
-      for (label, nbytes) in self.memory['materials'].items():
-        print "    %s: %d bytes (%.3f MB)" % (label, nbytes, nbytes / megabyte)
-    print "  TOTAL:           %d bytes (%.3f MB)" % (self.memory['total'], self.memory['total'] / megabyte)
-    mem = logger.getAllocationTotal() - logger.getDeallocationTotal()
-    print "  TOTAL (Code):    %d bytes (%.3f MB)" % (mem, mem / megabyte)
-    print "  Percentage memory modeled: %.2f%%" % (self.memory['total']*100.0/mem)
-    return
-
   # PRIVATE METHODS ////////////////////////////////////////////////////
 
   def _configure(self):

Modified: short/3D/PyLith/trunk/pylith/perf/Mesh.py
===================================================================
--- short/3D/PyLith/trunk/pylith/perf/Mesh.py	2009-05-09 00:38:09 UTC (rev 14936)
+++ short/3D/PyLith/trunk/pylith/perf/Mesh.py	2009-05-09 02:14:34 UTC (rev 14937)
@@ -42,44 +42,15 @@
       raise ValueError("Unknown cell type '%s' for dim %d and cone size %d." % (self.cellType,self.dimension,self.coneSize))
     return
 
-  def tabulateNew(self, memDict):
+  def tabulate(self, memDict):
     """
     Tabulate memory use.
     """
     memDict['Creation']       = self.sizeInt * (2 * (self.coneSize*self.ncells + self.nvertices + self.ncells) + self.coneSize*self.ncells)
     memDict['Stratification'] = 2 * self.sizeArrow * (self.nvertices + self.ncells)
-    memDict['Coordinates']    = self.sizeDouble * self.dimension * self.nvertices
+    # Here we have data + atlas (could use uniform) + bc (could use Section)
+    memDict['Coordinates']    = (self.sizeDouble * self.dimension * self.nvertices) + (2 * self.sizeInt * self.nvertices) + (2 * self.sizeInt * self.nvertices)
     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 = self.sizeInt * (2 * (coneSize*ncells + nvertices + ncells) + coneSize*ncells)
-    memory['mesh'] = nbytes
-
-    # stratification
-    nbytes = 2 * self.sizeArrow * (nvertices + ncells)
-    memory['stratification'] = nbytes
-
-    # coordinates
-    nbytes = self.sizeDouble * dimension * nvertices
-    memory['coordinates'] = nbytes
-
-    # materials
-    nbytes = 2 * self.sizeArrow * ncells
-    memory['materials'] = nbytes
-    return memory
-
 if __name__ == '__main__':
   print 'Memory:',Mesh(2, 3, 10, 25).tabulate()

Modified: short/3D/PyLith/trunk/pylith/perf/VertexGroup.py
===================================================================
--- short/3D/PyLith/trunk/pylith/perf/VertexGroup.py	2009-05-09 00:38:09 UTC (rev 14936)
+++ short/3D/PyLith/trunk/pylith/perf/VertexGroup.py	2009-05-09 02:14:34 UTC (rev 14937)
@@ -6,26 +6,22 @@
   """
   Mesh object for holding vertex group memory and performance information.
   """
-  def __init__(self, label = '', numVertices = 0):
+  def __init__(self, label = '', numVertices = 0, numMeshVertices = 0):
     """
     Constructor.
     """
-    self.label     = label
-    self.nvertices = numVertices
+    self.label         = label
+    self.nvertices     = numVertices
+    self.nMeshVertices = numMeshVertices
     return
 
-  def tabulateNew(self, memDict):
+  def tabulate(self, memDict):
     """
     Tabulate memory use.
     """
-    memDict[self.label] = self.sizeInt * (2 * self.nvertices + self.nvertices)
+    # Here we have data + atlas (could use uniform) + bc (use Section)
+    memDict[self.label] = (self.sizeInt * self.nvertices) + (2 * self.sizeInt * self.nMeshVertices) + (2 * self.sizeInt * self.nMeshVertices)
     return
 
-  def tabulate(self):
-    """
-    Tabulate memory use.
-    """
-    return self.sizeInt * ( 2 * self.nvertices + self.nvertices)
-
 if __name__ == '__main__':
   print 'Memory:',VertexGroup('rock', 35).tabulate()



More information about the CIG-COMMITS mailing list