19 inline std::chrono::high_resolution_clock::time_point
now() {
28 std::chrono::high_resolution_clock::time_point& tic,
bool reset =
false 30 auto const toc =
now();
31 auto const timing =
static_cast<float>(
32 std::chrono::duration_cast<std::chrono::milliseconds>(toc - tic).count()
44 std::chrono::high_resolution_clock::time_point& tic,
float* cumul =
nullptr 46 if (cumul !=
nullptr) {
65 float interpolate = 0;
80 std::string output =
"";
115 constexpr
int const nsteps = 10;
116 constexpr
float const time_eps = 1.E-4;
118 float const elap[nsteps] = {
119 std::max(time_eps, time.mesh_init),
120 std::max(time_eps, time.redistrib),
121 std::max(time_eps, time.interface),
122 std::max(time_eps, time.search),
123 std::max(time_eps, time.intersect),
124 std::max(time_eps, time.gradient),
125 std::max(time_eps, time.interpolate),
126 std::max(time_eps, time.mismatch),
127 std::max(time_eps, time.remap),
128 std::max(time_eps, time.total - time.mesh_init - time.interface - time.remap)
131 int time_ratio[nsteps];
134 for (
int i = 0; i < nsteps; ++i) {
135 time_ratio[i] =
static_cast<int>(100 * (elap[i] / time.total));
136 max_elap = std::max(max_elap, static_cast<int>(elap[i]));
141 int const n_tot = 1 + n_dec + (max_elap > 0 ? ((int) std::floor(std::log10(max_elap))) + 1 : 0);
143 std::string
const& path = params.output;
144 std::printf(
"\nRecap: total elapsed time %.3f s\n", time.total);
145 std::printf(
" \u2022 %2d %% generate mesh \e[32m(%*.3f s)\e[0m.\n", time_ratio[0], n_tot, elap[0]);
146 std::printf(
" \u2022 %2d %% redistribute \e[32m(%*.3f s)\e[0m.\n", time_ratio[1], n_tot, elap[1]);
147 std::printf(
" \u2022 %2d %% interface reconst. \e[32m(%*.3f s)\e[0m.\n", time_ratio[2], n_tot, elap[2]);
148 std::printf(
" \u2022 %2d %% search \e[32m(%*.3f s)\e[0m.\n", time_ratio[3], n_tot, elap[3]);
149 std::printf(
" \u2022 %2d %% intersect \e[32m(%*.3f s)\e[0m.\n", time_ratio[4], n_tot, elap[4]);
150 std::printf(
" \u2022 %2d %% gradient \e[32m(%*.3f s)\e[0m.\n", time_ratio[5], n_tot, elap[5]);
151 std::printf(
" \u2022 %2d %% interpolate \e[32m(%*.3f s)\e[0m.\n", time_ratio[6], n_tot, elap[6]);
152 std::printf(
" \u2022 %2d %% mismatch \e[32m(%*.3f s)\e[0m.\n", time_ratio[7], n_tot, elap[7]);
153 std::printf(
" \u2022 %2d %% remap \e[32m(%*.3f s)\e[0m.\n", time_ratio[8], n_tot, elap[8]);
154 std::printf(
" \u2022 %2d %% post-process \e[32m(%*.3f s)\e[0m.\n", time_ratio[9], n_tot, elap[9]);
157 std::printf(
"Exporting stats to '%s' ... ", path.data());
162 std::ofstream file(path, std::ios::out|std::ios::app);
163 if (not file.good()) {
164 std::fprintf(stderr,
"Could not open file :%s\n", path.data());
169 std::ifstream checkfile(path);
170 assert(checkfile.good());
171 checkfile.seekg(0, std::ios::end);
172 bool const is_empty = checkfile.tellg() == 0;
177 file <<
"# Profiling data for t-junction app" << std::endl;
178 file <<
"#" << std::endl;
179 file <<
"# Fields" << std::endl;
180 file <<
"# 1. number of ranks" << std::endl;
181 file <<
"# 2. number of threads" << std::endl;
182 file <<
"# 3. initialization time" << std::endl;
183 file <<
"# 4. redistribution time" << std::endl;
184 file <<
"# 5. interface reconstruction time" << std::endl;
185 file <<
"# 6. search time" << std::endl;
186 file <<
"# 7. intersection time" << std::endl;
187 file <<
"# 8. gradient time" << std::endl;
188 file <<
"# 9. interpolation time" << std::endl;
189 file <<
"# 10. mismatch time" << std::endl;
190 file <<
"# 11. remapping time" << std::endl;
191 file <<
"# 12. total elapsed time" << std::endl;
192 file <<
"# 13. mesh dimension" << std::endl;
193 file <<
"# 14. source cells count" << std::endl;
194 file <<
"# 15. target cells count" << std::endl;
195 file <<
"# 16. materials count" << std::endl;
196 file <<
"# 17. remap order" << std::endl << std::endl;
199 file << params.ranks <<
"\t" 200 << params.threads <<
"\t" 201 << time.mesh_init <<
"\t" 202 << time.redistrib <<
"\t" 203 << time.interface <<
"\t" 204 << time.search <<
"\t" 205 << time.intersect <<
"\t" 206 << time.gradient <<
"\t" 207 << time.interpolate <<
"\t" 208 << time.gradient <<
"\t" 209 << time.remap <<
"\t" 210 << time.total <<
"\t" 211 << params.dim <<
"\t" 212 << params.nsource <<
"\t" 213 << params.ntarget <<
"\t" 214 << params.nmats <<
"\t" 215 << params.order << std::endl;
std::chrono::high_resolution_clock::time_point now()
Get current time.
Definition: timer.h:19
float elapsed(std::chrono::high_resolution_clock::time_point &tic, bool reset=false)
Get elapsed time in seconds.
Definition: timer.h:27
bool dump()
Definition: timer.h:112
void reset(std::chrono::high_resolution_clock::time_point &tic, float *cumul=nullptr)
Dump current time and reset it afterwards.
Definition: timer.h:43