Program Listing for File SimGalaxy.hpp
↰ Return to documentation for file (src/core/SimGalaxy.hpp)
#ifndef SIMGALAXY_HPP
#define SIMGALAXY_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 SimGalaxy
{
public:
SimGalaxy(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
SimGalaxy(const SimGalaxy&) = delete;
auto operator=(const SimGalaxy&) -> SimGalaxy& = delete;
SimGalaxy(SimGalaxy&&) = delete;
auto operator=(SimGalaxy&&) -> SimGalaxy& = delete;
~SimGalaxy() = 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; see SimCluster's own
// identical members
std::optional<unsigned long> testFailTrial_;
std::optional<unsigned long> testFailRank_;
};
} // namespace core
#endif // SIMGALAXY_HPP