2
########################################################
4
# Copyright (c) 2003-2010 by University of Queensland
5
# Earth Systems Science Computational Center (ESSCC)
6
# http://www.uq.edu.au/esscc
8
# Primary Business: Queensland, Australia
9
# Licensed under the Open Software License version 3.0
10
# http://www.opensource.org/licenses/osl-3.0.php
12
########################################################
14
__copyright__="""Copyright (c) 2003-2010 by University of Queensland
15
Earth Systems Science Computational Center (ESSCC)
16
http://www.uq.edu.au/esscc
17
Primary Business: Queensland, Australia"""
18
__license__="""Licensed under the Open Software License version 3.0
19
http://www.opensource.org/licenses/osl-3.0.php"""
20
__url__="https://launchpad.net/escript-finley"
24
TEST_STR="timing: per iteration step:"
26
HEADER="""from esys.escript import *
27
from esys.dudley import Rectangle,Brick
28
from esys.escript.linearPDEs import LinearPDE
36
setNumberOfThreads(%d)
39
DOM_2_1="dom=Rectangle(NE,NE,order=1, useFullElementOrder=False,optimize=OPTIMIZE)"
40
DOM_2_2="dom=Rectangle(NE,NE,order=2, useFullElementOrder=False,optimize=OPTIMIZE)"
41
DOM_3_1="dom=Brick(NE,NE,NE,order=1, useFullElementOrder=True,optimize=OPTIMIZE)"
42
DOM_3_2="dom=Brick(NE,NE,NE,order=2, useFullElementOrder=True,optimize=OPTIMIZE)"
44
TEST_2_s="""x=Solution(dom).getX()
45
u_ex=Scalar(0,Solution(dom))
46
u_ex=1.+2.*x[0]+3.*x[1]
47
g_ex=Data(0.,(2,),Solution(dom))
50
pde=LinearPDE(dom,numEquations=1)
52
pde.setValue(r=u_ex,q=mask)
53
pde.setValue(A=kronecker(2),y=inner(g_ex,dom.getNormal()))
55
TEST_2_v="""x=Solution(dom).getX()
56
x=Solution(dom).getX()
57
u_ex=Vector(0,Solution(dom))
58
u_ex[0]=1.+2.*x[0]+3.*x[1]
59
u_ex[1]=-1.+3.*x[0]+2.*x[1]
60
g_ex=Data(0.,(2,2),Solution(dom))
65
pde=LinearPDE(dom,numEquations=2)
67
pde.setValue(r=u_ex,q=mask*numarray.ones(2,))
68
A=Tensor4(0,Function(dom))
69
A[0,:,0,:]=kronecker(2)
70
A[1,:,1,:]=kronecker(2)
71
Y=Vector(0.,Function(dom))
72
Y[0]=u_ex[0]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG
73
Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG
74
pde.setValue(A=A, D=kronecker(2)*(FAC_DIAG-FAC_OFFDIAG)+numarray.ones((2,2))*FAC_OFFDIAG, Y=Y, y=matrixmult(g_ex,dom.getNormal()))
77
TEST_3_s="""x=Solution(dom).getX()
78
u_ex=1.+2.*x[0]+3.*x[1]+4.*x[2]
79
g_ex=Data(0.,(3,),Solution(dom))
83
pde=LinearPDE(dom,numEquations=1)
85
pde.setValue(r=u_ex,q=mask)
86
pde.setValue(A=kronecker(3),y=inner(g_ex,dom.getNormal()))
89
TEST_3_v="""x=Solution(dom).getX()
90
u_ex=Vector(0,Solution(dom))
91
u_ex[0]=1.+2.*x[0]+3.*x[1]+4.*x[2]
92
u_ex[1]=-1.+4.*x[0]+1.*x[1]-2.*x[2]
93
u_ex[2]=5.+8.*x[0]+4.*x[1]+5.*x[2]
94
g_ex=Data(0.,(3,3),Solution(dom))
104
pde=LinearPDE(dom,numEquations=3)
106
pde.setValue(r=u_ex,q=mask*numarray.ones(3,))
107
A=Tensor4(0,Function(dom))
108
A[0,:,0,:]=kronecker(3)
109
A[1,:,1,:]=kronecker(3)
110
A[2,:,2,:]=kronecker(3)
111
Y=Vector(0.,Function(dom))
112
Y[0]=u_ex[0]*FAC_DIAG+u_ex[2]*FAC_OFFDIAG+u_ex[1]*FAC_OFFDIAG
113
Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG+u_ex[2]*FAC_OFFDIAG
114
Y[2]=u_ex[2]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG+u_ex[0]*FAC_OFFDIAG
116
D=kronecker(3)*(FAC_DIAG-FAC_OFFDIAG)+numarray.ones((3,3))*FAC_OFFDIAG,
118
y=matrixmult(g_ex,dom.getNormal()))
121
SOLVE_AND_TEST="""pde.setTolerance(SOLVER_TOL)
122
pde.setSolverMethod(pde.PCG,pde.JACOBI)
123
pde.setSolverPackage(pde.PASO)
124
u=pde.getSolution(verbose=SOLVER_VERBOSE)
125
error=Lsup(u-u_ex)/Lsup(u_ex)
126
if error>REL_TOL*Lsup(u_ex): raise RuntimeError("solution error %s is too big."%error)
130
#for n in [10000, 50000, 100000]:
132
# for n in [1000, 10000]:
133
#for prop in [ (1,2), (2,2), (1,3), (2,3) ]:
134
for prop in [ (1,2), (1,3) ]:
135
for tp in [ "s", "v" ]:
137
prog=HEADER%NUM_THREADS
139
if isinstance(prop[0], int):
145
NE=int(float(n/q-1)**(1./dim)/o+0.5)
168
print "l= %d, dim= %d, type=%s, order=%s"%(q*(o*NE+1)**dim,dim,tp,o)
172
print >> file("__prog","w"), prog
173
# activate for dynamic
174
# for CHUNK in [1,10,100,1000,10000, 100000]:
175
# for CHUNK_PCG in [1,10,100,1000,10000, 100000]:
176
# activate for static
178
for CHUNK_PCG in [-1]:
179
if CHUNK*NUM_THREADS <= n and CHUNK_PCG*NUM_THREADS <=n:
181
for i in range(REPEAT):
182
os.system("export OMP_NUM_THREADS=%d;export PASO_CHUNK_SIZE_MVM=%d; export PASO_CHUNK_SIZE_PCG=%d; python __prog > __out;"%(NUM_THREADS,CHUNK,CHUNK_PCG))
183
out=file("__out","r").read()
184
for i in out.split("\n"):
185
if i.startswith(TEST_STR): time_per_iter+=float(i[len(TEST_STR):-3].strip())
186
print CHUNK,CHUNK_PCG,time_per_iter/REPEAT