perf(thread saftey): All Engines are now thread safe
Previously engines were not thread safe, a seperate engine would be needed for every thread. This is no longer the case. This allows for much more efficient parallel execution
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include "gridfire/reaction/reaction.h"
|
||||
#include "gridfire/engine/engine_abstract.h"
|
||||
#include "gridfire/partition/partition.h"
|
||||
#include "gridfire/utils/logging.h"
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
@@ -43,6 +44,28 @@ namespace gridfire::policy {
|
||||
INITIALIZED_VERIFIED
|
||||
};
|
||||
|
||||
inline std::string NetworkPolicyStatusToString(NetworkPolicyStatus status) {
|
||||
switch (status) {
|
||||
case NetworkPolicyStatus::UNINITIALIZED:
|
||||
return "UNINITIALIZED";
|
||||
case NetworkPolicyStatus::INITIALIZED_UNVERIFIED:
|
||||
return "INITIALIZED_UNVERIFIED";
|
||||
case NetworkPolicyStatus::MISSING_KEY_REACTION:
|
||||
return "MISSING_KEY_REACTION";
|
||||
case NetworkPolicyStatus::MISSING_KEY_SPECIES:
|
||||
return "MISSING_KEY_SPECIES";
|
||||
case NetworkPolicyStatus::INITIALIZED_VERIFIED:
|
||||
return "INITIALIZED_VERIFIED";
|
||||
default:
|
||||
return "UNKNOWN_STATUS";
|
||||
}
|
||||
}
|
||||
|
||||
struct ConstructionResults {
|
||||
const engine::DynamicEngine& engine;
|
||||
std::unique_ptr<engine::scratch::StateBlob> scratch_blob;
|
||||
};
|
||||
|
||||
/**
|
||||
* @class NetworkPolicy
|
||||
* @brief Abstract interface for policies that construct DynamicEngine networks from a seed composition.
|
||||
@@ -139,7 +162,7 @@ namespace gridfire::policy {
|
||||
* NetOut out = solver.evaluate(netIn, true);
|
||||
* @endcode
|
||||
*/
|
||||
[[nodiscard]] virtual engine::DynamicEngine& construct() = 0;
|
||||
[[nodiscard]] virtual ConstructionResults construct() = 0;
|
||||
|
||||
/**
|
||||
* @brief Returns the current verification/construction status of the policy.
|
||||
@@ -160,6 +183,8 @@ namespace gridfire::policy {
|
||||
[[nodiscard]] virtual std::vector<engine::EngineTypes> get_engine_types_stack() const = 0;
|
||||
|
||||
[[nodiscard]] virtual const std::unique_ptr<partition::PartitionFunction>& get_partition_function() const = 0;
|
||||
|
||||
[[nodiscard]] virtual std::unique_ptr<engine::scratch::StateBlob> get_stack_scratch_blob() const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -217,3 +242,27 @@ namespace gridfire::policy {
|
||||
};
|
||||
|
||||
}
|
||||
// 1. Define the BASE specialization first
|
||||
template<>
|
||||
struct std::formatter<gridfire::policy::NetworkPolicy> {
|
||||
static constexpr auto parse(const format_parse_context& ctx) { return ctx.begin(); }
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(const gridfire::policy::NetworkPolicy& policy, FormatContext& ctx) const {
|
||||
std::vector<gridfire::engine::EngineTypes> engine_types = policy.get_engine_types_stack();
|
||||
std::ranges::reverse(engine_types);
|
||||
|
||||
return format_to(
|
||||
ctx.out(),
|
||||
"{}(Status: {}, Engine Stack Size: {}, Engine Stack: <(TOP) [{}] (BOTTOM)>)",
|
||||
policy.name(),
|
||||
gridfire::policy::NetworkPolicyStatusToString(policy.get_status()),
|
||||
policy.get_engine_stack().size(),
|
||||
gridfire::utils::iterable_to_delimited_string(
|
||||
engine_types,
|
||||
" -> ",
|
||||
[](const auto& type) { return gridfire::engine::engine_type_to_string(type); }
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
@@ -26,7 +26,6 @@
|
||||
|
||||
#include "fourdst/composition/composition.h"
|
||||
#include "fourdst/atomic/atomicSpecies.h"
|
||||
#include "gridfire/partition/composite/partition_composite.h"
|
||||
|
||||
#include "gridfire/policy/chains.h"
|
||||
|
||||
@@ -135,7 +134,7 @@ namespace gridfire::policy {
|
||||
* // ... run solver ...
|
||||
* @endcode
|
||||
*/
|
||||
engine::DynamicEngine& construct() override;
|
||||
ConstructionResults construct() override;
|
||||
|
||||
/**
|
||||
* @brief Gets the current status of the policy.
|
||||
@@ -148,6 +147,8 @@ namespace gridfire::policy {
|
||||
[[nodiscard]] std::vector<engine::EngineTypes> get_engine_types_stack() const override;
|
||||
[[nodiscard]] const std::unique_ptr<partition::PartitionFunction>& get_partition_function() const override;
|
||||
|
||||
[[nodiscard]] std::unique_ptr<engine::scratch::StateBlob> get_stack_scratch_blob() const override;
|
||||
|
||||
private:
|
||||
std::set<fourdst::atomic::Species> m_seed_species; ///< The set of seed species required by this policy. These are H-1, He-3, He-4, C-12, N-14, O-16, Ne-20, Mg-24.
|
||||
|
||||
@@ -159,12 +160,12 @@ namespace gridfire::policy {
|
||||
NetworkPolicyStatus m_status = NetworkPolicyStatus::UNINITIALIZED; ///< The current status of the policy.
|
||||
private:
|
||||
static std::unique_ptr<partition::PartitionFunction> build_partition_function();
|
||||
[[nodiscard]] NetworkPolicyStatus check_status() const;
|
||||
[[nodiscard]] NetworkPolicyStatus check_status(engine::scratch::StateBlob& ctx) const;
|
||||
|
||||
public:
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
template<>
|
||||
struct std::formatter<gridfire::policy::MainSequencePolicy> : std::formatter<gridfire::policy::NetworkPolicy> {};
|
||||
Reference in New Issue
Block a user