Program Listing for File SimCluster.hpp

↰ Return to documentation for file (src/core/SimCluster.hpp)

#ifndef SIMCLUSTER_HPP
#define SIMCLUSTER_HPP

#include "../io/OutputManager.hpp"
#include "../io/SimControls.hpp"
#include <atomic>
#include <exception> // NOLINT(misc-include-cleaner) -- correct header for std::exception_ptr; see the identical NOLINT in SimCluster.cpp
#include <memory>
#include <optional>

namespace core
{

    class SimCluster
    {
    public:

        SimCluster(const io::SimControls& simControls,
            std::unique_ptr<io::OutputManager> outputManager, bool restart = false);

        // Disallow copying and moving: this object owns the output
        // manager exclusively, so duplicating or relocating it makes
        // no sense
        SimCluster(const SimCluster&) = delete;
        auto operator=(const SimCluster&) -> SimCluster& = delete;
        SimCluster(SimCluster&&) = delete;
        auto operator=(SimCluster&&) -> SimCluster& = delete;

        ~SimCluster() = default;

        static constexpr int sigtermExitCode = 143;

        auto run() -> int;

        [[nodiscard]] auto trialsCompleted() const -> unsigned long
        {
            return trialsCompleted_.load(std::memory_order_relaxed);
        }

    private:

        void runTrial(unsigned long trialNum);

        auto runBatch(unsigned long rankBatchStart, unsigned long rankBatchEnd) -> std::exception_ptr;

        const io::SimControls& simControls_;
        std::unique_ptr<io::OutputManager> outputManager_;
        std::atomic<unsigned long> trialsCompleted_{0};
        bool restart_ = false;
        // Fault injection for tests only (tests/mpi/test_mpi_e2e.py),
        // read once by the constructor from environment variables that
        // are never set in normal use. They exist because there is no
        // way to make one particular MPI rank fail deterministically
        // from an input deck alone.
        std::optional<unsigned long> testFailTrial_;
        std::optional<unsigned long> testFailRank_;
    };

} // namespace core

#endif // SIMCLUSTER_HPP