[cig-commits] r14952 - in short/3D/PyLith/trunk: libsrc/topology modulesrc/topology pylith pylith/perf pylith/problems

knepley at geodynamics.org knepley at geodynamics.org
Sat May 9 17:16:38 PDT 2009


Author: knepley
Date: 2009-05-09 17:16:38 -0700 (Sat, 09 May 2009)
New Revision: 14952

Added:
   short/3D/PyLith/trunk/pylith/perf/Field.py
Modified:
   short/3D/PyLith/trunk/libsrc/topology/Field.cc
   short/3D/PyLith/trunk/libsrc/topology/Field.hh
   short/3D/PyLith/trunk/libsrc/topology/Fields.hh
   short/3D/PyLith/trunk/libsrc/topology/Fields.icc
   short/3D/PyLith/trunk/modulesrc/topology/Field.i
   short/3D/PyLith/trunk/modulesrc/topology/Fields.i
   short/3D/PyLith/trunk/pylith/Makefile.am
   short/3D/PyLith/trunk/pylith/perf/MemoryLogger.py
   short/3D/PyLith/trunk/pylith/problems/Formulation.py
Log:
More logging


Modified: short/3D/PyLith/trunk/libsrc/topology/Field.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Field.cc	2009-05-10 00:02:11 UTC (rev 14951)
+++ short/3D/PyLith/trunk/libsrc/topology/Field.cc	2009-05-10 00:16:38 UTC (rev 14952)
@@ -75,6 +75,24 @@
 } // spaceDim
 
 // ----------------------------------------------------------------------
+// Get the chart size
+template<typename mesh_type>
+int
+pylith::topology::Field<mesh_type>::chartSize(void) const
+{ // spaceDim
+  return _section->getChart().size();
+} // spaceDim
+
+// ----------------------------------------------------------------------
+// Get the size
+template<typename mesh_type>
+int
+pylith::topology::Field<mesh_type>::size(void) const
+{ // spaceDim
+  return _section->size();
+} // spaceDim
+
+// ----------------------------------------------------------------------
 // Create seive section.
 template<typename mesh_type>
 void
@@ -156,9 +174,11 @@
 { // newSection
   ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
   logger.stagePush("Field");
-  if (_section.isNull())
+  if (_section.isNull()) {
+    logger.stagePop();
     newSection();
-
+    logger.stagePush("Field");
+  }
   _section->setChart(chart);
 
   const typename chart_type::const_iterator chartEnd = chart.end();
@@ -166,7 +186,11 @@
        c_iter != chartEnd;
        ++c_iter)
     _section->setFiberDimension(*c_iter, fiberDim);
-  allocate();
+  {
+    logger.stagePop();
+    allocate();
+    logger.stagePush("Field");
+  }
   logger.stagePop();
 } // newSection
 
@@ -181,8 +205,11 @@
   _vecFieldType = src._vecFieldType;
 
   const ALE::Obj<RealSection>& srcSection = src.section();
-  if (!srcSection.isNull() && _section.isNull())
+  if (!srcSection.isNull() && _section.isNull()) {
+    logger.stagePop();
     newSection();
+    logger.stagePush("Field");
+  }
 
   if (!_section.isNull()) {
     _section->setAtlas(srcSection->getAtlas());

Modified: short/3D/PyLith/trunk/libsrc/topology/Field.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Field.hh	2009-05-10 00:02:11 UTC (rev 14951)
+++ short/3D/PyLith/trunk/libsrc/topology/Field.hh	2009-05-10 00:16:38 UTC (rev 14952)
@@ -132,6 +132,18 @@
    */
   int spaceDim(void) const;
 
+  /** Get the number of sieve points in the chart.
+   *
+   * @returns the chart size.
+   */
+  int chartSize(void) const;
+
+  /** Get the number of degrees of freedom.
+   *
+   * @returns the number of degrees of freedom.
+   */
+  int size(void) const;
+
   /// Create sieve section.
   void newSection(void);
 

Modified: short/3D/PyLith/trunk/libsrc/topology/Fields.hh
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Fields.hh	2009-05-10 00:02:11 UTC (rev 14951)
+++ short/3D/PyLith/trunk/libsrc/topology/Fields.hh	2009-05-10 00:16:38 UTC (rev 14952)
@@ -104,6 +104,12 @@
    */
   const typename field_type::Mesh& mesh(void) const;
 
+  /** Return the names of all fields.
+   *
+   * @returns an array of all field names
+   */
+  void fieldNames(int *numNames, char ***outNames);
+
 // PROTECTED TYPEDEFS ///////////////////////////////////////////////////
 protected :
 

Modified: short/3D/PyLith/trunk/libsrc/topology/Fields.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Fields.icc	2009-05-10 00:02:11 UTC (rev 14951)
+++ short/3D/PyLith/trunk/libsrc/topology/Fields.icc	2009-05-10 00:16:38 UTC (rev 14952)
@@ -39,14 +39,11 @@
 void
 pylith::topology::Fields<field_type>::deallocate(void)
 { // deallocate
-  ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
-  logger.stagePush("Field");
   const typename map_type::iterator begin = _fields.begin();
   const typename map_type::iterator end = _fields.end();
   for (typename map_type::iterator iter=begin; iter != end; ++iter) {
     delete iter->second; iter->second = 0;
   } // for
-  logger.stagePop();
 } // deallocate
 
 // ----------------------------------------------------------------------
@@ -56,8 +53,6 @@
 pylith::topology::Fields<field_type>::add(const char* name,
 					  const char* label)
 { // add
-  ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
-  logger.stagePush("Field");
   typename map_type::iterator iter = _fields.find(name);
   if (iter != _fields.end()) {
     std::ostringstream msg;
@@ -68,7 +63,6 @@
   
   _fields[name] = new field_type(_mesh);
   _fields[name]->label(label);
-  logger.stagePop();
 } // add
 
 // ----------------------------------------------------------------------
@@ -81,8 +75,6 @@
 			const pylith::topology::FieldBase::DomainEnum domain,
 			const int fiberDim)
 { // add
-  ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
-  logger.stagePush("Field");
   typename map_type::iterator iter = _fields.find(name);
   if (iter != _fields.end()) {
     std::ostringstream msg;
@@ -94,7 +86,6 @@
   _fields[name] = new field_type(_mesh);
   _fields[name]->label(label);
   _fields[name]->newSection(domain, fiberDim);
-  logger.stagePop();
 } // add
 
 // ----------------------------------------------------------------------
@@ -103,8 +94,6 @@
 void
 pylith::topology::Fields<field_type>::del(const char* name)
 { // del
-  ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
-  logger.stagePush("Field");
   typename map_type::iterator iter = _fields.find(name);
   if (iter == _fields.end()) {
     std::ostringstream msg;
@@ -114,7 +103,6 @@
   } // if
   delete iter->second; iter->second = 0;
   _fields.erase(name);
-  logger.stagePop();
 } // del
 
 // ----------------------------------------------------------------------
@@ -165,8 +153,6 @@
 void
 pylith::topology::Fields<field_type>::copyLayout(const char* name)
 { // copyLayout
-  ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
-  logger.stagePush("Field");
   typename map_type::const_iterator src = _fields.find(name);
   if (src == _fields.end()) {
     std::ostringstream msg;
@@ -180,7 +166,6 @@
   for (typename map_type::iterator iter=begin; iter != end; ++iter)
     if (iter != src)
       iter->second->newSection(*src->second);
-  logger.stagePop();
 } // copyLayout
 
 // ----------------------------------------------------------------------
@@ -192,5 +177,23 @@
   return _mesh;
 } // mesh
 
+// ----------------------------------------------------------------------
+// Get names of all fields
+template<typename field_type>
+void
+pylith::topology::Fields<field_type>::fieldNames(int *numNames, char ***outNames)
+{ // fieldNames
+  *numNames = _fields.size();
+  PetscErrorCode ierr = PetscMalloc((*numNames) * sizeof(char *), outNames);
+  const typename map_type::const_iterator namesEnd = _fields.end();
+  int i = 0;
+  for (typename map_type::const_iterator name = _fields.begin(); name != namesEnd; ++name) {
+    char *newName;
 
+    ierr = PetscStrallocpy(name->first.c_str(), &newName);
+    (*outNames)[i++] = newName;
+  }
+} // fieldNames
+
+
 // End of file 

Modified: short/3D/PyLith/trunk/modulesrc/topology/Field.i
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/Field.i	2009-05-10 00:02:11 UTC (rev 14951)
+++ short/3D/PyLith/trunk/modulesrc/topology/Field.i	2009-05-10 00:16:38 UTC (rev 14952)
@@ -121,6 +121,18 @@
        */
       int spaceDim(void) const;
       
+      /** Get the number of sieve points in the chart.
+       *
+       * @returns the chart size.
+       */
+      int chartSize(void) const;
+      
+      /** Get the number of degrees of freedom.
+       *
+       * @returns the number of degrees of freedom.
+       */
+      int size(void) const;
+      
       /// Create sieve section.
       void newSection(void);
 

Modified: short/3D/PyLith/trunk/modulesrc/topology/Fields.i
===================================================================
--- short/3D/PyLith/trunk/modulesrc/topology/Fields.i	2009-05-10 00:02:11 UTC (rev 14951)
+++ short/3D/PyLith/trunk/modulesrc/topology/Fields.i	2009-05-10 00:16:38 UTC (rev 14952)
@@ -88,6 +88,12 @@
        */
       const typename field_type::Mesh& mesh(void) const;
 
+      /** Return the names of all fields.
+       *
+       * @returns an array of all field names
+       */
+      void fieldNames(int *numNames, char ***outNames);
+
     }; // Fields
 
   } // topology

Modified: short/3D/PyLith/trunk/pylith/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/pylith/Makefile.am	2009-05-10 00:02:11 UTC (rev 14951)
+++ short/3D/PyLith/trunk/pylith/Makefile.am	2009-05-10 00:16:38 UTC (rev 14952)
@@ -90,6 +90,7 @@
 	perf/Mesh.py \
 	perf/Material.py \
 	perf/VertexGroup.py \
+	perf/Field.py \
 	problems/__init__.py \
 	problems/Explicit.py \
 	problems/Formulation.py \

Added: short/3D/PyLith/trunk/pylith/perf/Field.py
===================================================================
--- short/3D/PyLith/trunk/pylith/perf/Field.py	                        (rev 0)
+++ short/3D/PyLith/trunk/pylith/perf/Field.py	2009-05-10 00:16:38 UTC (rev 14952)
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+
+from Memory import Memory
+
+class Field(Memory):
+  """
+  Mesh object for holding field memory and performance information.
+  """
+  def __init__(self, label = '', size = 0, chartSize = 0):
+    """
+    Constructor.
+    """
+    self.label     = label
+    self.size      = size
+    self.chartSize = chartSize
+    return
+
+  def tabulate(self, memDict):
+    """
+    Tabulate memory use.
+    """
+    # Here we have data + atlas + bc
+    memDict[self.label] = (self.sizeDouble * self.size) + (2 * self.sizeInt * self.chartSize) + (2 * self.sizeInt * self.chartSize)
+    return
+
+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-10 00:02:11 UTC (rev 14951)
+++ short/3D/PyLith/trunk/pylith/perf/MemoryLogger.py	2009-05-10 00:16:38 UTC (rev 14952)
@@ -53,7 +53,6 @@
     Logger.__init__(self, name)
     self.megabyte = float(2**20)
     self.memory   = {}
-    self.memory['Field'] = 0
     self.memory['Completion'] = 0
     return
 
@@ -95,6 +94,18 @@
     if self.verbose: self.show()
     return
 
+  def logField(self, stage, field):
+    """
+    Read field parameters to determine memory from our model.
+    """
+    import pylith.perf.Field
+
+    if not 'Field' in self.memory: self.memory['Field'] = {}
+    field = pylith.perf.Field.Field(field.label(), field.size(), field.chartSize())
+    field.tabulate(self.memory['Field'])
+    if self.verbose: self.show()
+    return
+
   def mergeMemDict(self, memDictTarget, memDictSource):
     for key in memDictSource:
       if not key in memDictTarget:
@@ -147,12 +158,9 @@
           output.append(self.memLine('Code',  name, mem, indent))
     if namePrefix:
       mem = logger.getAllocationTotal(namePrefix) - logger.getDeallocationTotal(namePrefix)
-      print 'Queried',namePrefix,'code memory'
     else:
       mem = logger.getAllocationTotal() - logger.getDeallocationTotal()
-      print 'Queried total code memory'
     if mem == 0:
-      print 'Used code total'
       mem = codeTotal
     output.append(self.memLine('Model', 'Total', total, indent))
     output.append(self.memLine('Code',  'Total', mem, indent))

Modified: short/3D/PyLith/trunk/pylith/problems/Formulation.py
===================================================================
--- short/3D/PyLith/trunk/pylith/problems/Formulation.py	2009-05-10 00:02:11 UTC (rev 14951)
+++ short/3D/PyLith/trunk/pylith/problems/Formulation.py	2009-05-10 00:16:38 UTC (rev 14952)
@@ -91,6 +91,11 @@
                                              factory=JacobianViewer)
     jacobianViewer.meta['tip'] = "Writer for Jacobian sparse matrix."
 
+    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="formulation"):
@@ -294,6 +299,10 @@
     logEvent = "%sfinalize" % self._loggingPrefix
     self._logger.eventBegin(logEvent)
 
+    for name in self.fields.fieldNames():
+      field = self.fields.get(name)
+      self.perfLogger.logField('Field', field)
+
     self._info.log("Formulation finalize.")
     self._debug.log(resourceUsageString())
     for integrator in self.integratorsMesh + self.integratorsSubMesh:
@@ -320,6 +329,7 @@
     self.output = self.inventory.output
     self.viewJacobian = self.inventory.viewJacobian
     self.jacobianViewer = self.inventory.jacobianViewer
+    self.perfLogger = self.inventory.perfLogger
 
     import journal
     self._debug = journal.debug(self.name)



More information about the CIG-COMMITS mailing list