Skip to content

Commit

Permalink
Merge pull request #423 from kgbudge/timer
Browse files Browse the repository at this point in the history
Safe a call to sqrt by wrapping its argument in fabs.

LGTM.
  • Loading branch information
KineticTheory authored Jun 26, 2018
2 parents e002110 + 3c38151 commit cab62a5
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/c4/Timer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ Timer::Timer()

//! Print out a timing report.
void Timer::print(std::ostream &out, int p) const {
using std::setw;
using std::ios;
using std::setw;

out.setf(ios::fixed, ios::floatfield);
out.precision(p);
Expand Down Expand Up @@ -131,8 +131,8 @@ void Timer::print(std::ostream &out, int p) const {
//! Print out a timing report as a single line summary.
void Timer::printline(std::ostream &out, unsigned const p,
unsigned const w) const {
using std::setw;
using std::ios;
using std::setw;

out.setf(ios::fixed, ios::floatfield);
out.precision(p);
Expand Down Expand Up @@ -333,8 +333,8 @@ void Timer::pause(double const pauseSeconds) {
*/
void Timer::printline_mean(std::ostream &out, unsigned const p,
unsigned const w, unsigned const v) const {
using std::setw;
using std::ios;
using std::setw;

unsigned const ranks = rtt_c4::nodes();

Expand Down Expand Up @@ -371,13 +371,13 @@ void Timer::printline_mean(std::ostream &out, unsigned const p,
// Width of first column (intervals) should be set by client before calling
// this function.
out << setw(w) << mni << " +/- " << setw(v)
<< sqrt((ni2 - 2 * mni * ni + ranks * mni * mni) / ranks) << setw(w)
<< sqrt(fabs(ni2 - 2 * mni * ni + ranks * mni * mni) / ranks) << setw(w)
<< mu << " +/- " << setw(v)
<< sqrt((u2 - 2 * mu * u + ranks * mu * mu) / ranks) << setw(w) << ms
<< " +/- " << setw(v)
<< sqrt((s2 - 2 * ms * s + ranks * ms * ms) / ranks) << setw(w) << mww
<< " +/- " << setw(v)
<< sqrt((ww2 - 2 * mww * ww + ranks * mww * mww) / ranks);
<< sqrt(fabs(u2 - 2 * mu * u + ranks * mu * mu) / ranks) << setw(w)
<< ms << " +/- " << setw(v)
<< sqrt(fabs(s2 - 2 * ms * s + ranks * ms * ms) / ranks) << setw(w)
<< mww << " +/- " << setw(v)
<< sqrt(fabs(ww2 - 2 * mww * ww + ranks * mww * mww) / ranks);

// Omit PAPI for now.

Expand Down

0 comments on commit cab62a5

Please sign in to comment.