From 10c4e03d80afbe39fc3ceefabe50770726c0e6bf Mon Sep 17 00:00:00 2001 From: James Willis <james.s.willis@durham.ac.uk> Date: Tue, 6 Dec 2016 12:13:52 +0000 Subject: [PATCH] Formatting. --- src/engine.c | 2 +- src/profiler.c | 192 ++++++++++++++++++++++++++++++------------------- src/profiler.h | 19 ++--- src/swift.h | 2 +- 4 files changed, 132 insertions(+), 83 deletions(-) diff --git a/src/engine.c b/src/engine.c index 41dbafbf2f..d604042fff 100644 --- a/src/engine.c +++ b/src/engine.c @@ -59,6 +59,7 @@ #include "parallel_io.h" #include "part.h" #include "partition.h" +#include "profiler.h" #include "proxy.h" #include "runner.h" #include "serial_io.h" @@ -68,7 +69,6 @@ #include "tools.h" #include "units.h" #include "version.h" -#include "profiler.h" const char *engine_policy_names[16] = {"none", "rand", diff --git a/src/profiler.c b/src/profiler.c index 5ddd12eee9..8f396e4bf4 100644 --- a/src/profiler.c +++ b/src/profiler.c @@ -34,17 +34,18 @@ /** * @brief Resets all timers. * - * @param (return) profiler #profiler object that holds file pointers and function timers. - */ + * @param (return) profiler #profiler object that holds file pointers and + * function timers. + */ void profiler_reset_timers(struct profiler *profiler) { profiler->collect_timesteps_time = 0; profiler->drift_time = 0; profiler->rebuild_time = 0; - profiler->reweight_time = 0; - profiler->clear_waits_time = 0; - profiler->re_wait_time = 0; - profiler->enqueue_time = 0; + profiler->reweight_time = 0; + profiler->clear_waits_time = 0; + profiler->re_wait_time = 0; + profiler->enqueue_time = 0; profiler->stats_time = 0; profiler->launch_time = 0; profiler->space_rebuild_time = 0; @@ -64,58 +65,82 @@ void profiler_reset_timers(struct profiler *profiler) { * @param fileName name of file to be written to. * @param functionName name of function that is being timed. * @param (return) file pointer used to open output file. - */ -void profiler_write_timing_info_header(struct engine *e, char *fileName, char *functionName, FILE **file) { + */ +void profiler_write_timing_info_header(struct engine *e, char *fileName, + char *functionName, FILE **file) { /* Create the file name in the format: "fileName_(no. of threads)" */ char fullFileName[200] = ""; - sprintf(fullFileName + strlen(fullFileName), "%s_%d.txt", fileName, e->nr_nodes * e->nr_threads); + sprintf(fullFileName + strlen(fullFileName), "%s_%d.txt", fileName, + e->nr_nodes * e->nr_threads); /* Open the file and write the header. */ *file = fopen(fullFileName, "w"); fprintf(*file, - "# Host: %s\n# Branch: %s\n# Revision: %s\n# Compiler: %s, " - "Version: %s \n# " - "Number of threads: %d\n# Number of MPI ranks: %d\n# Hydrodynamic " - "scheme: %s\n# Hydrodynamic kernel: %s\n# No. of neighbours: %.2f " - "+/- %.2f\n# Eta: %f\n" - "# %6s %14s %14s %10s %10s %16s [%s]\n", - hostname(), functionName, git_revision(), compiler_name(), - compiler_version(), e->nr_threads, e->nr_nodes, SPH_IMPLEMENTATION, - kernel_name, e->hydro_properties->target_neighbours, - e->hydro_properties->delta_neighbours, - e->hydro_properties->eta_neighbours, - "Step","Time", "Time-step", "Updates", "g-Updates", "Wall-clock time", - clocks_getunit()); + "# Host: %s\n# Branch: %s\n# Revision: %s\n# Compiler: %s, " + "Version: %s \n# " + "Number of threads: %d\n# Number of MPI ranks: %d\n# Hydrodynamic " + "scheme: %s\n# Hydrodynamic kernel: %s\n# No. of neighbours: %.2f " + "+/- %.2f\n# Eta: %f\n" + "# %6s %14s %14s %10s %10s %16s [%s]\n", + hostname(), functionName, git_revision(), compiler_name(), + compiler_version(), e->nr_threads, e->nr_nodes, SPH_IMPLEMENTATION, + kernel_name, e->hydro_properties->target_neighbours, + e->hydro_properties->delta_neighbours, + e->hydro_properties->eta_neighbours, "Step", "Time", "Time-step", + "Updates", "g-Updates", "Wall-clock time", clocks_getunit()); fflush(*file); } /** - * @brief Writes the headers for all output files. Should be called once at the start of the simulation, it could be called in engine_init() for example. + * @brief Writes the headers for all output files. Should be called once at the + * start of the simulation, it could be called in engine_init() for example. * * @param e #engine object to get various properties. - * @param (return) profiler #profiler object that holds file pointers and function timers. - */ -void profiler_write_all_timing_info_headers(struct engine *e, struct profiler *profiler) { - - profiler_write_timing_info_header(e,"enginecollecttimesteps","engine_collect_timesteps",&profiler->file_engine_collect_timesteps); - profiler_write_timing_info_header(e,"enginedrift","engine_drift",&profiler->file_engine_drift); - profiler_write_timing_info_header(e,"enginerebuild","engine_rebuild",&profiler->file_engine_rebuild); - profiler_write_timing_info_header(e,"schedulerreweight","scheduler_reweight",&profiler->file_scheduler_reweight); - profiler_write_timing_info_header(e,"schedulerclearwaits","scheduler_clear_waits",&profiler->file_scheduler_clear_waits); - profiler_write_timing_info_header(e,"schedulerrewait","scheduler_rewait",&profiler->file_scheduler_re_wait); - profiler_write_timing_info_header(e,"schedulerenqueue","scheduler_enqueue",&profiler->file_scheduler_enqueue); - profiler_write_timing_info_header(e,"engineprintstats","engine_print_stats",&profiler->file_engine_stats); - profiler_write_timing_info_header(e,"enginelaunch","engine_launch",&profiler->file_engine_launch); - profiler_write_timing_info_header(e,"spacerebuild","space_rebuild",&profiler->file_space_rebuild); - profiler_write_timing_info_header(e,"enginemaketasks","engine_maketasks",&profiler->file_engine_maketasks); - profiler_write_timing_info_header(e,"enginemarktasks","engine_marktasks",&profiler->file_engine_marktasks); - profiler_write_timing_info_header(e,"spaceregrid","space_regrid",&profiler->file_space_regrid); - profiler_write_timing_info_header(e,"spacepartssort","space_parts_sort",&profiler->file_space_parts_sort); - profiler_write_timing_info_header(e,"spacesplit","space_split",&profiler->file_space_split); - profiler_write_timing_info_header(e,"spacegetcellid","space_get_cell_id",&profiler->file_space_parts_get_cell_id); - profiler_write_timing_info_header(e,"spacecountparts","space_count_parts",&profiler->file_space_count_parts); + * @param (return) profiler #profiler object that holds file pointers and + * function timers. + */ +void profiler_write_all_timing_info_headers(struct engine *e, + struct profiler *profiler) { + + profiler_write_timing_info_header(e, "enginecollecttimesteps", + "engine_collect_timesteps", + &profiler->file_engine_collect_timesteps); + profiler_write_timing_info_header(e, "enginedrift", "engine_drift", + &profiler->file_engine_drift); + profiler_write_timing_info_header(e, "enginerebuild", "engine_rebuild", + &profiler->file_engine_rebuild); + profiler_write_timing_info_header(e, "schedulerreweight", + "scheduler_reweight", + &profiler->file_scheduler_reweight); + profiler_write_timing_info_header(e, "schedulerclearwaits", + "scheduler_clear_waits", + &profiler->file_scheduler_clear_waits); + profiler_write_timing_info_header(e, "schedulerrewait", "scheduler_rewait", + &profiler->file_scheduler_re_wait); + profiler_write_timing_info_header(e, "schedulerenqueue", "scheduler_enqueue", + &profiler->file_scheduler_enqueue); + profiler_write_timing_info_header(e, "engineprintstats", "engine_print_stats", + &profiler->file_engine_stats); + profiler_write_timing_info_header(e, "enginelaunch", "engine_launch", + &profiler->file_engine_launch); + profiler_write_timing_info_header(e, "spacerebuild", "space_rebuild", + &profiler->file_space_rebuild); + profiler_write_timing_info_header(e, "enginemaketasks", "engine_maketasks", + &profiler->file_engine_maketasks); + profiler_write_timing_info_header(e, "enginemarktasks", "engine_marktasks", + &profiler->file_engine_marktasks); + profiler_write_timing_info_header(e, "spaceregrid", "space_regrid", + &profiler->file_space_regrid); + profiler_write_timing_info_header(e, "spacepartssort", "space_parts_sort", + &profiler->file_space_parts_sort); + profiler_write_timing_info_header(e, "spacesplit", "space_split", + &profiler->file_space_split); + profiler_write_timing_info_header(e, "spacegetcellid", "space_get_cell_id", + &profiler->file_space_parts_get_cell_id); + profiler_write_timing_info_header(e, "spacecountparts", "space_count_parts", + &profiler->file_space_count_parts); } /** @@ -124,48 +149,69 @@ void profiler_write_all_timing_info_headers(struct engine *e, struct profiler *p * @param e #engine object to get various properties. * @param time #ticks time in ticks to be written to the output file. * @param (return) file pointer used to open output file. - */ + */ void profiler_write_timing_info(struct engine *e, ticks time, FILE **file) { - fprintf(*file, " %6d %14e %14e %10zu %10zu %21.3f\n", e->step, - e->time, e->timeStep, e->updates, e->g_updates, clocks_from_ticks(time)); + fprintf(*file, " %6d %14e %14e %10zu %10zu %21.3f\n", e->step, e->time, + e->timeStep, e->updates, e->g_updates, clocks_from_ticks(time)); fflush(*file); } /** - * @brief Writes timing info to all output files. Should be called at the end of every time step, in engine_step() for example. + * @brief Writes timing info to all output files. Should be called at the end of + * every time step, in engine_step() for example. * * @param e #engine object to get various properties. - * @param (return) profiler #profiler object that holds file pointers and function timers. - */ -void profiler_write_all_timing_info(struct engine *e, struct profiler *profiler) { - - profiler_write_timing_info(e,profiler->drift_time,&profiler->file_engine_drift); - profiler_write_timing_info(e,profiler->rebuild_time,&profiler->file_engine_rebuild); - profiler_write_timing_info(e,profiler->reweight_time,&profiler->file_scheduler_reweight); - profiler_write_timing_info(e,profiler->clear_waits_time,&profiler->file_scheduler_clear_waits); - profiler_write_timing_info(e,profiler->re_wait_time,&profiler->file_scheduler_re_wait); - profiler_write_timing_info(e,profiler->enqueue_time,&profiler->file_scheduler_enqueue); - profiler_write_timing_info(e,profiler->stats_time,&profiler->file_engine_stats); - profiler_write_timing_info(e,profiler->launch_time,&profiler->file_engine_launch); - profiler_write_timing_info(e,profiler->space_rebuild_time,&profiler->file_space_rebuild); - profiler_write_timing_info(e,profiler->engine_maketasks_time,&profiler->file_engine_maketasks); - profiler_write_timing_info(e,profiler->engine_marktasks_time,&profiler->file_engine_marktasks); - profiler_write_timing_info(e,profiler->space_regrid_time,&profiler->file_space_regrid); - profiler_write_timing_info(e,profiler->space_parts_sort_time,&profiler->file_space_parts_sort); - profiler_write_timing_info(e,profiler->space_split_time,&profiler->file_space_split); - profiler_write_timing_info(e,profiler->space_parts_get_cell_id_time,&profiler->file_space_parts_get_cell_id); - profiler_write_timing_info(e,profiler->space_count_parts_time,&profiler->file_space_count_parts); - + * @param (return) profiler #profiler object that holds file pointers and + * function timers. + */ +void profiler_write_all_timing_info(struct engine *e, + struct profiler *profiler) { + + profiler_write_timing_info(e, profiler->drift_time, + &profiler->file_engine_drift); + profiler_write_timing_info(e, profiler->rebuild_time, + &profiler->file_engine_rebuild); + profiler_write_timing_info(e, profiler->reweight_time, + &profiler->file_scheduler_reweight); + profiler_write_timing_info(e, profiler->clear_waits_time, + &profiler->file_scheduler_clear_waits); + profiler_write_timing_info(e, profiler->re_wait_time, + &profiler->file_scheduler_re_wait); + profiler_write_timing_info(e, profiler->enqueue_time, + &profiler->file_scheduler_enqueue); + profiler_write_timing_info(e, profiler->stats_time, + &profiler->file_engine_stats); + profiler_write_timing_info(e, profiler->launch_time, + &profiler->file_engine_launch); + profiler_write_timing_info(e, profiler->space_rebuild_time, + &profiler->file_space_rebuild); + profiler_write_timing_info(e, profiler->engine_maketasks_time, + &profiler->file_engine_maketasks); + profiler_write_timing_info(e, profiler->engine_marktasks_time, + &profiler->file_engine_marktasks); + profiler_write_timing_info(e, profiler->space_regrid_time, + &profiler->file_space_regrid); + profiler_write_timing_info(e, profiler->space_parts_sort_time, + &profiler->file_space_parts_sort); + profiler_write_timing_info(e, profiler->space_split_time, + &profiler->file_space_split); + profiler_write_timing_info(e, profiler->space_parts_get_cell_id_time, + &profiler->file_space_parts_get_cell_id); + profiler_write_timing_info(e, profiler->space_count_parts_time, + &profiler->file_space_count_parts); + /* Reset timers. */ - profiler_reset_timers(profiler); + profiler_reset_timers(profiler); } /** - * @brief Closes all output files, should be called at the end of the simulation. + * @brief Closes all output files, should be called at the end of the + * simulation. * - * @param (return) profiler #profiler object that holds file pointers and function timers. - */ + * @param (return) profiler #profiler object that holds file pointers and + * function timers. + */ void profiler_close_files(struct profiler *profiler) { fclose(profiler->file_engine_drift); diff --git a/src/profiler.h b/src/profiler.h index 30088ef21a..4c0d2ba6c2 100644 --- a/src/profiler.h +++ b/src/profiler.h @@ -30,8 +30,8 @@ /* Includes. */ #include "clocks.h" #include "engine.h" -#include "version.h" #include "hydro.h" +#include "version.h" /* Profiler that holds file pointers and time taken in functions. */ struct profiler { @@ -59,10 +59,10 @@ struct profiler { ticks collect_timesteps_time; ticks drift_time; ticks rebuild_time; - ticks reweight_time; - ticks clear_waits_time; - ticks re_wait_time; - ticks enqueue_time; + ticks reweight_time; + ticks clear_waits_time; + ticks re_wait_time; + ticks enqueue_time; ticks stats_time; ticks launch_time; ticks space_rebuild_time; @@ -77,10 +77,13 @@ struct profiler { /* Function prototypes. */ void profiler_reset_timers(struct profiler *profiler); -void profiler_write_timing_info_header(struct engine *e, char *fileName, char *functionName, FILE **file); -void profiler_write_all_timing_info_headers(struct engine *e, struct profiler *profiler); +void profiler_write_timing_info_header(struct engine *e, char *fileName, + char *functionName, FILE **file); +void profiler_write_all_timing_info_headers(struct engine *e, + struct profiler *profiler); void profiler_write_timing_info(struct engine *e, ticks time, FILE **file); -void profiler_write_all_timing_info(struct engine *e, struct profiler *profiler); +void profiler_write_all_timing_info(struct engine *e, + struct profiler *profiler); void profiler_close_files(struct profiler *profiler); #endif /* SWIFT_PROFILER_H */ diff --git a/src/swift.h b/src/swift.h index cbb8baee6d..2928c26352 100644 --- a/src/swift.h +++ b/src/swift.h @@ -44,6 +44,7 @@ #include "partition.h" #include "physical_constants.h" #include "potential.h" +#include "profiler.h" #include "queue.h" #include "runner.h" #include "scheduler.h" @@ -56,6 +57,5 @@ #include "tools.h" #include "units.h" #include "version.h" -#include "profiler.h" #endif /* SWIFT_SWIFT_H */ -- GitLab