Skip to content

ContextBase

nphtan edited this page May 19, 2021 · 11 revisions

KokkosResilience::ContextBase

Base object that all Contexts inherit.

Header File: Context.hpp

Synopsis

class ContextBase {

  explicit ContextBase( Config cfg );

  virtual ~ContextBase() = default;

  virtual void register_hashes(const std::vector< std::unique_ptr< Kokkos::ViewHolderBase > > &views,
                               const std::vector< Detail::CrefImpl > &crefs) = 0;
  virtual bool restart_available( const std::string &label, int version ) = 0;
  virtual void restart( const std::string &label, int version,
                        const std::vector< std::unique_ptr< Kokkos::ViewHolderBase > > &views ) = 0;
  virtual void checkpoint( const std::string &label, int version,
                           const std::vector< std::unique_ptr< Kokkos::ViewHolderBase > > &views ) = 0;

  virtual int latest_version( const std::string &label ) const noexcept = 0;
  virtual void register_alias( const std::string &original, const std::string &alias ) = 0;

  virtual void reset() = 0;

  const std::function< bool( int ) > &default_filter() const noexcept { return m_default_filter; }

  Config &config() noexcept { return m_config; }
  const Config &config() const noexcept { return m_config; }

#ifdef KR_ENABLE_TRACING
  Util::detail::TraceStack  &trace() { return m_trace; };
#endif

private:

  Config m_config;

  std::function< bool( int ) > m_default_filter;

#ifdef KR_ENABLE_TRACING
  Util::detail::TraceStack  m_trace;
#endif
};

std::unique_ptr< ContextBase > make_context( const std::string &config );
#ifdef KR_ENABLE_MPI_BACKENDS
std::unique_ptr< ContextBase > make_context( MPI_Comm comm, const std::string &config );
#endif
#ifdef KR_ENABLE_STDFILE
std::unique_ptr< ContextBase > make_context( const std::string &filename, const std::string &config );
#endif

Public Class Members

Constructors

  • explicit ContextBase( Config cfg );
    Constructs the default Context object.

Functions

  • virtual void register_hashes(const std::vector< std::unique_ptr< Kokkos::ViewHolderBase > > &views, const std::vector< Detail::CrefImpl > &crefs) = 0;
  • virtual bool restart_available( const std::string &label, int version ) = 0;

    Check if an existing restart is available. The version argument specifies the most recent version to use. Setting version to 0 will have Kokkos-Resilience use the most recent checkpoint.

  • virtual void restart( const std::string &label, int version, const std::vector< std::unique_ptr< Kokkos::ViewHolderBase > > &views ) = 0;

    Restart the supplied Views from the checkpoint specified by the label and version. The version argument specifies the most recent version to use. Setting version to 0 will have Kokkos-Resilience use the most recent checkpoint.

  • virtual void checkpoint( const std::string &label, int version,
                              const std::vector< std::unique_ptr< Kokkos::ViewHolderBase > > &views ) = 0;

    Checkpoint the specified Views with the supplied label and version.

  • virtual int latest_version( const std::string &label ) const noexcept = 0;

    Get the latest version number for the specified checkpoint.

  • virtual void register_alias( const std::string &original, const std::string &alias ) = 0;
  • virtual void reset() = 0;

    Reset the Context.

  • const std::function< bool( int ) > &default_filter() const noexcept { return m_default_filter; }

    Retrieve the default filter function.

  • Config &config() noexcept { return m_config; }

    Get the config member.

  • const Config &config() const noexcept { return m_config; }

    Get the config member

  • Util::detail::TraceStack  &trace() { return m_trace; };

    Get the trace stack from the context. Only applicable if tracing is enabled with KR_ENABLE_TRACING

Helper Functions

  • std::unique_ptr< ContextBase > make_context( const std::string &config );

    Create a standard ContextBase object from the specified config file path.

  • std::unique_ptr< ContextBase > make_context( MPI_Comm comm, const std::string &config );

    Create a ContextBase using the MPI backend. Requires the KR_ENABLE_MPI_BACKENDS to be set.

  • std::unique_ptr< ContextBase > make_context( const std::string &filename, const std::string &config );

    Create a ContextBase for the StdFile backend with the supplied filename. Requires the KR_ENABLE_STDFILE flag to be set.