def lhs_overhead(self, a, bcs=None, N=1000): A = assemble(a, bcs=bcs) A.M tic('matrix assembly') for _ in range(N): assemble(a, tensor=A, bcs=bcs).M return toc('matrix assembly')/N
def timestep_iteration(): # Advection if have_advection: tic('advection') tic('assembly') mat.zero() op2.par_loop( mass, elements(3, 3), mat((elem_node[op2.i[0]], elem_node[op2.i[1]]), op2.INC), coords(elem_node, op2.READ)) op2.par_loop(zero_dat, nodes, b(op2.IdentityMap, op2.WRITE)) op2.par_loop(adv_rhs, elements(3), b(elem_node[op2.i[0]], op2.INC), coords(elem_node, op2.READ), tracer(elem_node, op2.READ), velocity(elem_node, op2.READ)) toc('assembly') tic('solve') op2.solve(mat, tracer, b) toc('solve') toc('advection') # Diffusion if have_diffusion: tic('diffusion') tic('assembly') mat.zero() op2.par_loop( diff_matrix, elements(3, 3), mat((elem_node[op2.i[0]], elem_node[op2.i[1]]), op2.INC), coords(elem_node, op2.READ)) op2.par_loop(zero_dat, nodes, b(op2.IdentityMap, op2.WRITE)) op2.par_loop(diff_rhs, elements(3), b(elem_node[op2.i[0]], op2.INC), coords(elem_node, op2.READ), tracer(elem_node, op2.READ)) toc('assembly') tic('solve') op2.solve(mat, tracer, b) toc('solve') toc('diffusion')
def test_reset_timers(self): tic('test_reset') toc('test_reset') reset_timers() assert get_timers().keys() == []
def test_create(self): tic('create') toc('create') assert 'create' in get_timers().keys()
def test_reset(self): tic("test_reset") toc("test_reset") reset() assert get_timers().keys() == []
def test_create(self): tic("create") toc("create") assert "create" in get_timers().keys()
def rhs_ffc_overhead(self, L, bcs=None, N=1000): tic('rhs assembly') for _ in range(N): # Need to create new copies of the forms, since kernels are cached assemble(copy(L), bcs=bcs).dat.data_ro return toc('rhs assembly')/N
def rhs_overhead(self, L, bcs=None, N=1000): b = assemble(L, bcs=bcs) tic('rhs assembly') for _ in range(N): assemble(L, tensor=b, bcs=bcs).dat.data_ro return toc('rhs assembly')/N
def lhs_ffc_overhead(self, a, bcs=None, N=1000): tic('matrix assembly') for _ in range(N): # Need to create new copies of the forms, since kernels are cached assemble(copy(a), bcs=bcs).M return toc('matrix assembly')/N
def wave(self, scale=1.0, lump_mass=True, N=100, save=False, weak=False, verbose=False, measure_overhead=False): if weak: self.series['weak'] = scale scale = round(scale/sqrt(op2.MPI.comm.size), 3) self.meta['scale'] = scale else: self.series['scale'] = scale self.meta['cells'] = cells[scale] self.meta['vertices'] = vertices[scale] if measure_overhead: mesh = UnitSquareMesh(1, 1) else: t_, mesh = self.make_mesh(scale) self.register_timing('mesh', t_) with self.timed_region('setup'): V = FunctionSpace(mesh, 'Lagrange', 1) total_dofs = np.zeros(1, dtype=int) op2.MPI.comm.Allreduce(np.array([V.dof_dset.size], dtype=int), total_dofs) self.meta['dofs'] = total_dofs[0] if verbose: print '[%d]' % op2.MPI.comm.rank, 'DOFs:', V.dof_dset.size p = Function(V) phi = Function(V, name="phi") u = TrialFunction(V) v = TestFunction(V) bcval = Constant(0.0) bc = DirichletBC(V, bcval, 1) if lump_mass: Ml = assemble(1.0 / assemble(v*dx)) dt = 0.001 * scale dtc = Constant(dt) t = 0.0 rhs = inner(grad(v), grad(phi)) * dx if save: outfile = File("vtk/firedrake_wave_%s.pvd" % scale) outfile << phi b = assemble(rhs) dphi = 0.5 * dtc * p dp = dtc * Ml * b if measure_overhead: repeats = 1000 tic('phi') for _ in range(repeats): phi -= dphi phi.dat.data_ro phi_overhead = N*toc('phi')/repeats print "phi overhead:", phi_overhead tic('p') for _ in range(repeats): bcval.assign(sin(2*pi*5*_*dt)) assemble(rhs, tensor=b) p += dp bc.apply(p) p.dat.data_ro p_overhead = N*toc('p')/repeats print "p overhead:", p_overhead return phi_overhead, p_overhead with self.timed_region('timestepping'): while t < N*dt: bcval.assign(sin(2*pi*5*t)) with self.timed_region('phi'): phi -= dphi phi.dat.data_ro with self.timed_region('p'): if lump_mass: assemble(rhs, tensor=b) p += dp bc.apply(p) p.dat.data_ro else: solve(u * v * dx == v * p * dx + dtc * rhs, p, bcs=bc, solver_parameters={'ksp_type': 'cg', 'pc_type': 'sor', 'pc_sor_symmetric': True}) with self.timed_region('phi'): phi -= dphi phi.dat.data_ro t += dt if save: outfile << phi for task, timer in get_timers(reset=True).items(): self.register_timing(task, timer.total)
def timestep_iteration(): # Advection if have_advection: tic("advection") tic("assembly") mat.zero() op2.par_loop( mass, elements(3, 3), mat((elem_node[op2.i[0]], elem_node[op2.i[1]]), op2.INC), coords(elem_node, op2.READ), ) op2.par_loop(zero_dat, nodes, b(op2.IdentityMap, op2.WRITE)) op2.par_loop( adv_rhs, elements(3), b(elem_node[op2.i[0]], op2.INC), coords(elem_node, op2.READ), tracer(elem_node, op2.READ), velocity(elem_node, op2.READ), ) toc("assembly") tic("solve") op2.solve(mat, tracer, b) toc("solve") toc("advection") # Diffusion if have_diffusion: tic("diffusion") tic("assembly") mat.zero() op2.par_loop( diff_matrix, elements(3, 3), mat((elem_node[op2.i[0]], elem_node[op2.i[1]]), op2.INC), coords(elem_node, op2.READ), ) op2.par_loop(zero_dat, nodes, b(op2.IdentityMap, op2.WRITE)) op2.par_loop( diff_rhs, elements(3), b(elem_node[op2.i[0]], op2.INC), coords(elem_node, op2.READ), tracer(elem_node, op2.READ), ) toc("assembly") tic("solve") op2.solve(mat, tracer, b) toc("solve") toc("diffusion")