~vcs-imports/escript-finley/trunk

« back to all changes in this revision

Viewing changes to dudley/test/python/time_chunks.py

  • Committer: jfenwick
  • Date: 2010-10-11 01:48:14 UTC
  • Revision ID: svn-v4:77569008-7704-0410-b7a0-a92fef0b09fd:trunk:3259
Merging dudley and scons updates from branches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
########################################################
 
3
#
 
4
# Copyright (c) 2003-2010 by University of Queensland
 
5
# Earth Systems Science Computational Center (ESSCC)
 
6
# http://www.uq.edu.au/esscc
 
7
#
 
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
 
11
#
 
12
########################################################
 
13
 
 
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"
 
21
 
 
22
NUM_THREADS=8
 
23
import os
 
24
TEST_STR="timing: per iteration step:"
 
25
REPEAT=10
 
26
HEADER="""from esys.escript import *
 
27
from esys.dudley import Rectangle,Brick 
 
28
from esys.escript.linearPDEs import LinearPDE 
 
29
SOLVER_TOL=1.e-2
 
30
REL_TOL=1.
 
31
OPTIMIZE=False 
 
32
SOLVER_VERBOSE=True
 
33
FAC_DIAG=1.
 
34
FAC_OFFDIAG=-0.4
 
35
 
 
36
setNumberOfThreads(%d)
 
37
"""
 
38
 
 
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)"
 
43
 
 
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))
 
48
g_ex[0]=2.
 
49
g_ex[1]=3.
 
50
pde=LinearPDE(dom,numEquations=1)
 
51
mask=whereZero(x[0])
 
52
pde.setValue(r=u_ex,q=mask)
 
53
pde.setValue(A=kronecker(2),y=inner(g_ex,dom.getNormal()))
 
54
"""
 
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))
 
61
g_ex[0,0]=2.
 
62
g_ex[0,1]=3.
 
63
g_ex[1,0]=3.
 
64
g_ex[1,1]=2.
 
65
pde=LinearPDE(dom,numEquations=2)
 
66
mask=whereZero(x[0])
 
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()))
 
75
"""
 
76
 
 
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))
 
80
g_ex[0]=2.
 
81
g_ex[1]=3.
 
82
g_ex[2]=4.
 
83
pde=LinearPDE(dom,numEquations=1)
 
84
mask=whereZero(x[0])
 
85
pde.setValue(r=u_ex,q=mask)
 
86
pde.setValue(A=kronecker(3),y=inner(g_ex,dom.getNormal()))
 
87
"""
 
88
 
 
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))
 
95
g_ex[0,0]=2.
 
96
g_ex[0,1]=3.
 
97
g_ex[0,2]=4.
 
98
g_ex[1,0]=4.
 
99
g_ex[1,1]=1.
 
100
g_ex[1,2]=-2.
 
101
g_ex[2,0]=8.
 
102
g_ex[2,1]=4.
 
103
g_ex[2,2]=5.
 
104
pde=LinearPDE(dom,numEquations=3)
 
105
mask=whereZero(x[0])
 
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
 
115
pde.setValue(A=A,
 
116
D=kronecker(3)*(FAC_DIAG-FAC_OFFDIAG)+numarray.ones((3,3))*FAC_OFFDIAG,
 
117
Y=Y,
 
118
y=matrixmult(g_ex,dom.getNormal()))
 
119
"""
 
120
 
 
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)
 
127
"""
 
128
 
 
129
 
 
130
#for n in [10000, 50000, 100000]:
 
131
for n in [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" ]:
 
136
      # create code:
 
137
      prog=HEADER%NUM_THREADS
 
138
      dim=prop[1]
 
139
      if isinstance(prop[0], int):
 
140
          o=prop[0]
 
141
          if tp=="s": 
 
142
                q=1
 
143
          else:
 
144
                q=dim
 
145
          NE=int(float(n/q-1)**(1./dim)/o+0.5)
 
146
          prog+="NE=%d\n"%NE
 
147
          if dim==2:
 
148
              if o==1:
 
149
                 prog+=DOM_2_1
 
150
              else:
 
151
                 prog+=DOM_2_2
 
152
          else:
 
153
              if o==1:
 
154
                 prog+=DOM_3_1
 
155
              else:
 
156
                 prog+=DOM_3_2
 
157
          prog+="\n"
 
158
      if dim==2:
 
159
        if tp =="s":
 
160
           prog+=TEST_2_s
 
161
        else:
 
162
           prog+=TEST_2_v
 
163
      else:
 
164
        if tp =="s":
 
165
           prog+=TEST_3_s
 
166
        else:
 
167
           prog+=TEST_3_v
 
168
      print "l= %d, dim= %d, type=%s, order=%s"%(q*(o*NE+1)**dim,dim,tp,o)
 
169
    
 
170
      prog+=SOLVE_AND_TEST 
 
171
      # run code:
 
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
 
177
      for CHUNK in [-1]:
 
178
       for CHUNK_PCG in [-1]:
 
179
        if CHUNK*NUM_THREADS <= n and CHUNK_PCG*NUM_THREADS <=n:
 
180
         time_per_iter=0
 
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
 
187