Skip to content

Commit 7ac03c4

Browse files
author
Michael Zingale
committed
enclassify the profile stuff -- there is now a TimerCollection that
holds instances of the Timer class.
1 parent 85c6a58 commit 7ac03c4

File tree

7 files changed

+148
-114
lines changed

7 files changed

+148
-114
lines changed

advection/simulation.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
from advection.problems import *
55
from advectiveFluxes import *
66
import mesh.patch as patch
7+
from util import profile
78

89
class Simulation:
910

10-
def __init__(self, problem_name, rp):
11+
def __init__(self, problem_name, rp, timers=None):
1112

1213
self.rp = rp
1314
self.cc_data = None
@@ -16,6 +17,12 @@ def __init__(self, problem_name, rp):
1617

1718
self.problem_name = problem_name
1819

20+
if timers == None:
21+
self.tc = profile.TimerCollection()
22+
else:
23+
self.tc = timers
24+
25+
1926

2027
def initialize(self):
2128
"""

compressible/simulation.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, idens=-1, ixmom=-1, iymom=-1, iener=-1):
3434

3535
class Simulation:
3636

37-
def __init__(self, problem_name, rp):
37+
def __init__(self, problem_name, rp, timers=None):
3838

3939
self.rp = rp
4040
self.cc_data = None
@@ -44,6 +44,11 @@ def __init__(self, problem_name, rp):
4444

4545
self.SMALL = 1.e-12
4646

47+
if timers == None:
48+
self.tc = profile.TimerCollection()
49+
else:
50+
self.tc = timers
51+
4752

4853
def initialize(self):
4954
"""
@@ -183,8 +188,8 @@ def evolve(self, dt):
183188
Evolve the equations of compressible hydrodynamics through a timestep dt
184189
"""
185190

186-
pf = profile.timer("evolve")
187-
pf.begin()
191+
tm_evolve = self.tc.timer("evolve")
192+
tm_evolve.begin()
188193

189194
dens = self.cc_data.get_var("density")
190195
xmom = self.cc_data.get_var("x-momentum")
@@ -195,7 +200,7 @@ def evolve(self, dt):
195200

196201
myg = self.cc_data.grid
197202

198-
Flux_x, Flux_y = unsplitFluxes(self.cc_data, self.rp, self.vars, dt)
203+
Flux_x, Flux_y = unsplitFluxes(self.cc_data, self.rp, self.vars, self.tc, dt)
199204

200205
old_dens = dens.copy()
201206
old_ymom = ymom.copy()
@@ -217,7 +222,7 @@ def evolve(self, dt):
217222
ymom += 0.5*dt*(dens + old_dens)*grav
218223
ener += 0.5*dt*(ymom + old_ymom)*grav
219224

220-
pf.end()
225+
tm_evolve.end()
221226

222227

223228
def dovis(self, n):

compressible/unsplitFluxes.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,8 @@
129129
import eos
130130
import interface_f
131131
import mesh.reconstruction_f as reconstruction_f
132-
from util import profile
133132

134-
def unsplitFluxes(my_data, rp, vars, dt):
133+
def unsplitFluxes(my_data, rp, vars, tc, dt):
135134
"""
136135
unsplitFluxes returns the fluxes through the x and y interfaces by
137136
doing an unsplit reconstruction of the interface values and then
@@ -142,8 +141,8 @@ def unsplitFluxes(my_data, rp, vars, dt):
142141
grav is the gravitational acceleration in the y-direction
143142
"""
144143

145-
pf = profile.timer("unsplitFluxes")
146-
pf.begin()
144+
tm_flux = tc.timer("unsplitFluxes")
145+
tm_flux.begin()
147146

148147
myg = my_data.grid
149148

@@ -197,8 +196,8 @@ def unsplitFluxes(my_data, rp, vars, dt):
197196
#=========================================================================
198197

199198
# monotonized central differences in x-direction
200-
pfa = profile.timer("limiting")
201-
pfa.begin()
199+
tm_limit = tc.timer("limiting")
200+
tm_limit.begin()
202201

203202
limiter = rp.get_param("compressible.limiter")
204203
if limiter == 0:
@@ -213,11 +212,11 @@ def unsplitFluxes(my_data, rp, vars, dt):
213212
ldelta_v = xi*limitFunc(1, v, myg.qx, myg.qy, myg.ng)
214213
ldelta_p = xi*limitFunc(1, p, myg.qx, myg.qy, myg.ng)
215214

216-
pfa.end()
215+
tm_limit.end()
217216

218217
# left and right primitive variable states
219-
pfb = profile.timer("interfaceStates")
220-
pfb.begin()
218+
tm_states = tc.timer("interfaceStates")
219+
tm_states.begin()
221220

222221
gamma = rp.get_param("eos.gamma")
223222

@@ -230,7 +229,7 @@ def unsplitFluxes(my_data, rp, vars, dt):
230229
r, u, v, p,
231230
ldelta_r, ldelta_u, ldelta_v, ldelta_p)
232231

233-
pfb.end()
232+
tm_states.end()
234233

235234

236235
# transform interface states back into conserved variables
@@ -256,25 +255,25 @@ def unsplitFluxes(my_data, rp, vars, dt):
256255
#=========================================================================
257256

258257
# monotonized central differences in y-direction
259-
pfa.begin()
258+
tm_limit.begin()
260259

261260
ldelta_r = xi*limitFunc(2, r, myg.qx, myg.qy, myg.ng)
262261
ldelta_u = xi*limitFunc(2, u, myg.qx, myg.qy, myg.ng)
263262
ldelta_v = xi*limitFunc(2, v, myg.qx, myg.qy, myg.ng)
264263
ldelta_p = xi*limitFunc(2, p, myg.qx, myg.qy, myg.ng)
265264

266-
pfa.end()
265+
tm_limit.end()
267266

268267
# left and right primitive variable states
269-
pfb.begin()
268+
tm_states.begin()
270269

271270
V_l, V_r = interface_f.states(2, myg.qx, myg.qy, myg.ng, myg.dy, dt,
272271
vars.nvar,
273272
gamma,
274273
r, u, v, p,
275274
ldelta_r, ldelta_u, ldelta_v, ldelta_p)
276275

277-
pfb.end()
276+
tm_states.end()
278277

279278

280279
# transform interface states back into conserved variables
@@ -331,8 +330,8 @@ def unsplitFluxes(my_data, rp, vars, dt):
331330
#=========================================================================
332331
# compute transverse fluxes
333332
#=========================================================================
334-
pfc = profile.timer("riemann")
335-
pfc.begin()
333+
tm_riem = tc.timer("riemann")
334+
tm_riem.begin()
336335

337336
riemann = rp.get_param("compressible.riemann")
338337

@@ -352,7 +351,7 @@ def unsplitFluxes(my_data, rp, vars, dt):
352351
vars.nvar, vars.idens, vars.ixmom, vars.iymom, vars.iener,
353352
gamma, U_yl, U_yr)
354353

355-
pfc.end()
354+
tm_riem.end()
356355

357356
#=========================================================================
358357
# construct the interface values of U now
@@ -401,8 +400,8 @@ def unsplitFluxes(my_data, rp, vars, dt):
401400
402401
"""
403402

404-
pfd = profile.timer("transverse flux addition")
405-
pfd.begin()
403+
tm_transverse = tc.timer("transverse flux addition")
404+
tm_transverse.begin()
406405

407406
# U_xl[i,j,:] = U_xl[i,j,:] - 0.5*dt/dy * (F_y[i-1,j+1,:] - F_y[i-1,j,:])
408407
U_xl[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,:] += \
@@ -424,7 +423,7 @@ def unsplitFluxes(my_data, rp, vars, dt):
424423
- 0.5*dt/myg.dx * (F_x[myg.ilo-1:myg.ihi+3,myg.jlo-2:myg.jhi+2,:] - \
425424
F_x[myg.ilo-2:myg.ihi+2,myg.jlo-2:myg.jhi+2,:])
426425

427-
pfd.end()
426+
tm_transverse.end()
428427

429428

430429
#=========================================================================
@@ -434,7 +433,7 @@ def unsplitFluxes(my_data, rp, vars, dt):
434433
# up until now, F_x and F_y stored the transverse fluxes, now we
435434
# overwrite with the fluxes normal to the interfaces
436435

437-
pfc.begin()
436+
tm_riem.begin()
438437

439438
F_x = riemannFunc(1, myg.qx, myg.qy, myg.ng,
440439
vars.nvar, vars.idens, vars.ixmom, vars.iymom, vars.iener,
@@ -444,7 +443,7 @@ def unsplitFluxes(my_data, rp, vars, dt):
444443
vars.nvar, vars.idens, vars.ixmom, vars.iymom, vars.iener,
445444
gamma, U_yl, U_yr)
446445

447-
pfc.end()
446+
tm_riem.end()
448447

449448
#=========================================================================
450449
# apply artificial viscosity
@@ -500,7 +499,7 @@ def unsplitFluxes(my_data, rp, vars, dt):
500499

501500

502501

503-
pf.end()
502+
tm_flux.end()
504503

505504
return F_x, F_y
506505

diffusion/simulation.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@
44
from diffusion.problems import *
55
import mesh.patch as patch
66
import multigrid.multigrid as multigrid
7-
from util import msg, runparams
7+
from util import msg, profile, runparams
88

99
class Simulation:
1010

11-
def __init__(self, problem_name, rp):
11+
def __init__(self, problem_name, rp, timers=None):
1212

1313
self.rp = rp
1414
self.cc_data = None
1515

1616
self.problem_name = problem_name
1717

18+
if timers == None:
19+
self.tc = profile.TimerCollection()
20+
else:
21+
self.tc = timers
22+
1823

1924
def initialize(self):
2025
"""

incompressible/simulation.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@
66
import mesh.reconstruction_f as reconstruction_f
77
import mesh.patch as patch
88
import multigrid.multigrid as multigrid
9+
from util import profile
910

1011
class Simulation:
1112

12-
def __init__(self, problem_name, rp):
13+
def __init__(self, problem_name, rp, timers=None):
1314

1415
self.rp = rp
1516
self.cc_data = None
1617

1718
self.problem_name = problem_name
1819

20+
if timers == None:
21+
self.tc = profile.TimerCollection()
22+
else:
23+
self.tc = timers
24+
1925

2026
def initialize(self):
2127
"""

pyro.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import getopt
44
import os
55
import sys
6-
import time
76

87
import numpy
98
import pylab
@@ -54,8 +53,10 @@
5453

5554
msg.bold('pyro ...')
5655

57-
pf = profile.timer("main")
58-
pf.begin()
56+
tc = profile.TimerCollection()
57+
58+
tm_main = tc.timer("main")
59+
tm_main.begin()
5960

6061
#-----------------------------------------------------------------------------
6162
# command line arguments / solver setup
@@ -151,7 +152,7 @@
151152

152153
# initialize the Simulation object -- this will hold the grid and data and
153154
# know about the runtime parameters and which problem we are running
154-
sim = solver.Simulation(problem_name, rp)
155+
sim = solver.Simulation(problem_name, rp, timers=tc)
155156

156157
sim.initialize()
157158
sim.preevolve()
@@ -186,10 +187,10 @@
186187
while sim.cc_data.t < tmax and n < max_steps:
187188

188189
# fill boundary conditions
189-
pfb = profile.timer("fill_bc")
190-
pfb.begin()
190+
tm_bc = tc.timer("fill_bc")
191+
tm_bc.begin()
191192
sim.cc_data.fill_BC_all()
192-
pfb.end()
193+
tm_bc.end()
193194

194195
# get the timestep
195196
dt = sim.timestep()
@@ -222,21 +223,21 @@
222223

223224
if sim.cc_data.t >= (nout + 1)*dt_out or n%n_out == 0:
224225

225-
pfc = profile.timer("output")
226-
pfc.begin()
226+
tm_io = tc.timer("output")
227+
tm_io.begin()
227228

228229
msg.warning("outputting...")
229230
basename = rp.get_param("io.basename")
230231
sim.cc_data.write(basename + "%4.4d" % (n))
231232
nout += 1
232233

233-
pfc.end()
234+
tm_io.end()
234235

235236

236237
# visualization
237238
if dovis:
238-
pfd = profile.timer("vis")
239-
pfd.begin()
239+
tm_vis = tc.timer("vis")
240+
tm_vis.begin()
240241

241242
sim.dovis(n)
242243
store = rp.get_param("vis.store_images")
@@ -245,9 +246,9 @@
245246
basename = rp.get_param("io.basename")
246247
pylab.savefig(basename + "%4.4d" % (n) + ".png")
247248

248-
pfd.end()
249+
tm_vis.end()
249250

250-
pf.end()
251+
tm_main.end()
251252

252253

253254
#-----------------------------------------------------------------------------
@@ -278,7 +279,7 @@
278279
# final reports
279280
#-----------------------------------------------------------------------------
280281
rp.print_unused_params()
281-
profile.timeReport()
282+
tc.report()
282283

283284
sim.finalize()
284285

0 commit comments

Comments
 (0)