[cig-commits] r14935 - in short/3D/PyLith/trunk: libsrc/meshio modulesrc/utils pylith/apps pylith/perf
knepley at geodynamics.org
knepley at geodynamics.org
Fri May 8 17:33:44 PDT 2009
Author: knepley
Date: 2009-05-08 17:33:43 -0700 (Fri, 08 May 2009)
New Revision: 14935
Modified:
short/3D/PyLith/trunk/libsrc/meshio/MeshBuilder.cc
short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc
short/3D/PyLith/trunk/modulesrc/utils/Makefile.am
short/3D/PyLith/trunk/modulesrc/utils/petsc.i
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:
Even more memory logging
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshBuilder.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshBuilder.cc 2009-05-08 23:58:03 UTC (rev 14934)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshBuilder.cc 2009-05-09 00:33:43 UTC (rev 14935)
@@ -81,6 +81,7 @@
ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
logger.setDebug(mesh->debug()/2);
+ logger.stagePush("Mesh");
logger.stagePush("MeshCreation");
if (0 == rank) {
assert(coordinates->size() == numVertices*spaceDim);
@@ -174,9 +175,28 @@
logger.stagePop();
} // if/else
+ const double lengthScale = normalizer.lengthScale();
+ normalizer.nondimensionalize(&(*coordinates)[0], coordinates->size(),
+ lengthScale);
+
+ logger.stagePush("MeshCoordinates");
+ ALE::SieveBuilder<SieveMesh>::buildCoordinates(sieveMesh, spaceDim,
+ &(*coordinates)[0]);
+ logger.stagePop();
+ logger.stagePop();
+
#if defined(ALE_MEM_LOGGING)
std::cout
<< std::endl
+ << "Mesh " << logger.getNumAllocations("Mesh")
+ << " allocations " << logger.getAllocationTotal("Mesh")
+ << " bytes" << std::endl
+
+ << "Mesh " << logger.getNumDeallocations("Mesh")
+ << " deallocations " << logger.getDeallocationTotal("Mesh")
+ << " bytes" << std::endl
+
+ << std::endl
<< "MeshCreation " << logger.getNumAllocations("MeshCreation")
<< " allocations " << logger.getAllocationTotal("MeshCreation")
<< " bytes" << std::endl
@@ -191,16 +211,17 @@
<< "MeshStratification " << logger.getNumDeallocations("MeshStratification")
<< " deallocations " << logger.getDeallocationTotal("MeshStratification")
+ << " bytes" << std::endl << std::endl
+
+ << "MeshCoordinates " << logger.getNumAllocations("MeshCoordinates")
+ << " allocations " << logger.getAllocationTotal("MeshCoordinates")
+ << " bytes" << std::endl
+
+ << "MeshCoordinates " << logger.getNumDeallocations("MeshCoordinates")
+ << " deallocations " << logger.getDeallocationTotal("MeshCoordinates")
<< " bytes" << std::endl << std::endl;
#endif
- const double lengthScale = normalizer.lengthScale();
- normalizer.nondimensionalize(&(*coordinates)[0], coordinates->size(),
- lengthScale);
-
- ALE::SieveBuilder<SieveMesh>::buildCoordinates(sieveMesh, spaceDim,
- &(*coordinates)[0]);
-
sieveMesh->getFactory()->clear();
} // buildMesh
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc 2009-05-08 23:58:03 UTC (rev 14934)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc 2009-05-09 00:33:43 UTC (rev 14935)
@@ -205,7 +205,7 @@
assert(!sieveMesh.isNull());
ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
- logger.stagePush("MaterialsCreation");
+ logger.stagePush("Materials");
const ALE::Obj<SieveMesh::label_type>& labelMaterials =
sieveMesh->createLabel("material-id");
if (!sieveMesh->commRank()) {
@@ -250,14 +250,14 @@
#if defined(ALE_MEM_LOGGING)
std::cout
- << "MaterialsCreation "
- << logger.getNumAllocations("MaterialsCreation")
- << " allocations " << logger.getAllocationTotal("MaterialsCreation")
+ << "Materials "
+ << logger.getNumAllocations("Materials")
+ << " allocations " << logger.getAllocationTotal("Materials")
<< " bytes"
<< std::endl
- << "MaterialsCreation "
- << logger.getNumDeallocations("MaterialsCreation")
- << " deallocations " << logger.getDeallocationTotal("MaterialsCreation")
+ << "Materials "
+ << logger.getNumDeallocations("Materials")
+ << " deallocations " << logger.getDeallocationTotal("Materials")
<< " bytes"
<< std::endl;
#endif
@@ -309,7 +309,7 @@
assert(!sieveMesh.isNull());
ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
- logger.stagePush("GroupCreation");
+ logger.stagePush("VertexGroups");
const ALE::Obj<IntSection>& groupField = sieveMesh->getIntSection(name);
assert(!groupField.isNull());
@@ -331,12 +331,12 @@
#if defined(ALE_MEM_LOGGING)
std::cout
- << "GroupCreation " << logger.getNumAllocations("GroupCreation")
- << " allocations " << logger.getAllocationTotal("GroupCreation")
+ << "VertexGroups " << logger.getNumAllocations("VertexGroups")
+ << " allocations " << logger.getAllocationTotal("VertexGroups")
<< " bytes"
<< std::endl
- << "GroupCreation " << logger.getNumDeallocations("GroupCreation")
- << " deallocations " << logger.getDeallocationTotal("GroupCreation")
+ << "VertexGroups " << logger.getNumDeallocations("VertexGroups")
+ << " deallocations " << logger.getDeallocationTotal("VertexGroups")
<< " bytes"
<< std::endl;
#endif
Modified: short/3D/PyLith/trunk/modulesrc/utils/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/modulesrc/utils/Makefile.am 2009-05-08 23:58:03 UTC (rev 14934)
+++ short/3D/PyLith/trunk/modulesrc/utils/Makefile.am 2009-05-09 00:33:43 UTC (rev 14935)
@@ -24,6 +24,7 @@
petsc_swig_sources = \
petsc.i \
petsc_general.i \
+ petsc_memory.i \
petsc_mat.i
petsc_swig_generated = \
Modified: short/3D/PyLith/trunk/modulesrc/utils/petsc.i
===================================================================
--- short/3D/PyLith/trunk/modulesrc/utils/petsc.i 2009-05-08 23:58:03 UTC (rev 14934)
+++ short/3D/PyLith/trunk/modulesrc/utils/petsc.i 2009-05-09 00:33:43 UTC (rev 14935)
@@ -16,6 +16,7 @@
// Header files for module C++ code
%{
#include <petsc.h>
+#include <ALE.hh>
%}
%include "exception.i"
@@ -32,6 +33,7 @@
// Interfaces
%include "petsc_general.i"
+%include "petsc_memory.i"
// End of file
Modified: short/3D/PyLith/trunk/pylith/apps/PyLithApp.py
===================================================================
--- short/3D/PyLith/trunk/pylith/apps/PyLithApp.py 2009-05-08 23:58:03 UTC (rev 14934)
+++ short/3D/PyLith/trunk/pylith/apps/PyLithApp.py 2009-05-09 00:33:43 UTC (rev 14935)
@@ -86,7 +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)
+ self.perfLogger.logMesh("MeshingCreation", mesh)
del interfaces
del self.mesher
self._debug.log(resourceUsageString())
@@ -120,6 +120,7 @@
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-08 23:58:03 UTC (rev 14934)
+++ short/3D/PyLith/trunk/pylith/perf/Material.py 2009-05-09 00:33:43 UTC (rev 14935)
@@ -14,6 +14,13 @@
self.ncells = numCells
return
+ def tabulateNew(self, memDict):
+ """
+ Tabulate memory use.
+ """
+ memDict[self.label] = 2 * self.sizeArrow * self.ncells
+ return
+
def tabulate(self):
"""
Tabulate memory use.
Modified: short/3D/PyLith/trunk/pylith/perf/MemoryLogger.py
===================================================================
--- short/3D/PyLith/trunk/pylith/perf/MemoryLogger.py 2009-05-08 23:58:03 UTC (rev 14934)
+++ short/3D/PyLith/trunk/pylith/perf/MemoryLogger.py 2009-05-09 00:33:43 UTC (rev 14935)
@@ -52,6 +52,7 @@
"""
Logger.__init__(self, name)
self.megabyte = float(2**20)
+ self.memoryNew = {}
self.materials = {}
self.vertexGroups = {}
return
@@ -62,6 +63,8 @@
"""
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'])
for group, nvertices in mesh.groupSizes():
self.logVertexGroup(stage, group, nvertices)
if self.verbose:
@@ -75,6 +78,8 @@
"""
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()
@@ -86,6 +91,8 @@
"""
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()
@@ -121,10 +128,30 @@
self.memory = memory
return
+ def mergeMemDict(self, memDictTarget, memDictSource):
+ for key in memDictSource:
+ if not key in memDictTarget:
+ memDictTarget[key] = memDictSource[key]
+ elif isinstance(memDictSource[key], dict):
+ if not isinstance(memDictTarget[key], dict):
+ raise RuntimeError('Type mismatch in memory dict for key '+str(key))
+ self.mergeMemDict(memDictTarget[key], memDictSource[key])
+ else:
+ 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:
@@ -157,10 +184,63 @@
self.memory['total'] += memory['total']
return
+ def prefix(self, indent):
+ prefix = ''
+ for i in range(indent):
+ prefix += ' '
+ return prefix
+
+ def memLine(self, source, name, mem, indent = 0):
+ return '%s%-30s %8d bytes (%.3f MB)' % (self.prefix(indent), name+' ('+source+'):', mem, mem / self.megabyte)
+
+ def processMemDict(self, memDict, indent = 0, namePrefix = ''):
+ from pylith.utils.petsc import MemoryLogger
+ logger = MemoryLogger.singleton()
+ output = []
+ total = 0
+ codeTotal = 0
+ indent += 1
+ for name,m in memDict.iteritems():
+ fullname = namePrefix+name
+ if isinstance(m, dict):
+ output.append(self.prefix(indent)+name)
+ out,mem,codeMem = self.processMemDict(m, indent, fullname)
+ output.extend(out)
+ total += mem
+ codeTotal += codeMem
+ else:
+ mem = logger.getAllocationTotal(fullname) - logger.getDeallocationTotal(fullname)
+ total += m
+ codeTotal += mem
+ output.append(self.memLine('Model', name, m, indent))
+ if logger.getAllocationTotal(fullname):
+ output.append(self.memLine('Code', name, mem, indent))
+ if namePrefix:
+ mem = logger.getAllocationTotal(namePrefix) - logger.getDeallocationTotal(namePrefix)
+ else:
+ mem = logger.getAllocationTotal() - logger.getDeallocationTotal()
+ if mem == 0:
+ mem = codeTotal
+ output.append(self.memLine('Model', 'Total', total, indent))
+ output.append(self.memLine('Code', 'Total', mem, indent))
+ output.append('%sPercentage memory modeled: %.2f%%' % (self.prefix(indent), total*100.0/mem))
+ return output, total, codeTotal
+
+ def showNew(self):
+ """
+ Print memory usage.
+ """
+ output = ["MEMORY USAGE"]
+ output.extend(self.processMemDict(self.memoryNew)[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:
@@ -170,6 +250,9 @@
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():
@@ -179,6 +262,9 @@
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 ////////////////////////////////////////////////////
Modified: short/3D/PyLith/trunk/pylith/perf/Mesh.py
===================================================================
--- short/3D/PyLith/trunk/pylith/perf/Mesh.py 2009-05-08 23:58:03 UTC (rev 14934)
+++ short/3D/PyLith/trunk/pylith/perf/Mesh.py 2009-05-09 00:33:43 UTC (rev 14935)
@@ -42,6 +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):
+ """
+ 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
+ return
+
def tabulate(self):
"""
Tabulate memory use.
Modified: short/3D/PyLith/trunk/pylith/perf/VertexGroup.py
===================================================================
--- short/3D/PyLith/trunk/pylith/perf/VertexGroup.py 2009-05-08 23:58:03 UTC (rev 14934)
+++ short/3D/PyLith/trunk/pylith/perf/VertexGroup.py 2009-05-09 00:33:43 UTC (rev 14935)
@@ -14,6 +14,13 @@
self.nvertices = numVertices
return
+ def tabulateNew(self, memDict):
+ """
+ Tabulate memory use.
+ """
+ memDict[self.label] = self.sizeInt * (2 * self.nvertices + self.nvertices)
+ return
+
def tabulate(self):
"""
Tabulate memory use.
More information about the CIG-COMMITS
mailing list