/[escript]/trunk/dudley/test/python/time_chunks.py
ViewVC logotype

Contents of /trunk/dudley/test/python/time_chunks.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4576 - (show annotations)
Mon Dec 9 23:35:30 2013 UTC (4 years, 8 months ago) by sshaw
File MIME type: text/x-python
File size: 5690 byte(s)
python3ified things, replaced mixed whitespace and xrange calls
1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2013 by University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development since 2012 by School of Earth Sciences
13 #
14 ##############################################################################
15
16 __copyright__="""Copyright (c) 2003-2013 by University of Queensland
17 http://www.uq.edu.au
18 Primary Business: Queensland, Australia"""
19 __license__="""Licensed under the Open Software License version 3.0
20 http://www.opensource.org/licenses/osl-3.0.php"""
21 __url__="https://launchpad.net/escript-finley"
22
23 NUM_THREADS=8
24 import os
25 TEST_STR="timing: per iteration step:"
26 REPEAT=10
27 HEADER="""from esys.escript import *
28 from esys.dudley import Rectangle,Brick
29 from esys.escript.linearPDEs import LinearPDE
30 SOLVER_TOL=1.e-2
31 REL_TOL=1.
32 OPTIMIZE=False
33 SOLVER_VERBOSE=True
34 FAC_DIAG=1.
35 FAC_OFFDIAG=-0.4
36
37 setNumberOfThreads(%d)
38 """
39
40 DOM_2_1="dom=Rectangle(NE,NE,order=1, useFullElementOrder=False,optimize=OPTIMIZE)"
41 DOM_2_2="dom=Rectangle(NE,NE,order=2, useFullElementOrder=False,optimize=OPTIMIZE)"
42 DOM_3_1="dom=Brick(NE,NE,NE,order=1, useFullElementOrder=True,optimize=OPTIMIZE)"
43 DOM_3_2="dom=Brick(NE,NE,NE,order=2, useFullElementOrder=True,optimize=OPTIMIZE)"
44
45 TEST_2_s="""x=Solution(dom).getX()
46 u_ex=Scalar(0,Solution(dom))
47 u_ex=1.+2.*x[0]+3.*x[1]
48 g_ex=Data(0.,(2,),Solution(dom))
49 g_ex[0]=2.
50 g_ex[1]=3.
51 pde=LinearPDE(dom,numEquations=1)
52 mask=whereZero(x[0])
53 pde.setValue(r=u_ex,q=mask)
54 pde.setValue(A=kronecker(2),y=inner(g_ex,dom.getNormal()))
55 """
56 TEST_2_v="""x=Solution(dom).getX()
57 x=Solution(dom).getX()
58 u_ex=Vector(0,Solution(dom))
59 u_ex[0]=1.+2.*x[0]+3.*x[1]
60 u_ex[1]=-1.+3.*x[0]+2.*x[1]
61 g_ex=Data(0.,(2,2),Solution(dom))
62 g_ex[0,0]=2.
63 g_ex[0,1]=3.
64 g_ex[1,0]=3.
65 g_ex[1,1]=2.
66 pde=LinearPDE(dom,numEquations=2)
67 mask=whereZero(x[0])
68 pde.setValue(r=u_ex,q=mask*numarray.ones(2,))
69 A=Tensor4(0,Function(dom))
70 A[0,:,0,:]=kronecker(2)
71 A[1,:,1,:]=kronecker(2)
72 Y=Vector(0.,Function(dom))
73 Y[0]=u_ex[0]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG
74 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG
75 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()))
76 """
77
78 TEST_3_s="""x=Solution(dom).getX()
79 u_ex=1.+2.*x[0]+3.*x[1]+4.*x[2]
80 g_ex=Data(0.,(3,),Solution(dom))
81 g_ex[0]=2.
82 g_ex[1]=3.
83 g_ex[2]=4.
84 pde=LinearPDE(dom,numEquations=1)
85 mask=whereZero(x[0])
86 pde.setValue(r=u_ex,q=mask)
87 pde.setValue(A=kronecker(3),y=inner(g_ex,dom.getNormal()))
88 """
89
90 TEST_3_v="""x=Solution(dom).getX()
91 u_ex=Vector(0,Solution(dom))
92 u_ex[0]=1.+2.*x[0]+3.*x[1]+4.*x[2]
93 u_ex[1]=-1.+4.*x[0]+1.*x[1]-2.*x[2]
94 u_ex[2]=5.+8.*x[0]+4.*x[1]+5.*x[2]
95 g_ex=Data(0.,(3,3),Solution(dom))
96 g_ex[0,0]=2.
97 g_ex[0,1]=3.
98 g_ex[0,2]=4.
99 g_ex[1,0]=4.
100 g_ex[1,1]=1.
101 g_ex[1,2]=-2.
102 g_ex[2,0]=8.
103 g_ex[2,1]=4.
104 g_ex[2,2]=5.
105 pde=LinearPDE(dom,numEquations=3)
106 mask=whereZero(x[0])
107 pde.setValue(r=u_ex,q=mask*numarray.ones(3,))
108 A=Tensor4(0,Function(dom))
109 A[0,:,0,:]=kronecker(3)
110 A[1,:,1,:]=kronecker(3)
111 A[2,:,2,:]=kronecker(3)
112 Y=Vector(0.,Function(dom))
113 Y[0]=u_ex[0]*FAC_DIAG+u_ex[2]*FAC_OFFDIAG+u_ex[1]*FAC_OFFDIAG
114 Y[1]=u_ex[1]*FAC_DIAG+u_ex[0]*FAC_OFFDIAG+u_ex[2]*FAC_OFFDIAG
115 Y[2]=u_ex[2]*FAC_DIAG+u_ex[1]*FAC_OFFDIAG+u_ex[0]*FAC_OFFDIAG
116 pde.setValue(A=A,
117 D=kronecker(3)*(FAC_DIAG-FAC_OFFDIAG)+numarray.ones((3,3))*FAC_OFFDIAG,
118 Y=Y,
119 y=matrixmult(g_ex,dom.getNormal()))
120 """
121
122 SOLVE_AND_TEST="""pde.setTolerance(SOLVER_TOL)
123 pde.setSolverMethod(pde.PCG,pde.JACOBI)
124 pde.setSolverPackage(pde.PASO)
125 u=pde.getSolution(verbose=SOLVER_VERBOSE)
126 error=Lsup(u-u_ex)/Lsup(u_ex)
127 if error>REL_TOL*Lsup(u_ex): raise RuntimeError("solution error %s is too big."%error)
128 """
129
130
131 #for n in [10000, 50000, 100000]:
132 for n in [100000]:
133 # for n in [1000, 10000]:
134 #for prop in [ (1,2), (2,2), (1,3), (2,3) ]:
135 for prop in [ (1,2), (1,3) ]:
136 for tp in [ "s", "v" ]:
137 # create code:
138 prog=HEADER%NUM_THREADS
139 dim=prop[1]
140 if isinstance(prop[0], int):
141 o=prop[0]
142 if tp=="s":
143 q=1
144 else:
145 q=dim
146 NE=int(float(n/q-1)**(1./dim)/o+0.5)
147 prog+="NE=%d\n"%NE
148 if dim==2:
149 if o==1:
150 prog+=DOM_2_1
151 else:
152 prog+=DOM_2_2
153 else:
154 if o==1:
155 prog+=DOM_3_1
156 else:
157 prog+=DOM_3_2
158 prog+="\n"
159 if dim==2:
160 if tp =="s":
161 prog+=TEST_2_s
162 else:
163 prog+=TEST_2_v
164 else:
165 if tp =="s":
166 prog+=TEST_3_s
167 else:
168 prog+=TEST_3_v
169 print("l= %d, dim= %d, type=%s, order=%s"%(q*(o*NE+1)**dim,dim,tp,o))
170
171 prog+=SOLVE_AND_TEST
172 # run code:
173 print(prog, file=file("__prog","w"))
174 # activate for dynamic
175 # for CHUNK in [1,10,100,1000,10000, 100000]:
176 # for CHUNK_PCG in [1,10,100,1000,10000, 100000]:
177 # activate for static
178 for CHUNK in [-1]:
179 for CHUNK_PCG in [-1]:
180 if CHUNK*NUM_THREADS <= n and CHUNK_PCG*NUM_THREADS <=n:
181 time_per_iter=0
182 for i in range(REPEAT):
183 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))
184 out=file("__out","r").read()
185 for i in out.split("\n"):
186 if i.startswith(TEST_STR): time_per_iter+=float(i[len(TEST_STR):-3].strip())
187 print(CHUNK,CHUNK_PCG,time_per_iter/REPEAT)
188

  ViewVC Help
Powered by ViewVC 1.1.26