[cig-commits] r17915 - in short/3D/PyLith/trunk: . libsrc/meshio libsrc/topology pylith/apps pylith/perf pylith/topology tests tests/topology tests/topology/data
brad at geodynamics.org
brad at geodynamics.org
Sat Feb 19 21:30:39 PST 2011
Author: brad
Date: 2011-02-19 21:30:39 -0800 (Sat, 19 Feb 2011)
New Revision: 17915
Added:
short/3D/PyLith/trunk/tests/topology/
short/3D/PyLith/trunk/tests/topology/Makefile.am
short/3D/PyLith/trunk/tests/topology/data/
short/3D/PyLith/trunk/tests/topology/data/tet4.exo
short/3D/PyLith/trunk/tests/topology/test_meshmem.py
short/3D/PyLith/trunk/tests/topology/test_topology.cc
Modified:
short/3D/PyLith/trunk/configure.ac
short/3D/PyLith/trunk/libsrc/meshio/MeshBuilder.cc
short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc
short/3D/PyLith/trunk/libsrc/topology/Distributor.cc
short/3D/PyLith/trunk/libsrc/topology/Mesh.cc
short/3D/PyLith/trunk/libsrc/topology/Mesh.icc
short/3D/PyLith/trunk/libsrc/topology/MeshRefiner.cc
short/3D/PyLith/trunk/libsrc/topology/RefineUniform.cc
short/3D/PyLith/trunk/libsrc/topology/ReverseCuthillMcKee.cc
short/3D/PyLith/trunk/libsrc/topology/SubMesh.cc
short/3D/PyLith/trunk/pylith/apps/PetscApplication.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
short/3D/PyLith/trunk/pylith/topology/MeshImporter.py
short/3D/PyLith/trunk/pylith/topology/RefineUniform.py
short/3D/PyLith/trunk/subpackage.am
short/3D/PyLith/trunk/tests/Makefile.am
Log:
Worked on adding memory logging to distribution, refinement, and reordering. Created test applications to check memory model and permit facilitate checking with valgrind.
Modified: short/3D/PyLith/trunk/configure.ac
===================================================================
--- short/3D/PyLith/trunk/configure.ac 2011-02-20 02:15:03 UTC (rev 17914)
+++ short/3D/PyLith/trunk/configure.ac 2011-02-20 05:30:39 UTC (rev 17915)
@@ -377,6 +377,7 @@
tests/3d/plasticity/threehex8/mesh/Makefile
tests/3d/plasticity/threehex8/results/Makefile
tests/3d/plasticity/threehex8/spatialdb/Makefile
+ tests/topology/Makefile
doc/Makefile
doc/developer/Makefile
doc/install/Makefile
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshBuilder.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshBuilder.cc 2011-02-20 02:15:03 UTC (rev 17914)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshBuilder.cc 2011-02-20 05:30:39 UTC (rev 17915)
@@ -84,9 +84,8 @@
MPI_Comm_rank(comm, &rank);
// Memory debugging
ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
- logger.setDebug(mesh->debug()/2);
+ //logger.setDebug(1);
- logger.stagePush("Mesh");
logger.stagePush("MeshCreation");
if (0 == rank) {
assert(coordinates->size() == numVertices*spaceDim);
@@ -173,6 +172,7 @@
} // if/else
logger.stagePop();
} else {
+ logger.stagePop();
logger.stagePush("MeshStratification");
sieveMesh->getSieve()->setChart(SieveMesh::sieve_type::chart_type());
sieveMesh->getSieve()->allocate();
@@ -183,10 +183,8 @@
logger.stagePush("MeshCoordinates");
ALE::SieveBuilder<SieveMesh>::buildCoordinates(sieveMesh, spaceDim,
&(*coordinates)[0]);
- logger.stagePop(); // MeshCoordinates
+ logger.stagePop(); // Coordinates
- logger.stagePop(); // Mesh
-
sieveMesh->getFactory()->clear();
} // buildMesh
@@ -219,7 +217,7 @@
// Memory logging
ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
- logger.setDebug(fault->debug()/2);
+ //logger.setDebug(fault->debug()/2);
logger.stagePush("FaultCreation");
if (0 == rank) {
Modified: short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc 2011-02-20 02:15:03 UTC (rev 17914)
+++ short/3D/PyLith/trunk/libsrc/meshio/MeshIO.cc 2011-02-20 05:30:39 UTC (rev 17915)
@@ -74,10 +74,16 @@
{ // read
assert(0 == _mesh);
+ ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
+ //logger.setDebug(1);
+ logger.stagePush("Mesh");
+
_mesh = mesh;
_mesh->debug(_debug);
_read();
+ logger.stagePop();
+
_mesh = 0;
} // read
@@ -207,7 +213,7 @@
ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
///logger.setDebug(2);
- logger.stagePush("Materials");
+ logger.stagePush("Labels");
const ALE::Obj<SieveMesh::label_type>& labelMaterials =
sieveMesh->createLabel("material-id");
if (!sieveMesh->commRank()) {
@@ -305,7 +311,7 @@
} // if
ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
- logger.stagePush("VertexGroups");
+ logger.stagePush("IntSections");
const ALE::Obj<IntSection>& groupField = sieveMesh->getIntSection(name);
assert(!groupField.isNull());
Modified: short/3D/PyLith/trunk/libsrc/topology/Distributor.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Distributor.cc 2011-02-20 02:15:03 UTC (rev 17914)
+++ short/3D/PyLith/trunk/libsrc/topology/Distributor.cc 2011-02-20 05:30:39 UTC (rev 17915)
@@ -84,6 +84,7 @@
<< "', distribution mesh using dumb partitioner." << journal::endl;
_distribute<ALE::DistributionNew<SieveMesh> >(newMesh, origMesh);
} // else
+
} // distribute
// ----------------------------------------------------------------------
@@ -112,6 +113,7 @@
const ALE::Obj<SieveMesh> sieveMesh = mesh.sieveMesh();
assert(!sieveMesh.isNull());
double rankReal = double(sieveMesh->commRank());
+ assert(sieveMesh->height() > 0);
const ALE::Obj<SieveMesh::label_sequence>& cells =
sieveMesh->heightStratum(0);
assert(!cells.isNull());
@@ -143,6 +145,11 @@
typedef typename DistributionType::partitioner_type partitioner_type;
typedef typename DistributionType::partition_type partition_type;
+ ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
+ //logger.setDebug(1);
+ logger.stagePush("Mesh");
+ logger.stagePush("MeshCreation");
+
journal::info_t info("distributor");
info << journal::at(__HERE__)
@@ -214,6 +221,9 @@
throw ALE::Exception("Invalid Overlap");
} // if
+ logger.stagePop();
+ logger.stagePush("MeshCoordinates");
+
// Distribute the coordinates
info << journal::at(__HERE__)
<< "Distribution the vertex coordinates." << journal::endl;
@@ -230,6 +240,9 @@
sendMeshOverlap, recvMeshOverlap,
parallelCoordinates);
+ logger.stagePop();
+ logger.stagePush("MeshRealSections");
+
// Distribute other sections
info << journal::at(__HERE__)
<< "Distribution other sections." << journal::endl;
@@ -253,6 +266,10 @@
if (n)
throw std::logic_error("Need to distribute more real sections");
}
+
+ logger.stagePop();
+ logger.stagePush("IntSections");
+
if (origSieveMesh->getIntSections()->size() > 0) {
ALE::Obj<std::set<std::string> > names = origSieveMesh->getIntSections();
assert(!names.isNull());
@@ -287,6 +304,9 @@
if (origSieveMesh->getArrowSections()->size() > 1)
throw std::logic_error("Need to distribute more arrow sections");
+ logger.stagePop();
+ logger.stagePush("Labels");
+
// Distribute labels
info << journal::at(__HERE__)
<< "Distributing labels." << journal::endl;
@@ -330,6 +350,9 @@
#endif
} // for
+ logger.stagePop();
+ logger.stagePush("MeshOverlap");
+
// Create the parallel overlap
info << journal::at(__HERE__)
<< "Creating the parallel overlap." << journal::endl;
@@ -347,6 +370,10 @@
sendParallelMeshOverlap,
recvParallelMeshOverlap);
newSieveMesh->setCalculatedOverlap(true);
+
+ logger.stagePop();
+ logger.stagePop(); // Mesh
+ //logger.setDebug(0);
} // distribute
Modified: short/3D/PyLith/trunk/libsrc/topology/Mesh.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Mesh.cc 2011-02-20 02:15:03 UTC (rev 17914)
+++ short/3D/PyLith/trunk/libsrc/topology/Mesh.cc 2011-02-20 05:30:39 UTC (rev 17915)
@@ -65,6 +65,7 @@
pylith::topology::Mesh::deallocate(void)
{ // deallocate
delete _coordsys; _coordsys = 0;
+ _mesh.destroy();
} // deallocate
// ----------------------------------------------------------------------
Modified: short/3D/PyLith/trunk/libsrc/topology/Mesh.icc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/Mesh.icc 2011-02-20 02:15:03 UTC (rev 17914)
+++ short/3D/PyLith/trunk/libsrc/topology/Mesh.icc 2011-02-20 05:30:39 UTC (rev 17915)
@@ -68,21 +68,23 @@
inline
int
pylith::topology::Mesh::coneSize(void) const {
- return (!_mesh.isNull()) ? _mesh->getSieve()->getConeSize(*_mesh->heightStratum(0)->begin()) : 0;
+
+ return (!_mesh.isNull() && numCells() > 0) ?
+ _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;
+ return (!_mesh.isNull() && _mesh->depth() > 0) ? _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;
+ return (!_mesh.isNull() && _mesh->height() > 0) ? _mesh->heightStratum(0)->size() : 0;
}
// Set MPI communicator associated with mesh.
Modified: short/3D/PyLith/trunk/libsrc/topology/MeshRefiner.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/MeshRefiner.cc 2011-02-20 02:15:03 UTC (rev 17914)
+++ short/3D/PyLith/trunk/libsrc/topology/MeshRefiner.cc 2011-02-20 05:30:39 UTC (rev 17915)
@@ -71,6 +71,11 @@
assert(_orderOldMesh);
assert(_orderNewMesh);
+ ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
+ //logger.setDebug(1);
+ logger.stagePush("Mesh");
+ logger.stagePush("MeshCreation");
+
// Calculate order in old mesh.
_orderOldMesh->initialize(mesh);
@@ -158,6 +163,11 @@
} // for
newSieve->symmetrize();
+
+ logger.stagePop();
+ //logger.setDebug(0);
+ logger.stagePush("MeshCoordinates");
+
// Set coordinates in refined mesh.
const Obj<mesh_type::real_section_type>& coordinates = mesh->getRealSection("coordinates");
assert(!coordinates.isNull());
@@ -184,10 +194,28 @@
refiner.setCoordsNewVertices(newCoordinates, coordinates);
+ logger.stagePop();
+ logger.stagePush("MeshStratification");
+
_stratify(newMesh);
+
+ logger.stagePop();
+ logger.stagePush("MeshOverlap");
+
_calcNewOverlap(newMesh, mesh, refiner);
+
+ logger.stagePop();
+ logger.stagePush("IntSections");
+
_createIntSections(newMesh, mesh, refiner);
+
+ logger.stagePop();
+ logger.stagePush("Labels");
+
_createLabels(newMesh, mesh, refiner);
+
+ logger.stagePop();
+ logger.stagePop(); // Mesh
} // _refine
// ----------------------------------------------------------------------
Modified: short/3D/PyLith/trunk/libsrc/topology/RefineUniform.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/RefineUniform.cc 2011-02-20 02:15:03 UTC (rev 17914)
+++ short/3D/PyLith/trunk/libsrc/topology/RefineUniform.cc 2011-02-20 05:30:39 UTC (rev 17915)
@@ -56,6 +56,10 @@
{ // refine
assert(0 != newMesh);
+ ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
+ //logger.setDebug(2);
+ logger.stagePush("Refinement");
+
typedef SieveMesh::point_type point_type;
const ALE::Obj<SieveMesh>& sieveMesh = mesh.sieveMesh();
@@ -123,6 +127,9 @@
} // switch
// newMesh->view("REFINED MESH");
+
+ logger.stagePop();
+ //logger.setDebug(0);
} // refine
Modified: short/3D/PyLith/trunk/libsrc/topology/ReverseCuthillMcKee.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/ReverseCuthillMcKee.cc 2011-02-20 02:15:03 UTC (rev 17914)
+++ short/3D/PyLith/trunk/libsrc/topology/ReverseCuthillMcKee.cc 2011-02-20 05:30:39 UTC (rev 17915)
@@ -35,7 +35,9 @@
{ // reorder
assert(0 != mesh);
- //logger.stagePush("MeshReordering");
+ ALE::MemoryLogger& logger = ALE::MemoryLogger::singleton();
+ //logger.setDebug(1);
+ logger.stagePush("MeshReordering");
int rank = 0;
MPI_Comm_rank(mesh->comm(), &rank);
@@ -58,7 +60,7 @@
//sieveMesh->view("MESH AFTER RELABEL");
} // if
- //logger.stagePop();
+ logger.stagePop();
} // reorder
Modified: short/3D/PyLith/trunk/libsrc/topology/SubMesh.cc
===================================================================
--- short/3D/PyLith/trunk/libsrc/topology/SubMesh.cc 2011-02-20 02:15:03 UTC (rev 17914)
+++ short/3D/PyLith/trunk/libsrc/topology/SubMesh.cc 2011-02-20 05:30:39 UTC (rev 17915)
@@ -60,6 +60,7 @@
pylith::topology::SubMesh::deallocate(void)
{ // deallocate
delete _coordsys; _coordsys = 0;
+ _mesh.destroy();
} // deallocate
// ----------------------------------------------------------------------
Modified: short/3D/PyLith/trunk/pylith/apps/PetscApplication.py
===================================================================
--- short/3D/PyLith/trunk/pylith/apps/PetscApplication.py 2011-02-20 02:15:03 UTC (rev 17914)
+++ short/3D/PyLith/trunk/pylith/apps/PetscApplication.py 2011-02-20 05:30:39 UTC (rev 17915)
@@ -76,9 +76,10 @@
except Exception, err:
self.cleanup() # Attempt to clean up memory.
- print "Fatal error while running PyLith:"
- print err
- print "Calling MPI_Abort() to abort PyLith application."
+ print "Fatal error. Calling MPI_Abort() to abort PyLith application."
+ # Print stacktrace
+ from traceback import print_exc
+ print_exc()
from pylith.mpi import mpi
errorCode = -1
mpi.mpi_abort(mpi.petsc_comm_world(), errorCode)
Modified: short/3D/PyLith/trunk/pylith/perf/MemoryLogger.py
===================================================================
--- short/3D/PyLith/trunk/pylith/perf/MemoryLogger.py 2011-02-20 02:15:03 UTC (rev 17914)
+++ short/3D/PyLith/trunk/pylith/perf/MemoryLogger.py 2011-02-20 05:30:39 UTC (rev 17915)
@@ -75,7 +75,7 @@
mesh.numVertices(), mesh.numCells())
meshModel.tabulate(self.memory[stage])
for group, nvertices in mesh.groupSizes():
- self.logVertexGroup('VertexGroups', group, nvertices, mesh.numVertices())
+ self.logVertexGroup('IntSections', group, nvertices, mesh.numVertices())
return
Modified: short/3D/PyLith/trunk/pylith/perf/Mesh.py
===================================================================
--- short/3D/PyLith/trunk/pylith/perf/Mesh.py 2011-02-20 02:15:03 UTC (rev 17914)
+++ short/3D/PyLith/trunk/pylith/perf/Mesh.py 2011-02-20 05:30:39 UTC (rev 17915)
@@ -61,7 +61,8 @@
Initialize application.
"""
try:
- self.cellType = self.cellTypes[(self.dimension,self.coneSize)]
+ if self.coneSize > 0:
+ self.cellType = self.cellTypes[(self.dimension,self.coneSize)]
except:
raise ValueError("Unknown cell type '%s' for dim %d and cone size %d." % (self.cellType,self.dimension,self.coneSize))
return
@@ -74,7 +75,11 @@
memDict['Stratification'] = 2 * self.sizeArrow * (self.nvertices + self.ncells)
# 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)
+ memDict['Overlap'] = 0 # Don't know overlap
+ memDict['RealSections'] = 0 # Real sections should be elsewhere
return
if __name__ == '__main__':
- print 'Memory:',Mesh(2, 3, 10, 25).tabulate()
+ d = {}
+ Mesh(2, 3, 10, 25).tabulate(d)
+ print 'Memory:',d
Modified: short/3D/PyLith/trunk/pylith/perf/VertexGroup.py
===================================================================
--- short/3D/PyLith/trunk/pylith/perf/VertexGroup.py 2011-02-20 02:15:03 UTC (rev 17914)
+++ short/3D/PyLith/trunk/pylith/perf/VertexGroup.py 2011-02-20 05:30:39 UTC (rev 17915)
@@ -46,7 +46,9 @@
return
if __name__ == '__main__':
- print 'Memory:',VertexGroup('rock', 35).tabulate()
+ d = {}
+ VertexGroup('rock', 35).tabulate(d)
+ print 'Memory:',d
# End of file
Modified: short/3D/PyLith/trunk/pylith/topology/MeshImporter.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/MeshImporter.py 2011-02-20 02:15:03 UTC (rev 17914)
+++ short/3D/PyLith/trunk/pylith/topology/MeshImporter.py 2011-02-20 05:30:39 UTC (rev 17915)
@@ -116,8 +116,7 @@
self._adjustTopology(mesh, faults)
# Distribute mesh
- import mpi
- if mpi.MPI_Comm_size(mpi.MPI_COMM_WORLD) > 1:
+ if mesh.getComm().size > 1:
self._info.log("Distributing mesh.")
mesh = self.distributor.distribute(mesh, normalizer)
if self.debug:
Modified: short/3D/PyLith/trunk/pylith/topology/RefineUniform.py
===================================================================
--- short/3D/PyLith/trunk/pylith/topology/RefineUniform.py 2011-02-20 02:15:03 UTC (rev 17914)
+++ short/3D/PyLith/trunk/pylith/topology/RefineUniform.py 2011-02-20 05:30:39 UTC (rev 17915)
@@ -68,6 +68,9 @@
newMesh.coordsys(mesh.coordsys())
ModuleRefineUniform.refine(self, newMesh, mesh, self.levels)
+ if mesh != newMesh:
+ mesh.deallocate();
+
self._eventLogger.eventEnd(logEvent)
return newMesh
Modified: short/3D/PyLith/trunk/subpackage.am
===================================================================
--- short/3D/PyLith/trunk/subpackage.am 2011-02-20 02:15:03 UTC (rev 17914)
+++ short/3D/PyLith/trunk/subpackage.am 2011-02-20 05:30:39 UTC (rev 17915)
@@ -41,7 +41,5 @@
INCLUDES = -I$(top_builddir)/include
-# version
-# $Id$
# End of file
Modified: short/3D/PyLith/trunk/tests/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/tests/Makefile.am 2011-02-20 02:15:03 UTC (rev 17914)
+++ short/3D/PyLith/trunk/tests/Makefile.am 2011-02-20 05:30:39 UTC (rev 17915)
@@ -18,6 +18,7 @@
SUBDIRS = \
2d \
- 3d
+ 3d \
+ topology
# End of file
Added: short/3D/PyLith/trunk/tests/topology/Makefile.am
===================================================================
--- short/3D/PyLith/trunk/tests/topology/Makefile.am (rev 0)
+++ short/3D/PyLith/trunk/tests/topology/Makefile.am 2011-02-20 05:30:39 UTC (rev 17915)
@@ -0,0 +1,49 @@
+# -*- Makefile -*-
+#
+# ----------------------------------------------------------------------
+#
+# Brad T. Aagaard, U.S. Geological Survey
+# Charles A. Williams, GNS Science
+# Matthew G. Knepley, University of Chicago
+#
+# This code was developed as part of the Computational Infrastructure
+# for Geodynamics (http://geodynamics.org).
+#
+# Copyright (c) 2010 University of California, Davis
+#
+# See COPYING for license information.
+#
+# ----------------------------------------------------------------------
+#
+
+if ENABLE_CUBIT
+
+TESTS = testtopology
+
+check_PROGRAMS = testtopology
+
+# Primary source files
+testtopology_SOURCES = \
+ test_topology.cc
+
+
+INCLUDES = -I$(top_builddir)/include
+
+AM_CPPFLAGS = \
+ $(PETSC_SIEVE_FLAGS) $(PETSC_CC_INCLUDES) \
+ -I$(PYTHON_INCDIR) $(PYTHON_EGG_CPPFLAGS)
+
+testtopology_LDFLAGS = \
+ $(AM_LDFLAGS) $(PYTHON_LA_LDFLAGS)
+
+testtopology_LDADD = \
+ $(top_builddir)/libsrc/libpylith.la \
+ -lspatialdata \
+ -lnetcdf_c++ -lnetcdf \
+ $(PETSC_LIB) $(PYTHON_BLDLIBRARY) $(PYTHON_LIBS) $(PYTHON_SYSLIBS)
+
+
+endif
+
+
+# End of file
Added: short/3D/PyLith/trunk/tests/topology/data/tet4.exo
===================================================================
(Binary files differ)
Property changes on: short/3D/PyLith/trunk/tests/topology/data/tet4.exo
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: short/3D/PyLith/trunk/tests/topology/test_meshmem.py
===================================================================
--- short/3D/PyLith/trunk/tests/topology/test_meshmem.py (rev 0)
+++ short/3D/PyLith/trunk/tests/topology/test_meshmem.py 2011-02-20 05:30:39 UTC (rev 17915)
@@ -0,0 +1,180 @@
+#!/usr/bin/env nemesis
+#
+# ======================================================================
+#
+# Brad T. Aagaard, U.S. Geological Survey
+# Charles A. Williams, GNS Science
+# Matthew G. Knepley, University of Chicago
+#
+# This code was developed as part of the Computational Infrastructure
+# for Geodynamics (http://geodynamics.org).
+#
+# Copyright (c) 2010 University of California, Davis
+#
+# See COPYING for license information.
+#
+# ======================================================================
+#
+
+## @file tests/topology/test_meshmem.py
+
+## @brief Python application for testing memory
+## allocation/deallocation in Mesh.
+
+from pyre.applications.Script import Script
+
+# ----------------------------------------------------------------------
+class TestApp(Script):
+ """
+ Test application.
+ """
+
+ # PUBLIC METHODS /////////////////////////////////////////////////////
+
+ def __init__(self, name="testapp"):
+ """
+ Constructor.
+ """
+ Script.__init__(self, name)
+ return
+
+
+ def main(self, *args, **kwds):
+ """
+ Run the application.
+ """
+ from pylith.utils.PetscManager import PetscManager
+ manager = PetscManager()
+ manager.initialize()
+
+ self._runTest()
+
+ manager.finalize()
+ return
+
+
+ # PRIVATE METHODS ////////////////////////////////////////////////////
+
+ def _runTest(self):
+ """
+ Run test.
+ """
+
+ #filenameIn = "data/tet4.exo"
+ filenameIn = "tri3_200m_gradient.exo"
+
+ from pylith.perf.MemoryLogger import MemoryLogger
+ self.logger = MemoryLogger()
+ self.logger._configure()
+ from pylith.topology.topology import MeshOps_numMaterialCells
+
+ from pylith.mpi.Communicator import petsc_comm_world
+ comm = petsc_comm_world()
+
+ self._showStatus("Before reading mesh")
+
+ # ------------------------------------------------------------
+ # Read mesh
+ from pylith.meshio.MeshIOCubit import MeshIOCubit
+ io = MeshIOCubit()
+ io.inventory.filename = filenameIn
+ io.inventory.useNames = False
+ io._configure()
+
+ from pylith.materials.ElasticIsotropic3D import ElasticIsotropic3D
+ material = ElasticIsotropic3D()
+ material.inventory.label = "Elastic material"
+ material.inventory.id = 1
+ material._configure()
+
+ mesh = io.read(debug=False, interpolate=False)
+ del io
+
+ self.logger.logMesh("Mesh", mesh)
+ material.ncells = MeshOps_numMaterialCells(mesh, material.id())
+ self.logger.logMaterial("Labels", material)
+
+
+ self._showStatus("After reading mesh")
+
+
+ # ------------------------------------------------------------
+ # Reorder mesh
+ from pylith.topology.ReverseCuthillMcKee import ReverseCuthillMcKee
+ ordering = ReverseCuthillMcKee()
+ ordering.reorder(mesh)
+ del ordering
+
+ # Expect no memory allocation
+ self.logger.memory["MeshReordering"] = 0
+
+ self._showStatus("After reordering mesh")
+
+ # ------------------------------------------------------------
+ # Distribute mesh
+ if comm.size > 1:
+ from pylith.topology.Distributor import Distributor
+ from spatialdata.units.Nondimensional import Nondimensional
+ distributor = Distributor()
+ normalizer = Nondimensional()
+ dmesh = distributor.distribute(mesh, normalizer)
+ del distributor
+
+ self.logger.logMesh("Mesh", dmesh)
+ material.ncells = MeshOps_numMaterialCells(dmesh, material.id())
+ self.logger.logMaterial("Labels", material)
+
+ self._showStatus("After distributing mesh")
+
+ mesh.deallocate()
+ mesh = dmesh
+ self._showStatus("After distributing mesh and deallocation")
+
+ # Refine mesh (if necessary)
+ from pylith.topology.RefineUniform import RefineUniform
+ refiner = RefineUniform()
+ rmesh = refiner.refine(mesh)
+ del refiner
+
+ self.logger.logMesh("Mesh", rmesh)
+ material.ncells = MeshOps_numMaterialCells(rmesh, material.id())
+ self.logger.logMaterial("Labels", material)
+
+ self._showStatus("After refining mesh")
+
+ if mesh != rmesh:
+ mesh.deallocate()
+ mesh = rmesh
+ self._showStatus("After refining mesh and deallocation")
+
+
+ return
+
+
+ def _showStatus(self, stage):
+ from pylith.utils.profiling import resourceUsageString
+ from pylith.mpi.Communicator import petsc_comm_world
+ comm = petsc_comm_world()
+
+ if comm.rank == 0:
+ print "\n----------------------------------------------------------------------"
+ print "STAGE: %s" % stage
+ print "----------------------------------------------------------------------"
+ for irank in xrange(comm.size):
+ comm.barrier()
+ if comm.rank == irank:
+ print "\nPROCESSOR %d" % comm.rank
+ print "\nStatus from ps: %s\n" % resourceUsageString()
+ self.logger.show()
+
+ comm.barrier()
+ return
+
+
+# ----------------------------------------------------------------------
+if __name__ == '__main__':
+ app = TestApp()
+ app.run()
+
+
+# End of file
Property changes on: short/3D/PyLith/trunk/tests/topology/test_meshmem.py
___________________________________________________________________
Name: svn:executable
+ *
Added: short/3D/PyLith/trunk/tests/topology/test_topology.cc
===================================================================
--- short/3D/PyLith/trunk/tests/topology/test_topology.cc (rev 0)
+++ short/3D/PyLith/trunk/tests/topology/test_topology.cc 2011-02-20 05:30:39 UTC (rev 17915)
@@ -0,0 +1,103 @@
+// -*- C++ -*-
+//
+// ----------------------------------------------------------------------
+//
+// Brad T. Aagaard, U.S. Geological Survey
+// Charles A. Williams, GNS Science
+// Matthew G. Knepley, University of Chicago
+//
+// This code was developed as part of the Computational Infrastructure
+// for Geodynamics (http://geodynamics.org).
+//
+// Copyright (c) 2010 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ----------------------------------------------------------------------
+//
+
+// Application for using valgrind to test for memory leaks in mesh
+// related operations, including reading, reordering, distribution,
+// and refinement.
+
+#include <portinfo>
+
+#include "pylith/topology/Mesh.hh"
+#include "pylith/meshio/MeshIOCubit.hh"
+#include "pylith/topology/ReverseCuthillMcKee.hh"
+#include "pylith/topology/Distributor.hh"
+#include "pylith/topology/RefineUniform.hh"
+
+#include <petsc.h>
+#include <Python.h>
+
+#include <stdlib.h> // USES abort()
+
+int
+main(int argc,
+ char* argv[])
+{ // main
+ std::string meshFilename = "data/tet4.exo";
+ // Initialize PETSc
+ PetscErrorCode err = PetscInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL);
+ CHKERRQ(err);
+
+ // Initialize Python
+ Py_Initialize();
+
+ if (argc == 2)
+ meshFilename = argv[1];
+
+ int rank;
+ MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
+
+ pylith::meshio::MeshIOCubit reader;
+ reader.filename(meshFilename.c_str());
+ reader.useNodesetNames(false);
+
+ // Read mesh
+ std::cout << "["<<rank<<"] Reading mesh" << std::endl;
+ pylith::topology::Mesh mesh;
+ reader.read(&mesh);
+
+ // Reorder mesh
+ std::cout << "["<<rank<<"] Reordering mesh" << std::endl;
+ pylith::topology::ReverseCuthillMcKee order;
+ order.reorder(&mesh);
+
+ int nprocs = 0;
+ MPI_Comm_size(mesh.comm(), &nprocs);
+ if (nprocs > 1) {
+ // Distribute mesh
+ std::cout << "["<<rank<<"] Distributing mesh" << std::endl;
+ pylith::topology::Mesh dmesh(mesh.dimension(), mesh.comm());
+ pylith::topology::Distributor::distribute(&dmesh, dmesh, "chaco");
+ mesh.deallocate();
+
+ // Refine mesh
+ std::cout << "["<<rank<<"] Refining mesh" << std::endl;
+ pylith::topology::RefineUniform refiner;
+ pylith::topology::Mesh rmesh(dmesh.dimension(), dmesh.comm());
+ refiner.refine(&rmesh, dmesh);
+ rmesh.deallocate();
+ } else {
+ // Refine mesh
+ std::cout << "["<<rank<<"] Refining mesh" << std::endl;
+ pylith::topology::RefineUniform refiner;
+ pylith::topology::Mesh rmesh(mesh.dimension(), mesh.comm());
+ refiner.refine(&rmesh, mesh);
+ rmesh.deallocate();
+ } // if/else
+
+ // Finalize Python
+ Py_Finalize();
+
+ // Finalize PETSc
+ err = PetscFinalize();
+ CHKERRQ(err);
+
+ return 0;
+} // main
+
+
+// End of file
More information about the CIG-COMMITS
mailing list