How do I use list_timings()?

Hello,

When I run the following command at the end of my program list_timings(), I get the following error.

TypeError: list_timings(): incompatible function arguments. The following argument types are supported:
    1. (arg0: dolfin.cpp.common.TimingClear, arg1: List[dolfin.cpp.common.TimingType]) -> None

What is the right way to use list_timings()? Thanks!

Minimal example:

from dolfin import *
import numpy as np
import matplotlib.pyplot as plt

mesh = UnitSquareMesh(8, 8)
V = FunctionSpace(mesh, 'P', 1)

# Define boundary condition
u_D = Expression('1 + x[0]*x[0] + 2*x[1]*x[1]', degree=2)

def boundary(x, on_boundary):
    return on_boundary

bc = DirichletBC(V, u_D, boundary)

# Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(-6.0)
a = dot(grad(u), grad(v))*dx
L = f*v*dx

# Compute solution
u = Function(V)
solve(a == L, u, bc)

# Plot solution and mesh
plot(u)

list_timings()

E.g.

list_timings(TimingClear.clear, [TimingType.wall])
1 Like

Hello, i’m looking for a way to save the output of list_timings and other useful logging info to a file. I found this outdated method on the old Forum: https://fenicsproject.org/qa/13524/redirect-dolfin-output-to-file/. Thanks in advance!

What’s wrong with the answer in the link you’ve provided? Is there something else you want to achieve?

time_table = timings(TimingClear.keep, [TimingType.wall])
with open("timings.log", "w") as out:
    out.write(time_table.str(True))

The problem was that I used list_timings(), rather than just timings() as in your example. The former method prints to the terminal, but returns time_table=None. Thanks for the help!

Hi there,

I am trying to do the same in dolfinx, but from what I can tell the functions timings() or dump_timings_to_xml() are not defined?

What would you suggest as the best equivalent?

Many thanks

You have two different options when it comes to timings in DOLFINx, you can either: List them as a table in terminal with dolfinx.common.list_timings: dolfinx/common.py at c2d1e71f1f9ac84bbf4c1fa81a8305f3ad043249 · FEniCS/dolfinx · GitHub
You can also simply call dolfinx.common.timing("name_of_task") (dolfinx/common.py at c2d1e71f1f9ac84bbf4c1fa81a8305f3ad043249 · FEniCS/dolfinx · GitHub) to get the local timing data per process, and the post-process it as you would like to (do MPI.min/max/avg/sum) and save it to whatever file format you would like.

The main reason for not having a convenience function list all tasks is that the timing system is used internally in the code for developers to make sure the code is scalable, and a lot of the output is not meaningful for the general user.

1 Like

Thanks a lot for your quick reply!