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

Annotation of /trunk/finley/test/python/time_chunks.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6651 - (hide annotations)
Wed Feb 7 02:12:08 2018 UTC (2 years, 8 months ago) by jfenwick
File MIME type: text/x-python
File size: 5795 byte(s)
Make everyone sad by touching all the files

Copyright dates update

1 ksteube 1811
2 jfenwick 3981 ##############################################################################
3 ksteube 1811 #
4 jfenwick 6651 # Copyright (c) 2003-2018 by The University of Queensland
5 jfenwick 3981 # http://www.uq.edu.au
6 ksteube 1811 #
7     # Primary Business: Queensland, Australia
8 jfenwick 6112 # Licensed under the Apache License, version 2.0
9     # http://www.apache.org/licenses/LICENSE-2.0
10 ksteube 1811 #
11 jfenwick 3981 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 jfenwick 4657 # Development 2012-2013 by School of Earth Sciences
13     # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 jfenwick 3981 #
15     ##############################################################################
16 ksteube 1811
17 sshaw 5706 from __future__ import print_function, division
18 sshaw 5017
19 jfenwick 6651 __copyright__="""Copyright (c) 2003-2018 by The University of Queensland
20 jfenwick 3981 http://www.uq.edu.au
21 ksteube 1811 Primary Business: Queensland, Australia"""
22 jfenwick 6112 __license__="""Licensed under the Apache License, version 2.0
23     http://www.apache.org/licenses/LICENSE-2.0"""
24 jfenwick 2344 __url__="https://launchpad.net/escript-finley"
25 ksteube 1811
26 gross 1565 NUM_THREADS=8
27 gross 1564 import os
28     TEST_STR="timing: per iteration step:"
29     REPEAT=10
30     HEADER="""from esys.escript import *
31     from esys.finley import Rectangle,Brick
32     from esys.escript.linearPDEs import LinearPDE
33 gross 1570 SOLVER_TOL=1.e-2
34     REL_TOL=1.
35 gross 1564 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 gross 1573 #for n in [10000, 50000, 100000]:
135     for n in [100000]:
136 gross 1565 # for n in [1000, 10000]:
137 gross 1566 #for prop in [ (1,2), (2,2), (1,3), (2,3) ]:
138     for prop in [ (1,2), (1,3) ]:
139 gross 1564 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 gross 1566 if tp=="s":
146 sshaw 4576 q=1
147     else:
148     q=dim
149 gross 1573 NE=int(float(n/q-1)**(1./dim)/o+0.5)
150 gross 1564 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 jfenwick 3772 print("l= %d, dim= %d, type=%s, order=%s"%(q*(o*NE+1)**dim,dim,tp,o))
173 gross 1564
174     prog+=SOLVE_AND_TEST
175     # run code:
176 jfenwick 3772 print(prog, file=file("__prog","w"))
177 gross 1573 # 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 gross 1570 if CHUNK*NUM_THREADS <= n and CHUNK_PCG*NUM_THREADS <=n:
184 gross 1564 time_per_iter=0
185     for i in range(REPEAT):
186 gross 1570 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 gross 1564 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 jfenwick 3772 print(CHUNK,CHUNK_PCG,time_per_iter/REPEAT)
191 gross 1564

  ViewVC Help
Powered by ViewVC 1.1.26