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)