From 1094c1bcf49b23d81b5e1e355ca1eedd616bc73a Mon Sep 17 00:00:00 2001 From: Phil Miller Date: Tue, 2 Jan 2024 17:20:16 -0800 Subject: [PATCH] Add coarse top-level timing profile output --- src/NGen.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/NGen.cpp b/src/NGen.cpp index a1e76ec901..63b97d76d2 100644 --- a/src/NGen.cpp +++ b/src/NGen.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include @@ -154,6 +155,8 @@ int main(int argc, char *argv[]) { exit(1); } + auto time_start = std::chrono::steady_clock::now(); + std::cout << "NGen Framework " << ngen_VERSION_MAJOR << "." << ngen_VERSION_MINOR << "." << ngen_VERSION_PATCH << std::endl; @@ -485,6 +488,9 @@ int main(int argc, char *argv[]) { } + auto time_done_init = std::chrono::steady_clock::now(); + auto time_elapsed_init = time_done_init - time_start; + //Now loop some time, iterate catchments, do stuff for total number of output times auto num_times = manager->Simulation_Time_Object->get_total_output_times(); for( int count = 0; count < num_times; count++) @@ -546,6 +552,8 @@ int main(int argc, char *argv[]) { std::cout << "Finished " << manager->Simulation_Time_Object->get_total_output_times() << " timesteps." << std::endl; } + auto time_done_simulation = std::chrono::steady_clock::now(); + auto time_elapsed_simulation = time_done_simulation - time_done_init; #ifdef NGEN_MPI_ACTIVE MPI_Barrier(MPI_COMM_WORLD); @@ -568,6 +576,25 @@ int main(int argc, char *argv[]) { } #endif + auto time_done_routing = std::chrono::steady_clock::now(); + auto time_elapsed_routing = time_done_routing - time_done_simulation; + + auto as_seconds = [](decltype(time_elapsed_routing) in) + { + return std::chrono::duration_cast(in).count(); + }; + + if (mpi_rank == 0) + { + std::cout << "NGen top-level timings:" + << "\n\tNGen::init: " << as_seconds(time_elapsed_init) + << "\n\tNGen::simulation: " << as_seconds(time_elapsed_simulation) +#ifdef NGEN_ROUTING_ACTIVE + << "\n\tNGen::routing: " << as_seconds(time_elapsed_routing) +#endif + << std::endl; + } + #ifdef NGEN_MPI_ACTIVE MPI_Finalize(); #endif