Reference on kuibit.cactus_timers¶
The cactus_timers
module provides an interface to Cactus timers.
Currently, the only timers supported are from the XML output by Carpet with the
option output_xml_timer_tree = yes
.
The main class defined in this module is TimersDir
. This is a
dictionary-like object that contains most of the information available in the
timers. The keys of this class are the various MPI ranks (ie, process numbers)
found in the output. The value are Tree
objects. These trees
contain the reported call-stack of the simulation with the associated timing
information. Simulation restarts are summed up. Often, it is useful to know how
much a function took on average across different MPI ranks. This can be accessed
with the TimerDir.average()
method.
Example of usage:
# Assuming sim is a SimDir
avg_timers = sim.timers.average
# avg_timers.name contains the name of the top level function, main
# avg_timers.value contains the time took on average by such function
# avg_timers.children contains a tuple with all the functions called by main.
# The type of these functions is Tree, so they have a name and value attribute.
# By default, the units are second. If you want to normalize to 1 and get the
# percentual value, you can use
normalized_avg_timers = avg_timers / avg_timers.tot_value_leaves
print(normalized_avg_timers.value) # Should be 1
# Another useful feature is to represent the timer tree with a dictionary or a
# json file, for postprocessing
print(normalized_avg_timers.to_json())
- class kuibit.cactus_timers.TimersDir(sd)[source]¶
Timer information read from Carpet.
This is a dictionary-like object that has as keys the process number and as values the timer information represented as a
Tree
object.Timers are summed up across different restarts.
The most useful method in this class is
average()
, which returns the average timing information across all the MPI ranks.Files are read only when needed. At the moment, only XML timers are supported, but different backends can be added.
Constructor.