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

  ViewVC Help
Powered by ViewVC 1.1.26