perf(openMP): added openMP support

Note that currently this actually slows the code down. Spinning up the threads and tearing them down is expensive
This commit is contained in:
2025-12-06 13:48:12 -05:00
parent 4e2b3cb11f
commit 67dde830af
7 changed files with 314 additions and 132 deletions

View File

@@ -97,7 +97,7 @@ namespace gridfire::engine {
*
* @see engine_abstract.h
*/
class GraphEngine final : public DynamicEngine{
class GraphEngine final : public DynamicEngine {
public:
/**
* @brief Constructs a GraphEngine from a composition.
@@ -855,6 +855,12 @@ namespace gridfire::engine {
const reaction::Reaction& m_reaction;
const GraphEngine& m_engine;
};
struct PrecomputationKernelResults {
std::vector<double> dydt_vector;
double total_neutrino_energy_loss_rate{0.0};
double total_neutrino_flux{0.0};
};
private:
Config<config::GridFireConfig> m_config;
quill::Logger* m_logger = LogManager::getInstance().getLogger("log");
@@ -959,6 +965,42 @@ namespace gridfire::engine {
*/
[[nodiscard]] bool validateConservation() const;
double compute_reaction_flow(
const std::vector<double> &local_abundances,
const std::vector<double> &screening_factors,
const std::vector<double> &bare_rates,
const std::vector<double> &bare_reverse_rates,
double rho,
size_t reactionCounter,
const reaction::Reaction &reaction,
size_t reactionIndex,
const PrecomputedReaction &precomputedReaction
) const;
std::pair<double, double> compute_neutrino_fluxes(
double netFlow,
const reaction::Reaction &reaction) const;
PrecomputationKernelResults accumulate_flows_serial(
const std::vector<double>& local_abundances,
const std::vector<double>& screening_factors,
const std::vector<double>& bare_rates,
const std::vector<double>& bare_reverse_rates,
double rho,
const reaction::ReactionSet& activeReactions
) const;
#ifdef GRIDFIRE_USE_OPENMP
PrecomputationKernelResults accumulate_flows_parallel(
const std::vector<double>& local_abundances,
const std::vector<double>& screening_factors,
const std::vector<double>& bare_rates,
const std::vector<double>& bare_reverse_rates,
double rho,
const reaction::ReactionSet& activeReactions
) const;
#endif
[[nodiscard]] StepDerivatives<double> calculateAllDerivativesUsingPrecomputation(
const fourdst::composition::CompositionAbstract &comp,

View File

@@ -878,6 +878,8 @@ namespace gridfire::reaction {
[[nodiscard]] std::optional<std::unique_ptr<Reaction>> get(const std::string_view& id) const;
[[nodiscard]] std::unique_ptr<Reaction> get(size_t index) const;
/**
* @brief Removes a reaction from the set.
* @param reaction The Reaction to remove.