Permalink
Browse files

enabled "mpiexec -n $np nosetests" by creating get_global_q()

Note, a lot of parallel apps are broken, and we're going to need to debug them
  • Loading branch information...
1 parent 53b584c commit 581d48763c76c4116adb5839880646cb2535a839 @ahmadia committed Apr 22, 2012
@@ -10,11 +10,20 @@ def verify_expected(expected):
def acoustics_verify(claw):
from clawpack.pyclaw.util import check_diff
import numpy as np
- q0=claw.frames[0].state.q.reshape([-1])
- qfinal=claw.frames[claw.num_output_times].state.q.reshape([-1])
- dx=claw.solution.domain.grid.delta[0]
- test = dx*np.sum(np.abs(qfinal-q0))
- return check_diff(expected, test, abstol=1e-5)
+
+ # tests are done across the entire domain of q normally
+ q0=claw.frames[0].state.get_q_global()
+ qfinal=claw.frames[claw.num_output_times].state.get_q_global()
+
+ # and q_global is only returned on process 0
+ if q0 != None and qfinal != None:
+ q0 = q0.reshape([-1])
+ qfinal = qfinal.reshape([-1])
+ dx=claw.solution.domain.grid.delta[0]
+ test = dx*np.sum(np.abs(qfinal-q0))
+ return check_diff(expected, test, abstol=1e-5)
+ else:
+ return
return acoustics_verify
from clawpack.pyclaw.util import gen_variants
@@ -75,8 +75,7 @@ def acoustics2D(iplot=False,kernel_language='Fortran',htmlplot=False,use_petsc=F
if htmlplot: pyclaw.plot.html_plot(outdir=outdir,file_format=claw.output_format)
if iplot: pyclaw.plot.interactive_plot(outdir=outdir,file_format=claw.output_format)
- pressure=claw.frames[claw.num_output_times].state.q[0,:,:]
- return pressure
+ return claw.frames[claw.num_output_times].state
def qinit(state,width=0.2):
@@ -2,16 +2,25 @@ def test_2d_acoustics():
"""test_2d_acoustics"""
def verify_data(data_filename):
- def verify(test_pressure):
+ def verify(test_state):
+ """ verifies 2d homogeneous acoustics from a previously verified run """
import os
import numpy as np
from clawpack.pyclaw.util import check_diff
- """ verifies 2d homogeneous acoustics from a previously verified run """
- thisdir = os.path.dirname(__file__)
- expected_pressure = np.loadtxt(os.path.join(thisdir,data_filename))
- test_err = np.linalg.norm(expected_pressure-test_pressure)
- expected_err = 0
- return check_diff(expected_err, test_err, abstol=1e-4)
+
+
+ #grabs parallel results to process 0, None to other processes
+ test_q=test_state.get_q_global()
+
+ if test_q is not None:
+ test_pressure = test_q[0,:,:]
+ thisdir = os.path.dirname(__file__)
+ expected_pressure = np.loadtxt(os.path.join(thisdir,data_filename))
+ test_err = np.linalg.norm(expected_pressure-test_pressure)
+ expected_err = 0
+ return check_diff(expected_err, test_err, abstol=1e-4)
+ else:
+ return
return verify
from clawpack.pyclaw.util import gen_variants
@@ -117,25 +117,32 @@ def acoustics3D(iplot=False,htmlplot=False,use_petsc=False,outdir='./_output',so
if htmlplot: pyclaw.plot.html_plot(outdir=outdir,file_format=claw.output_format)
if iplot: pyclaw.plot.interactive_plot(outdir=outdir,file_format=claw.output_format)
+ pinitial=claw.frames[0].state.get_q_global()
+ pmiddle =claw.frames[3].state.get_q_global()
+ pfinal =claw.frames[claw.num_output_times].state.get_q_global()
- pinitial=claw.frames[0].state.q[0,:,:,:].reshape(-1)
- pmiddle =claw.frames[3].state.q[0,:,:,:].reshape(-1)
- pfinal =claw.frames[claw.num_output_times].state.q[0,:,:,:].reshape(-1)
+ if pinitial != None and pmiddle != None and pfinal != None:
+ pinitial =pinitial[0,:,:,:].reshape(-1)
+ pmiddle =pmiddle[0,:,:,:].reshape(-1)
+ pfinal =pfinal[0,:,:,:].reshape(-1)
+ final_difference =np.prod(grid.delta)*np.linalg.norm(pfinal-pinitial,ord=1)
+ middle_difference=np.prod(grid.delta)*np.linalg.norm(pmiddle-pinitial,ord=1)
- #import matplotlib.pyplot as plt
- #for i in range(claw.num_output_times):
- # plt.pcolor(claw.frames[i].state.q[0,:,:,mz/2])
- # plt.figure()
- #plt.show()
+ if app == None:
+ print 'Final error: ', final_difference
+ print 'Middle error: ', middle_difference
- final_difference =np.prod(grid.delta)*np.linalg.norm(pfinal-pinitial,ord=1)
- middle_difference=np.prod(grid.delta)*np.linalg.norm(pmiddle-pinitial,ord=1)
+ #import matplotlib.pyplot as plt
+ #for i in range(claw.num_output_times):
+ # plt.pcolor(claw.frames[i].state.q[0,:,:,mz/2])
+ # plt.figure()
+ #plt.show()
- if app == None:
- print 'Final error: ', final_difference
- print 'Middle error: ', middle_difference
+ return pfinal, final_difference
- return pfinal, final_difference
+ else:
+
+ return
if __name__=="__main__":
import sys
@@ -4,19 +4,23 @@ def test_3d_acoustics():
def acoustics_verify_homogeneous(return_tuple):
from clawpack.pyclaw.util import check_diff
- test_final_difference = return_tuple[1]
- return check_diff(0.00286, test_final_difference, abstol=1e-4)
+ if return_tuple != None:
+ test_final_difference = return_tuple[1]
+ return check_diff(0.00286, test_final_difference, abstol=1e-4)
+ return
def acoustics_verify_heterogeneous(return_tuple):
import os
import numpy as np
from clawpack.pyclaw.util import check_diff
- test_pfinal = return_tuple[0]
- thisdir = os.path.dirname(__file__)
- verify_pfinal = np.loadtxt(os.path.join(thisdir,'verify_classic_heterogeneous.txt'))
- norm_err = np.linalg.norm(test_pfinal-verify_pfinal)
- return check_diff(0, norm_err, abstol=1e-4)
+ if return_tuple != None:
+ test_pfinal = return_tuple[0]
+ thisdir = os.path.dirname(__file__)
+ verify_pfinal = np.loadtxt(os.path.join(thisdir,'verify_classic_heterogeneous.txt'))
+ norm_err = np.linalg.norm(test_pfinal-verify_pfinal)
+ return check_diff(0, norm_err, abstol=1e-4)
+ return
from clawpack.pyclaw.util import gen_variants
from acoustics import acoustics3D
@@ -205,10 +205,7 @@ def shockbubble(use_petsc=False,kernel_language='Fortran',solver_type='classic',
if htmlplot: pyclaw.plot.html_plot(file_format=claw.output_format)
if iplot: pyclaw.plot.interactive_plot(file_format=claw.output_format)
- density=claw.frames[claw.num_output_times].state.q[0,:,:]
- return density
-
-
+ return claw.frames[claw.num_output_times].state
if __name__=="__main__":
from pyclaw.util import run_app_from_main
@@ -1,15 +1,21 @@
def test_2d_euler_shockbubble():
"""test_2d_euler_shockbubble"""
- def verify_classic_shockbubble(test_density):
+ def verify_classic_shockbubble(test_state):
import os
from clawpack.pyclaw.util import check_diff
import numpy as np
""" verifies 2d euler shockbubble from a previously verified classic run """
- thisdir = os.path.dirname(__file__)
- expected_density = np.loadtxt(os.path.join(thisdir,'verify_shockbubble_classic.txt'))
- test_err = np.linalg.norm(expected_density-test_density)
- expected_err = 0
- return check_diff(expected_err, test_err, abstol=1e-12)
+
+ test_q=test_state.get_q_global()
+
+
+ if test_q != None:
+ thisdir = os.path.dirname(__file__)
+ expected_density = np.loadtxt(os.path.join(thisdir,'verify_shockbubble_classic.txt'))
+ test_density = test_q[0,:,:]
+ test_err = np.linalg.norm(expected_density-test_density)
+ expected_err = 0
+ return check_diff(expected_err, test_err, abstol=1e-12)
from shockbubble import shockbubble
from clawpack.pyclaw.util import gen_variants
View
@@ -276,3 +276,23 @@ def set_num_ghost(self,num_ghost):
def sum_F(self,i):
return self.gFVec.strideNorm(i,0)
+
+ def get_q_global(self):
+ r"""
+ Returns a copy of the global q array on process 0, otherwise returns None
+ """
+ from petsc4py import PETSc
+ scatter, q0Vec = PETSc.Scatter.toZero(self.gqVec)
+ scatter.scatter(self.gqVec, q0Vec, False, PETSc.Scatter.Mode.FORWARD)
+ rank = PETSc.COMM_WORLD.getRank()
+ if rank == 0:
+ shape = self.patch.num_cells_global
+ shape.insert(0,self.num_eqn)
+ q0=q0Vec.getArray().reshape(shape, order = 'F').copy()
+ else:
+ q0=None
+
+ scatter.destroy()
+ q0Vec.destroy()
+
+ return q0
View
@@ -247,6 +247,11 @@ def new_array(self,dof):
shape.extend(self.grid.num_cells)
return np.empty(shape,order='F')
+ def get_q_global(self):
+ r"""
+ Returns a copy of the global q array
+ """
+ return self.q.copy()
if __name__ == "__main__":
import doctest
View
@@ -90,8 +90,20 @@ def test_app_variants(application, verifier, python_kernel, **kwargs):
def test_app(application, verifier, kwargs):
print kwargs
+
+ if 'use_petsc' in kwargs and not kwargs['use_petsc']:
+ try:
+ # don't duplicate serial test runs
+ from petsc4py import PETSc
+ rank = PETSc.COMM_WORLD.getRank()
+ if rank != 0:
+ return
+ except ImportError, e:
+ pass
+
output = application(**kwargs)
check_values = verifier(output)
+
if check_values is not None:
import inspect
err = \

0 comments on commit 581d487

Please sign in to comment.