Skip to content

TimeFilter

nphtan edited this page May 19, 2021 · 2 revisions

KokkosResilience::Filter::TimeFilter

Filter for checkpointing periodically.

Header File: CheckpointFilter.hpp

Synopsis

struct TimeFilter
  {
    using clock_type = std::chrono::steady_clock;
    using duration_type = std::chrono::steady_clock::duration;
    using time_point_type = std::chrono::steady_clock::time_point;

    template< typename Rep, typename Period >
    explicit TimeFilter( std::chrono::duration< Rep, Period > duration )
        : checkpoint_interval( std::chrono::duration_cast< duration_type >( duration ) ),
          start( clock_type::now() )
    {
    }

    bool operator()( int ) const
    {
      auto now = clock_type::now();
      bool ret = ( now - start ) > checkpoint_interval;
      if ( ret )
        start = now;

      return ret;
    }

    mutable time_point_type start;
    duration_type checkpoint_interval;
  };

Public Members

Typedefs

  • clock_type: Identify what kind of underlying clock to use.
  • duration_type: Identify what kind of type to use to express time differences
  • time_point_type: Identify the type to use for a time point.

Constructor

  • template< typename Rep, typename Period >
        explicit TimeFilter( std::chrono::duration< Rep, Period > duration )
            : checkpoint_interval( std::chrono::duration_cast< duration_type >( duration ) ),
              start( clock_type::now() )
    Construct the TimeFilter with the supplied time period between checkpoints.

Operator

  • bool operator()( int ) const
    Get whether it is time to checkpoint.