-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write celer-sim results as 'null' when they're disabled (#1223)
* Add step timer to disable gettime calls * Write 'null' time and track counts when they're disabled
- Loading branch information
Showing
6 changed files
with
115 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
//----------------------------------*-C++-*----------------------------------// | ||
// Copyright 2024 UT-Battelle, LLC, and other Celeritas developers. | ||
// See the top-level COPYRIGHT file for details. | ||
// SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
//---------------------------------------------------------------------------// | ||
//! \file celer-sim/StepTimer.hh | ||
//---------------------------------------------------------------------------// | ||
#pragma once | ||
|
||
#include <vector> | ||
|
||
#include "corecel/sys/Stopwatch.hh" | ||
|
||
namespace celeritas | ||
{ | ||
namespace app | ||
{ | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Optionally append a time at every call. | ||
*/ | ||
class StepTimer | ||
{ | ||
public: | ||
//!@{ | ||
//! \name Type aliases | ||
using VecDbl = std::vector<double>; | ||
//!@} | ||
|
||
public: | ||
// Construct with a pointer to the times being appended, possibly null | ||
explicit inline StepTimer(VecDbl* times); | ||
|
||
// If enabled, push back the time and reset the timer | ||
inline void operator()(); | ||
|
||
private: | ||
VecDbl* times_; | ||
Stopwatch get_step_time_; | ||
}; | ||
|
||
//---------------------------------------------------------------------------// | ||
// INLINE DEFINITIONS | ||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Construct with a pointer to the times being appended. | ||
* | ||
* If this is null, the stopwatch will not be enabled. | ||
*/ | ||
StepTimer::StepTimer(VecDbl* times) : times_{times} {} | ||
|
||
//---------------------------------------------------------------------------// | ||
/*! | ||
* Push back the time and reset the timer, if requested. | ||
*/ | ||
void StepTimer::operator()() | ||
{ | ||
if (times_) | ||
{ | ||
times_->push_back(get_step_time_()); | ||
get_step_time_ = {}; | ||
} | ||
} | ||
|
||
//---------------------------------------------------------------------------// | ||
} // namespace app | ||
} // namespace celeritas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters