Skip to content

MPIContext

nphtan edited this page May 19, 2021 · 1 revision

KokkosResilience::MPIContext

Context object using the MPI Backend

Header File: MPIContext.hpp

Synopsis

template <typename Backend>
class MPIContext : public ContextBase {
public:
explicit MPIContext(MPI_Comm comm, Config &cfg)
    : ContextBase(cfg), m_backend(*this, comm), m_comm(comm) {}

MPIContext(const MPIContext &) = delete;
MPIContext(MPIContext &&) noexcept = default;

MPIContext &operator=(const MPIContext &) = delete;
MPIContext &operator=(MPIContext &&) noexcept = default;

virtual ~MPIContext() {
#ifdef KR_ENABLE_TRACING
  int rank = -1;
  MPI_Comm_rank(m_comm, &rank);
  int size = -1;
  MPI_Comm_size(m_comm, &size);

  std::ostringstream fname;
  fname << "trace" << rank << ".json";

  std::ofstream out(fname.str());

  std::cout << "writing trace to " << fname.str() << '\n';

  trace().write(out);

  // Metafile
  picojson::object root;
  root["num_ranks"] = picojson::value(static_cast<double>(size));

  std::ofstream meta_out("meta.json");
  picojson::value(root).serialize(std::ostream_iterator<char>(meta_out),
                                  true);
#endif
}

MPI_Comm comm() const noexcept

Backend &backend()

void register_hashes(
    const std::vector<std::unique_ptr<Kokkos::ViewHolderBase>> &views,
    const std::vector<Detail::CrefImpl> &crefs) override

bool restart_available(const std::string &label, int version) override 

void restart(const std::string &label, int version,
             const std::vector<std::unique_ptr<Kokkos::ViewHolderBase>>
                 &views) override

void checkpoint(const std::string &label, int version,
                const std::vector<std::unique_ptr<Kokkos::ViewHolderBase>>
                    &views) override 

int latest_version(const std::string &label) const noexcept override 

void register_alias( const std::string &original, const std::string &alias ) override 

void reset() override

Public Class Members

Constructors

  • explicit MPIContext(MPI_Comm comm, Config &cfg)
        : ContextBase(cfg), m_backend(*this, comm), m_comm(comm) {}

    Construct a MPIContext with the supplied communicator and Config object.

  • MPIContext(const MPIContext &) = delete;

    Copy constructor is deleted.

  • MPIContext(MPIContext &&) noexcept = default;

    Move constructor.

Operators

  • MPIContext &operator=(const MPIContext &) = delete;

    Copy constructor is deleted.

  • MPIContext &operator=(MPIContext &&) noexcept = default;

    Move constructor.

Functions

  • MPI_Comm comm() const noexcept

    Access the underlying communicator.

  • Backend &backend()

    Access the underlying Backend. Returns a reference.

  • void register_hashes(
        const std::vector<std::unique_ptr<Kokkos::ViewHolderBase>> &views,
        const std::vector<Detail::CrefImpl> &crefs) override

    Register Views. Overrides the ContextBase implementation.

  • bool restart_available(const std::string &label, int version) override

    Check if an existing restart is available. Searches based on the supplied label. version determines the most recent version to search for. For example, setting version to 5 will search for any restart up to version 5. Setting version to 0 will search for the most recent restart.

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

    Restart the specified Views from the checkpoint determined by the label and version.

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

    Create a checkpoint of the specified Views.

  • int latest_version(const std::string &label) const noexcept override

    Get the latest version of the checkpoint with the name label.

  • void register_alias( const std::string &original, const std::string &alias ) override

    Register a new alias.

  • void reset() override

    Reset the context.