Skip to content

Commit

Permalink
Merge pull request #225 from awslabs/sjg/timer-fix
Browse files Browse the repository at this point in the history
Fix timer value of `Timer::TOTAL` for AMR simulations
  • Loading branch information
sebastiangrimberg authored Apr 8, 2024
2 parents f066315 + 1f50b12 commit 6c180aa
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions palace/utils/timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,25 @@ class Timer
// Return the time elapsed since timer creation.
Duration TimeFromStart() const { return Now() - start_time; }

// Save a timing step by adding a duration, without lapping; optionally, count it.
Duration SaveTime(Index idx, Duration time, bool count_it = true)
// Lap and record a timing step.
Duration MarkTime(Index idx, bool count_it = true)
{
data[idx] += time;
counts[idx] += count_it;
return data[idx];
return MarkTime(idx, Lap(), count_it);
}

// Lap and record a timing step.
Duration MarkTime(Index idx, bool count_it = true)
// Record a timing step by adding a duration, without lapping; optionally, count it.
Duration MarkTime(Index idx, Duration time, bool count_it = true)
{
return SaveTime(idx, Lap(), count_it);
if (idx == Timer::TOTAL)
{
data[idx] = time;
}
else
{
data[idx] += time;
}
counts[idx] += count_it;
return data[idx];
}

// Provide map-like read-only access to the timing data.
Expand Down Expand Up @@ -186,7 +193,7 @@ class BlockTimer
timer.MarkTime(stack.top());
stack.pop();
}
timer.SaveTime(Timer::TOTAL, timer.TimeFromStart());
timer.MarkTime(Timer::TOTAL, timer.TimeFromStart());

// Reduce timing data.
std::vector<double> data_min, data_max, data_avg;
Expand Down

0 comments on commit 6c180aa

Please sign in to comment.