diff --git a/README b/README index bec538bfc35239945d60487d66ed2e02b5d363a2..6e2b2cb2304aaa1790646de5316b7c08362779bf 100644 --- a/README +++ b/README @@ -31,6 +31,7 @@ Valid options are: -s Run with hydrodynamics. -S Run with stars. -t {int} The number of threads to use on each MPI rank. Defaults to 1 if not specified. + -T Print timers every time-step. -v [12] Increase the level of verbosity 1: MPI-rank 0 writes 2: All MPI-ranks write diff --git a/examples/main.c b/examples/main.c index 2b741f75b236de9a3d64d382c442d4f53713e1b2..5f42f3e06ea46d0c3b73363956f470016e5d1498 100644 --- a/examples/main.c +++ b/examples/main.c @@ -90,6 +90,7 @@ void print_help_message() { printf(" %2s %8s %s\n", "-t", "{int}", "The number of threads to use on each MPI rank. Defaults to 1 if not " "specified."); + printf(" %2s %8s %s\n", "-T", "", "Print timers every time-step."); printf(" %2s %8s %s\n", "-v", "[12]", "Increase the level of verbosity."); printf(" %2s %8s %s\n", "", "", "1: MPI-rank 0 writes "); printf(" %2s %8s %s\n", "", "", "2: All MPI-ranks write"); @@ -165,12 +166,13 @@ int main(int argc, char *argv[]) { int with_drift_all = 0; int verbose = 0; int nr_threads = 1; + int with_verbose_timers = 0; char paramFileName[200] = ""; unsigned long long cpufreq = 0; /* Parse the parameters */ int c; - while ((c = getopt(argc, argv, "acCdDef:FgGhn:sSt:v:y:")) != -1) switch (c) { + while ((c = getopt(argc, argv, "acCdDef:FgGhn:sSt:Tv:y:")) != -1) switch (c) { case 'a': with_aff = 1; break; @@ -229,6 +231,9 @@ int main(int argc, char *argv[]) { return 1; } break; + case 'T': + with_verbose_timers = 1; + break; case 'v': if (sscanf(optarg, "%d", &verbose) != 1) { if (myrank == 0) printf("Error parsing verbosity level (-v).\n"); @@ -596,11 +601,18 @@ int main(int argc, char *argv[]) { engine_dump_snapshot(&e); /* Legend */ - if (myrank == 0) + if (myrank == 0) { printf("# %6s %14s %14s %10s %10s %10s %16s [%s]\n", "Step", "Time", "Time-step", "Updates", "g-Updates", "s-Updates", "Wall-clock time", clocks_getunit()); + if (with_verbose_timers) { + printf("timers: "); + for (int k = 0; k < timer_count; k++) printf("%s\t", timers_names[k]); + printf("\n"); + } + } + /* Main simulation loop */ for (int j = 0; !engine_is_done(&e) && e.step - 1 != nsteps; j++) { @@ -610,6 +622,15 @@ int main(int argc, char *argv[]) { /* Take a step. */ engine_step(&e); + /* Print the timers. */ + if (with_verbose_timers) { + printf("timers: "); + for (int k = 0; k < timer_count; k++) + printf("%.3f\t", clocks_from_ticks(timers[k])); + printf("\n"); + timers_reset(0xFFFFFFFFllu); + } + #ifdef SWIFT_DEBUG_TASKS /* Dump the task data using the given frequency. */ if (dump_tasks && (dump_tasks == 1 || j % dump_tasks == 1)) { diff --git a/src/timers.c b/src/timers.c index c2f3b35d75ea340082acf1a5ec334bb3543bab12..9b6b32251d8efd2890ed3855b5e9b87c15978784 100644 --- a/src/timers.c +++ b/src/timers.c @@ -29,6 +29,53 @@ /* The timers. */ ticks timers[timer_count]; +/* Timer names. */ +char *timers_names[timer_count] = { + "none", + "prepare", + "init", + "drift", + "kick1", + "kick2", + "timestep", + "endforce", + "dosort", + "doself_density", + "doself_gradient", + "doself_force", + "doself_grav_pp", + "dopair_density", + "dopair_gradient", + "dopair_force", + "dopair_grav_pm", + "dopair_grav_mm", + "dopair_grav_pp", + "dograv_external", + "dograv_down", + "dograv_long_range", + "dosource", + "dosub_self_density", + "dosub_self_gradient", + "dosub_self_force", + "dosub_self_grav", + "dosub_pair_density", + "dosub_pair_gradient", + "dosub_pair_force", + "dosub_pair_grav", + "dopair_subset", + "do_ghost", + "do_extra_ghost", + "dorecv_part", + "dorecv_gpart", + "dorecv_spart", + "gettask", + "qget", + "qsteal", + "runners", + "step", + "do_cooling", +}; + /** * @brief Re-set the timers. * diff --git a/src/timers.h b/src/timers.h index 39bcf30fba0ec36d9209ddcbf3c71035a5851dbb..d4bfedaa0a11a02b8244ab78645a9502226ef6da 100644 --- a/src/timers.h +++ b/src/timers.h @@ -27,7 +27,12 @@ #include "cycle.h" #include "inline.h" -/* The timers themselves. */ +/** + * @brief The timers themselves. + * + * If you modify this list, be sure to change timers_names in timers.c as + * well! + **/ enum { timer_none = 0, timer_prepare, @@ -78,6 +83,9 @@ enum { /* The timers. */ extern ticks timers[timer_count]; +/* The timer names. */ +extern char *timers_names[]; + /* Mask for all timers. */ #define timers_mask_all ((1ull << timer_count) - 1)