[cig-commits] r20608 - in short/3D/PyLith/branches/v1.7-stable: modulesrc/mpi pylith/problems unittests/pytests/mpi unittests/pytests/problems
brad at geodynamics.org
brad at geodynamics.org
Mon Aug 20 10:12:39 PDT 2012
Author: brad
Date: 2012-08-20 10:12:38 -0700 (Mon, 20 Aug 2012)
New Revision: 20608
Added:
short/3D/PyLith/branches/v1.7-stable/modulesrc/mpi/mpi_reduce.i
short/3D/PyLith/branches/v1.7-stable/unittests/pytests/mpi/TestReduce.py
Modified:
short/3D/PyLith/branches/v1.7-stable/modulesrc/mpi/Makefile.am
short/3D/PyLith/branches/v1.7-stable/modulesrc/mpi/mpi.i
short/3D/PyLith/branches/v1.7-stable/pylith/problems/TimeStep.py
short/3D/PyLith/branches/v1.7-stable/unittests/pytests/mpi/Makefile.am
short/3D/PyLith/branches/v1.7-stable/unittests/pytests/mpi/testmpi.py
short/3D/PyLith/branches/v1.7-stable/unittests/pytests/problems/TestTimeStepAdapt.py
short/3D/PyLith/branches/v1.7-stable/unittests/pytests/problems/TestTimeStepUniform.py
short/3D/PyLith/branches/v1.7-stable/unittests/pytests/problems/TestTimeStepUser.py
Log:
Fixed bug in calculating stable time step. Value was not reduced among processors. Added reduction in pylith.problems.TimeStep.
Modified: short/3D/PyLith/branches/v1.7-stable/modulesrc/mpi/Makefile.am
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/modulesrc/mpi/Makefile.am 2012-08-20 16:41:27 UTC (rev 20607)
+++ short/3D/PyLith/branches/v1.7-stable/modulesrc/mpi/Makefile.am 2012-08-20 17:12:38 UTC (rev 20608)
@@ -26,6 +26,7 @@
swig_sources = \
mpi.i \
mpi_comm.i \
+ mpi_reduce.i \
mpi_error.i
swig_generated = \
Modified: short/3D/PyLith/branches/v1.7-stable/modulesrc/mpi/mpi.i
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/modulesrc/mpi/mpi.i 2012-08-20 16:41:27 UTC (rev 20607)
+++ short/3D/PyLith/branches/v1.7-stable/modulesrc/mpi/mpi.i 2012-08-20 17:12:38 UTC (rev 20608)
@@ -29,6 +29,7 @@
// Interfaces
%include "mpi_comm.i"
%include "mpi_error.i"
+%include "mpi_reduce.i"
// End of file
Added: short/3D/PyLith/branches/v1.7-stable/modulesrc/mpi/mpi_reduce.i
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/modulesrc/mpi/mpi_reduce.i (rev 0)
+++ short/3D/PyLith/branches/v1.7-stable/modulesrc/mpi/mpi_reduce.i 2012-08-20 17:12:38 UTC (rev 20608)
@@ -0,0 +1,78 @@
+// -*- 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-2012 University of California, Davis
+//
+// See COPYING for license information.
+//
+// ======================================================================
+//
+
+// ----------------------------------------------------------------------
+// MPI_SUM
+%inline %{
+ MPI_Op*
+ mpi_sum(void) {
+ return new MPI_Op(MPI_SUM);
+ } // mpi_sum
+%}
+
+
+// ----------------------------------------------------------------------
+// MPI_MIN
+%inline %{
+ MPI_Op*
+ mpi_min(void) {
+ return new MPI_Op(MPI_MIN);
+ } // mpi_min
+%}
+
+
+// ----------------------------------------------------------------------
+// MPI_AX
+%inline %{
+ MPI_Op*
+ mpi_max(void) {
+ return new MPI_Op(MPI_MAX);
+ } // mpi_max
+%}
+
+
+// ----------------------------------------------------------------------
+// allreduce_scalar_double
+%inline %{
+ double
+ allreduce_scalar_double(double value,
+ MPI_Op* op,
+ MPI_Comm* comm) {
+ double result = 0.0;
+ MPI_Allreduce(&value, &result, 1, MPI_DOUBLE, *op, *comm);
+ return result;
+ } // allreduce_scalar_double
+%}
+
+
+// ----------------------------------------------------------------------
+// allreduce_scalar_int
+%inline %{
+ int
+ allreduce_scalar_int(int value,
+ MPI_Op* op,
+ MPI_Comm* comm) {
+ int result = 0;
+ MPI_Allreduce(&value, &result, 1, MPI_INT, *op, *comm);
+ return result;
+ } // allreduce_int
+%}
+
+
+// End of file
+
Modified: short/3D/PyLith/branches/v1.7-stable/pylith/problems/TimeStep.py
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/pylith/problems/TimeStep.py 2012-08-20 16:41:27 UTC (rev 20607)
+++ short/3D/PyLith/branches/v1.7-stable/pylith/problems/TimeStep.py 2012-08-20 17:12:38 UTC (rev 20608)
@@ -186,7 +186,9 @@
dt = integrator.stableTimeStep(mesh)
if dt < dtStable:
dtStable = dt
-
+ import pylith.mpi.mpi as mpi
+ comm = mesh.getComm()
+ dtStableAll = mpi.allreduce_scalar_double(dtStable, mpi.mpi_min(), comm.handle)
return dtStable
Modified: short/3D/PyLith/branches/v1.7-stable/unittests/pytests/mpi/Makefile.am
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/unittests/pytests/mpi/Makefile.am 2012-08-20 16:41:27 UTC (rev 20607)
+++ short/3D/PyLith/branches/v1.7-stable/unittests/pytests/mpi/Makefile.am 2012-08-20 17:12:38 UTC (rev 20608)
@@ -25,7 +25,8 @@
TESTS_ENVIRONMENT = $(PYTHON)
noinst_PYTHON = \
- TestCommunicator.py
+ TestCommunicator.py \
+ TestReduce.py
# End of file
Added: short/3D/PyLith/branches/v1.7-stable/unittests/pytests/mpi/TestReduce.py
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/unittests/pytests/mpi/TestReduce.py (rev 0)
+++ short/3D/PyLith/branches/v1.7-stable/unittests/pytests/mpi/TestReduce.py 2012-08-20 17:12:38 UTC (rev 20608)
@@ -0,0 +1,66 @@
+#!/usr/bin/env python
+#
+# ======================================================================
+#
+# 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-2012 University of California, Davis
+#
+# See COPYING for license information.
+#
+# ======================================================================
+#
+
+## @file unittests/pytests/utils/TestReduce.py
+
+## @brief Unit testing of MPI reduce functions.
+
+import unittest
+
+import pylith.mpi.mpi as mpi
+
+# ----------------------------------------------------------------------
+class TestReduce(unittest.TestCase):
+ """
+ Unit testing of MPI reduce functions.
+ """
+
+
+ def test_allreduce_scalar_double(self):
+ """
+ Test allreduce_double().
+ """
+ value = 2.0
+ result = mpi.allreduce_scalar_double(value, mpi.mpi_sum(), mpi.petsc_comm_world())
+ self.assertEqual(value, result)
+
+ result = mpi.allreduce_scalar_double(value, mpi.mpi_min(), mpi.petsc_comm_self())
+ self.assertEqual(value, result)
+
+ result = mpi.allreduce_scalar_double(value, mpi.mpi_max(), mpi.petsc_comm_world())
+ self.assertEqual(value, result)
+ return
+
+
+ def test_allreduce_scalar_int(self):
+ """
+ Test allreduce_int().
+ """
+ value = 3
+ result = mpi.allreduce_scalar_int(value, mpi.mpi_sum(), mpi.petsc_comm_world())
+ self.assertEqual(value, result)
+
+ result = mpi.allreduce_scalar_int(value, mpi.mpi_min(), mpi.petsc_comm_self())
+ self.assertEqual(value, result)
+
+ result = mpi.allreduce_scalar_int(value, mpi.mpi_max(), mpi.petsc_comm_world())
+ self.assertEqual(value, result)
+ return
+
+
+# End of file
Modified: short/3D/PyLith/branches/v1.7-stable/unittests/pytests/mpi/testmpi.py
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/unittests/pytests/mpi/testmpi.py 2012-08-20 16:41:27 UTC (rev 20607)
+++ short/3D/PyLith/branches/v1.7-stable/unittests/pytests/mpi/testmpi.py 2012-08-20 17:12:38 UTC (rev 20608)
@@ -65,6 +65,9 @@
from TestCommunicator import TestCommunicator
suite.addTest(unittest.makeSuite(TestCommunicator))
+ from TestReduce import TestReduce
+ suite.addTest(unittest.makeSuite(TestReduce))
+
return suite
Modified: short/3D/PyLith/branches/v1.7-stable/unittests/pytests/problems/TestTimeStepAdapt.py
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/unittests/pytests/problems/TestTimeStepAdapt.py 2012-08-20 16:41:27 UTC (rev 20607)
+++ short/3D/PyLith/branches/v1.7-stable/unittests/pytests/problems/TestTimeStepAdapt.py 2012-08-20 17:12:38 UTC (rev 20608)
@@ -91,8 +91,12 @@
tstep.adaptSkip = 2
integrators = [Integrator(2.0),
Integrator(0.5)]
- mesh = None
+ from pylith.topology.Mesh import Mesh
+ from pylith.mpi.Communicator import petsc_comm_world
+ mesh = Mesh()
+ mesh.setComm(petsc_comm_world())
+
# Set time step
dt = 0.5 / 2.0
self.assertEqual(dt, tstep.timeStep(mesh, integrators))
@@ -145,7 +149,12 @@
integrators = [Integrator(3.0),
Integrator(2.4)]
- mesh = None
+
+ from pylith.topology.Mesh import Mesh
+ from pylith.mpi.Communicator import petsc_comm_world
+ mesh = Mesh()
+ mesh.setComm(petsc_comm_world())
+
dt = 2.4 / 2.0
tstep.timeStep(mesh, integrators)
self.assertEqual(dt, tstep.currentStep())
Modified: short/3D/PyLith/branches/v1.7-stable/unittests/pytests/problems/TestTimeStepUniform.py
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/unittests/pytests/problems/TestTimeStepUniform.py 2012-08-20 16:41:27 UTC (rev 20607)
+++ short/3D/PyLith/branches/v1.7-stable/unittests/pytests/problems/TestTimeStepUniform.py 2012-08-20 17:12:38 UTC (rev 20608)
@@ -83,8 +83,12 @@
integrators = [Integrator(4.0),
Integrator(8.0)]
- mesh = None
+ from pylith.topology.Mesh import Mesh
+ from pylith.mpi.Communicator import petsc_comm_world
+ mesh = Mesh()
+ mesh.setComm(petsc_comm_world())
+
self.assertEqual(1.0, tstep.timeStep(mesh, integrators))
tstep.dtN = 0.5
Modified: short/3D/PyLith/branches/v1.7-stable/unittests/pytests/problems/TestTimeStepUser.py
===================================================================
--- short/3D/PyLith/branches/v1.7-stable/unittests/pytests/problems/TestTimeStepUser.py 2012-08-20 16:41:27 UTC (rev 20607)
+++ short/3D/PyLith/branches/v1.7-stable/unittests/pytests/problems/TestTimeStepUser.py 2012-08-20 17:12:38 UTC (rev 20608)
@@ -108,8 +108,12 @@
integrators = [Integrator(40.0),
Integrator(80.0)]
- mesh = None
+ from pylith.topology.Mesh import Mesh
+ from pylith.mpi.Communicator import petsc_comm_world
+ mesh = Mesh()
+ #mesh.setComm(petsc_comm_world())
+
self.assertEqual(step1, tstep.timeStep(mesh, integrators))
self.assertEqual(step2, tstep.timeStep(mesh, integrators))
self.assertEqual(step3, tstep.timeStep(mesh, integrators))
@@ -144,8 +148,12 @@
integrators = [Integrator(4.0),
Integrator(8.0)]
- mesh = None
+ from pylith.topology.Mesh import Mesh
+ from pylith.mpi.Communicator import petsc_comm_world
+ mesh = Mesh()
+ #mesh.setComm(petsc_comm_world())
+
tstep.timeStep(mesh, integrators)
stepE = 1.0 / 0.5 # Nondimensionalize
self.assertEqual(stepE, tstep.currentStep())
More information about the CIG-COMMITS
mailing list