Commit 3e5c3215 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Use more fine-grained timing information in the FOF part of the code.

parent fc71d4df
......@@ -1842,8 +1842,9 @@ void engine_skip_drift(struct engine *e) {
* @brief Launch the runners.
*
* @param e The #engine.
* @param fof Are we launching the FOF tasks or the regular tasks?
*/
void engine_launch(struct engine *e) {
void engine_launch(struct engine *e, const int fof) {
const ticks tic = getticks();
#ifdef SWIFT_DEBUG_CHECKS
......@@ -1869,9 +1870,14 @@ void engine_launch(struct engine *e) {
/* Sit back and wait for the runners to come home. */
swift_barrier_wait(&e->wait_barrier);
if (e->verbose)
message("took %.3f %s.", clocks_from_ticks(getticks() - tic),
clocks_getunit());
if (e->verbose) {
if (fof)
message("(fof) took %.3f %s.", clocks_from_ticks(getticks() - tic),
clocks_getunit());
else
message("(tasks) took %.3f %s.", clocks_from_ticks(getticks() - tic),
clocks_getunit());
}
}
/**
......@@ -1958,7 +1964,7 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs,
/* Now, launch the calculation */
TIMER_TIC;
engine_launch(e);
engine_launch(e, /*fof=*/0);
TIMER_TOC(timer_runners);
/* Apply some conversions (e.g. internal energy -> entropy) */
......@@ -1972,7 +1978,7 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs,
if (hydro_need_extra_init_loop) {
engine_marktasks(e);
engine_skip_force_and_kick(e);
engine_launch(e);
engine_launch(e, /*fof=*/0);
}
}
......@@ -2020,7 +2026,7 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs,
/* Run the 0th time-step */
TIMER_TIC2;
engine_launch(e);
engine_launch(e, /*fof=*/0);
TIMER_TOC2(timer_runners);
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
......@@ -2318,7 +2324,7 @@ void engine_step(struct engine *e) {
/* Start all the tasks. */
TIMER_TIC;
engine_launch(e);
engine_launch(e, /*fof=*/0);
TIMER_TOC(timer_runners);
#ifdef SWIFT_GRAVITY_FORCE_CHECKS
......
......@@ -519,7 +519,7 @@ void engine_config(int restart, int fof, struct engine *e,
int nr_threads, int with_aff, int verbose,
const char *restart_file);
void engine_dump_index(struct engine *e);
void engine_launch(struct engine *e);
void engine_launch(struct engine *e, const int fof);
void engine_prepare(struct engine *e);
void engine_init_particles(struct engine *e, int flag_entropy_ICs,
int clean_h_values);
......
......@@ -123,8 +123,11 @@ void engine_fof(struct engine *e, const int dump_results,
/* and activate them. */
engine_activate_fof_tasks(e);
/* Print the number of active tasks ? */
if (e->verbose) engine_print_task_counts(e);
/* Perform local FOF tasks. */
engine_launch(e);
engine_launch(e, /*fof=*/1);
/* Perform FOF search over foreign particles and
* find groups which require black hole seeding. */
......
......@@ -3119,8 +3119,8 @@ void engine_make_fof_tasks(struct engine *e) {
e->sched.size * sizeof(struct task) / (1024 * 1024));
if (e->verbose)
message("took %.3f %s (including reweight).",
clocks_from_ticks(getticks() - tic), clocks_getunit());
message("took %.3f %s.", clocks_from_ticks(getticks() - tic),
clocks_getunit());
}
/**
......
......@@ -246,6 +246,7 @@ void fof_allocate(const struct space *s, const long long total_nr_DM_particles,
struct fof_props *props) {
const int verbose = s->e->verbose;
const ticks total_tic = getticks();
/* Start by computing the mean inter DM particle separation */
......@@ -343,6 +344,10 @@ void fof_allocate(const struct space *s, const long long total_nr_DM_particles,
#ifdef SWIFT_DEBUG_CHECKS
ti_current = s->e->ti_current;
#endif
if (verbose)
message("took %.3f %s.", clocks_from_ticks(getticks() - total_tic),
clocks_getunit());
}
/**
......@@ -2303,7 +2308,7 @@ void fof_search_foreign_cells(struct fof_props *props, const struct space *s) {
tic = getticks();
/* Perform send and receive tasks. */
engine_launch(e);
engine_launch(e, /*fof=*/1);
if (verbose)
message("MPI send/recv comms took: %.3f %s.",
......@@ -2974,8 +2979,8 @@ void fof_search_tree(struct fof_props *props,
message("Largest group by size: %d", max_group_size);
}
if (verbose)
message("FOF search took: %.3f %s.",
clocks_from_ticks(getticks() - tic_total), clocks_getunit());
message("took %.3f %s.", clocks_from_ticks(getticks() - tic_total),
clocks_getunit());
#ifdef WITH_MPI
MPI_Barrier(MPI_COMM_WORLD);
......
......@@ -45,6 +45,7 @@ params = {
"lines.markersize": 6,
"lines.linewidth": 3.0,
"text.latex.unicode": True,
'hatch.linewidth': 4
}
rcParams.update(params)
......@@ -68,7 +69,6 @@ labels = [
["Counting and linking tasks", 1],
["Setting super-pointers", 1],
["Making extra hydroloop tasks", 1],
["Making extra starsloop tasks", 1],
["Linking gravity tasks", 1],
["Creating send tasks", 1],
["Exchanging cell tags", 1],
......@@ -83,7 +83,7 @@ labels = [
["engine_drift_all:", 0],
["engine_unskip:", 0],
["engine_collect_end_of_step:", 0],
["engine_launch:", 0],
["engine_launch: \(tasks\)", 0],
["writing particle properties", 0],
["engine_repartition:", 0],
["engine_exchange_cells:", 1],
......@@ -98,10 +98,15 @@ labels = [
["space_init", 0],
["engine_init", 0],
["engine_repartition_trigger:", 0],
["VR Collecting top-level cell info", 0],
["VR Collecting particle info", 0],
["VR Invokation of velociraptor", 0],
["VR Copying group information back", 0]
["VR Collecting top-level cell info", 3],
["VR Collecting particle info", 3],
["VR Invokation of velociraptor", 3],
["VR Copying group information back", 3],
["fof_allocate:", 2],
["engine_make_fof_tasks:", 2],
["engine_activate_fof_tasks:", 2],
["fof_search_tree:", 2],
["engine_launch: \(fof\)", 2],
]
times = np.zeros(len(labels))
counts = np.zeros(len(labels))
......@@ -142,6 +147,7 @@ for i in range(num_files):
# Extract the different blocks
if re.search("%s took" % labels[i][0], line):
counts[i] += 1.0
times[i] += float(
re.findall(r"[+-]?((\d+\.?\d*)|(\.\d+))", line)[-1][0]
......@@ -184,10 +190,16 @@ counts = counts[order]
time_ratios = time_ratios[order]
labels = [labels[i] for i in order]
# Remove the regexp escapes to make the labels prettier
for i in range(len(labels)):
labels[i][0] = labels[i][0].replace("\\","")
# Keep only the important components
important_times = [0.0]
important_ratios = [0.0]
important_is_rebuild = [0]
important_is_fof = [0]
important_is_VR = [0]
important_labels = ["Others (all below %.1f\%%)" % (threshold * 100)]
need_print = True
print("Time spent in the different code sections:")
......@@ -195,7 +207,9 @@ for i in range(len(labels)):
if time_ratios[i] > threshold:
important_times.append(times[i])
important_ratios.append(time_ratios[i])
important_is_rebuild.append(labels[i][1])
important_is_rebuild.append(labels[i][1] == 1)
important_is_fof.append(labels[i][1] == 2)
important_is_VR.append(labels[i][1] == 3)
important_labels.append(labels[i][0])
else:
if need_print:
......@@ -232,6 +246,19 @@ pie, _, _ = pie(
startangle=-15,
colors=cols,
)
# Use hashing for the FOF and VR wedges
for i in range(len(pie)):
if (important_is_fof[i]):
pie[i].set_hatch('o')
pie[i].set_edgecolor(pie[i].get_facecolor())
pie[i].set_fill(False)
for i in range(len(pie)):
if (important_is_VR[i]):
pie[i].set_hatch('+')
pie[i].set_edgecolor(pie[i].get_facecolor())
pie[i].set_fill(False)
legend(pie, important_labels, title="SWIFT operations", loc="upper left")
savefig("time_pie.pdf", dpi=150)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment