This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

MPIRUN timing

0 votes

My question concerns MPI execution timing. Specifically is there a way to time the functions assemble_system and ksp.solve in the attached code? I am running it with mpirun -np 2 ..

from dolfin import *
import petsc4py
import sys
petsc4py.init(sys.argv)
from petsc4py import PETSc

parameters['linear_algebra_backend'] = 'PETSc'
parameters["form_compiler"]["optimize"]     = True
parameters["form_compiler"]["cpp_optimize"] = True
parameters["form_compiler"]["representation"] = "quadrature"
parameters['reorder_dofs_serial'] = False

n = int(2**4)
mesh = UnitCubeMesh(n,n,n)

V = VectorFunctionSpace(mesh, "CG", 2)
v = TestFunction(V)
u = TrialFunction(V)

class r0(Expression):
    def __init__(self):
        self.M = 1
    def eval_cell(self, values, x, ufc_cell):
        values[0] = 1.
        values[1] = 1.
        values[2] = 1.
    def value_shape(self):
        return (3,)
f = r0()
a = inner(grad(u),grad(v))*dx
l = inner(f,v)*dx
def boundary(x, on_boundary):
    return on_boundary

A = PETScMatrix()
b = PETScVector()
bc = DirichletBC(V,f, boundary)
assemble_system(a, l, bc, A_tensor = A, b_tensor = b)

A_petsc = A.mat()
b_petsc = b.vec()
u = b_petsc.duplicate()
ksp = PETSc.KSP()
ksp.create(comm=PETSc.COMM_WORLD)
pc = ksp.getPC()
ksp.setType('cg')
pc.setType('gamg')
ksp.setFromOptions()
scale = b_petsc.norm()
b_petsc = b_petsc/scale
ksp.setOperators(A_petsc,A_petsc)
ksp.solve(b_petsc,u)
asked Apr 26, 2016 by mwathen FEniCS Novice (710 points)

1 Answer

0 votes

You can use Timer and list_timings. For example:

...
t0 = Timer("assemble_system")
assemble_system(a, l, bc, A_tensor = A, b_tensor = b)
del(t0)
...
t0 = Timer("ksp.solve")
ksp.solve(b_petsc,u)
del(t0)
list_timings()
answered Apr 27, 2016 by johannr FEniCS Expert (17,350 points)

That worked great, thanks!

Do you know if there is a way just to show these timing results without the rest from list_timings()?

I don't know if you can do that with list_timings. How about using Timer.elapsed or Timer.stop?

...