63 if (omp_get_thread_num() == 0) {
65 if (m_events.find(a_event) == m_events.end()) {
69 m_events.emplace(a_event, std::make_tuple(
false, startTime, elapsedTime));
73 std::tuple<bool, TimePoint, Duration>&
event = m_events.at(a_event);
74 const bool stoppedEvent = std::get<StoppedEvent>(event);
78 const Duration& previousElapsedTime = std::get<ElapsedTime>(event);
80 event = std::make_tuple(
false, startTime, previousElapsedTime);
116 std::ios::fmtflags oldFlags = a_outputStream.flags();
118 if (omp_get_thread_num() == 0) {
120 std::stringstream header;
122 <<
"| ---------------------------------------------------------------------------------------------------------|"
124 <<
"| " + m_processName +
" kernel report: " <<
"\n"
125 <<
"| ---------------------------------------------------------------------------------------------------------|"
127 <<
"| " << std::left << std::setw(25) <<
"Event" <<
"| " << std::right << std::setw(8) <<
"Loc. (s)" <<
"| "
128 << std::right << std::setw(8) <<
"Loc. (%)"
130 <<
"| " << std::right << std::setw(8) <<
"Min. (s)" <<
"| " << std::right << std::setw(8) <<
"Max. (s)" <<
"| "
131 << std::right << std::setw(8) <<
"Avg. (s)" <<
"| " << std::right << std::setw(8) <<
"Dev. (s)" <<
"| "
132 << std::right << std::setw(8) <<
"Min rank" <<
"| " << std::right << std::setw(8) <<
"Max rank" <<
"| "
135 <<
"| ---------------------------------------------------------------------------------------------------------|"
138 a_outputStream << header.str();
142 a_outputStream.flags(oldFlags);
174 std::ios::fmtflags oldFlags = a_outputStream.flags();
176 if (omp_get_thread_num() == 0) {
179 this->printReportHeader(a_outputStream);
181 const std::pair<Real, Real> totalTime = this->computeTotalElapsedTime(a_localReportOnly);
182 const Real totalTimeLocal = totalTime.first;
184 for (
const auto& e : m_events) {
186 const std::string& eventName = e.first;
187 const bool finishedEvent = std::get<StoppedEvent>(e.second);
189 std::stringstream ssLocalDuration;
190 std::stringstream ssPercentage;
191 std::stringstream ssMinDuration;
192 std::stringstream ssMaxDuration;
193 std::stringstream ssAvgDuration;
194 std::stringstream ssDevDuration;
195 std::stringstream ssMinRank;
196 std::stringstream ssMaxRank;
199 const Duration localDuration = std::get<ElapsedTime>(e.second);
200 const Real localDurationInSeconds = localDuration.count();
202 ssLocalDuration << std::fixed << std::setprecision(4) << localDurationInSeconds;
203 ssPercentage << std::fixed << std::setprecision(4) << 100. * localDurationInSeconds / totalTimeLocal;
206 if (!a_localReportOnly) {
208 const int srcRank = 0;
209 const int numRank = numProc();
211 Vector<Real> allDurations(numRank);
212 gather(allDurations, localDurationInSeconds, srcRank);
218 Real maxTime = std::numeric_limits<Real>::min();
219 Real minTime = std::numeric_limits<Real>::max();
227 for (
int i = 0; i < allDurations.size(); i++) {
228 average += allDurations[i];
230 if (allDurations[i] < minTime) {
232 minTime = allDurations[i];
234 if (allDurations[i] > maxTime) {
236 maxTime = allDurations[i];
239 average *= 1. / numRank;
242 for (
int i = 0; i < allDurations.size(); i++) {
243 sigma += sqrt(std::pow(allDurations[i] - average, 2));
245 sigma = sqrt(sigma / numRank);
248 broadcast(average, srcRank);
249 broadcast(sigma, srcRank);
250 broadcast(maxTime, srcRank);
251 broadcast(minTime, srcRank);
252 broadcast(minRank, srcRank);
253 broadcast(maxRank, srcRank);
255 ssMinDuration << std::fixed << std::setprecision(4) << minTime;
256 ssMaxDuration << std::fixed << std::setprecision(4) << maxTime;
257 ssAvgDuration << std::fixed << std::setprecision(4) << average;
258 ssDevDuration << std::fixed << std::setprecision(4) << sigma;
259 ssMinRank << std::fixed << std::setprecision(4) << minRank;
260 ssMaxRank << std::fixed << std::setprecision(4) << maxRank;
263 ssMinDuration <<
" N/A ";
264 ssMaxDuration <<
" N/A ";
265 ssAvgDuration <<
" N/A ";
266 ssDevDuration <<
" N/A ";
267 ssMinRank <<
" N/A ";
268 ssMaxRank <<
" N/A ";
273 ssLocalDuration <<
" - ";
274 ssPercentage <<
" - ";
275 ssMinDuration <<
" - ";
276 ssMaxDuration <<
" - ";
277 ssAvgDuration <<
" - ";
278 ssDevDuration <<
" - ";
283 std::stringstream outputString;
286 outputString <<
"| " << std::left << std::setw(25) << eventName <<
"| " << std::right << std::setw(8)
287 << ssLocalDuration.str() <<
"| " << std::right << std::setw(8) << ssPercentage.str()
289 <<
"| " << std::right << std::setw(8) << ssMinDuration.str() <<
"| " << std::right << std::setw(8)
290 << ssMaxDuration.str() <<
"| " << std::right << std::setw(8) << ssAvgDuration.str() <<
"| "
291 << std::right << std::setw(8) << ssDevDuration.str() <<
"| " << std::right << std::setw(8)
292 << ssMinRank.str() <<
"| " << std::right << std::setw(8) << ssMaxRank.str()
296 a_outputStream << outputString.str();
299 this->printReportTail(a_outputStream, totalTime);
304 a_outputStream.flags(oldFlags);
311 Real elapsedTimeLocal = 0.0;
312 Real elapsedTimeGlobal = 0.0;
314 for (
const auto& e : m_events) {
315 const bool finishedEvent = std::get<StoppedEvent>(e.second);
318 const Duration elapsedTime = std::get<ElapsedTime>(e.second);
319 const Real localDurationInSeconds = elapsedTime.count();
321 elapsedTimeLocal += localDurationInSeconds;
326 if (!a_localReportOnly) {
327 MPI_Allreduce(&elapsedTimeLocal, &elapsedTimeGlobal, 1, MPI_CH_REAL, MPI_MAX, Chombo_MPI::comm);
330 elapsedTimeGlobal = elapsedTimeLocal;
333 elapsedTimeGlobal = elapsedTimeLocal;
336 return std::make_pair(elapsedTimeLocal, elapsedTimeGlobal);
344 std::vector<std::string> headerRow;
345 headerRow.emplace_back(
"# MPI rank");
350 std::vector<std::vector<Real>> finishedEvents;
353 constexpr int srcRank = 0;
354 const int numRanks = numProc();
356 const int numRanks = 1;
359 for (
const auto& e : m_events) {
360 const std::string& eventName = e.first;
361 const std::tuple<bool, TimePoint, Duration>& eventData = e.second;
363 const bool finishedEvent = std::get<StoppedEvent>(eventData);
368 const Real localEventDuration = std::get<ElapsedTime>(eventData).count();
369 Vector<Real> allTimes(numRanks, 0.0);
371 gather(allTimes, localEventDuration, srcRank);
373 allTimes[0] = localEventDuration;
376 finishedEvents.emplace_back(allTimes.stdVector());
377 headerRow.emplace_back(eventName);
383 if (procID() == srcRank) {
386 if (omp_get_thread_num() == 0) {
389 f.open(a_fileName, std::ios_base::trunc);
391 const int width = 12;
392 for (
int col = 0; col < headerRow.size(); col++) {
393 f << std::left << std::setw(width) << headerRow[col] <<
"\t";
398 for (
int irank = 0; irank < numRanks; irank++) {
399 f << std::left << std::setw(width) << irank <<
"\t";
400 for (
int event = 0;
event < finishedEvents.size();
event++) {
401 f << std::left << std::setw(width) << finishedEvents[event][irank] <<
"\t";