Skip to content

Commit

Permalink
update for new state policies
Browse files Browse the repository at this point in the history
  • Loading branch information
mattldawson committed May 16, 2024
1 parent 42de6d9 commit 100b3d6
Show file tree
Hide file tree
Showing 19 changed files with 235 additions and 199 deletions.
2 changes: 2 additions & 0 deletions docker/Dockerfile.llvm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN dnf -y update \
make \
zlib-devel \
llvm-devel \
openmpi-devel \
valgrind \
&& dnf clean all

Expand All @@ -24,6 +25,7 @@ RUN mkdir /build \
-D MICM_ENABLE_CLANG_TIDY:BOOL=FALSE \
-D MICM_ENABLE_LLVM:BOOL=TRUE \
-D MICM_ENABLE_MEMCHECK:BOOL=TRUE \
-D MICM_ENABLE_OPENMP:BOOL=TRUE \
../micm \
&& make install -j 8

Expand Down
24 changes: 12 additions & 12 deletions include/micm/process/process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ namespace micm
/// @brief Update the solver state rate constants
/// @param processes The set of processes being solved
/// @param state The solver state to update
template<template<class> class MatrixPolicy, class SparseMatrixPolicy>
requires(!VectorizableDense<MatrixPolicy<double>>) static void UpdateState(
template<class DenseMatrixPolicy, class SparseMatrixPolicy>
requires(!VectorizableDense<DenseMatrixPolicy>) static void UpdateState(
const std::vector<Process>& processes,
State<MatrixPolicy, SparseMatrixPolicy>& state);
template<template<class> class MatrixPolicy, class SparseMatrixPolicy>
requires(VectorizableDense<MatrixPolicy<double>>) static void UpdateState(
State<DenseMatrixPolicy, SparseMatrixPolicy>& state);
template<class DenseMatrixPolicy, class SparseMatrixPolicy>
requires(VectorizableDense<DenseMatrixPolicy>) static void UpdateState(
const std::vector<Process>& processes,
State<MatrixPolicy, SparseMatrixPolicy>& state);
State<DenseMatrixPolicy, SparseMatrixPolicy>& state);

friend class ProcessBuilder;
static ProcessBuilder Create();
Expand Down Expand Up @@ -148,10 +148,10 @@ namespace micm
ProcessBuilder& SetPhase(const Phase& phase);
};

template<template<class> class MatrixPolicy, class SparseMatrixPolicy>
requires(!VectorizableDense<MatrixPolicy<double>>) void Process::UpdateState(
template<class DenseMatrixPolicy, class SparseMatrixPolicy>
requires(!VectorizableDense<DenseMatrixPolicy>) void Process::UpdateState(
const std::vector<Process>& processes,
State<MatrixPolicy, SparseMatrixPolicy>& state)
State<DenseMatrixPolicy, SparseMatrixPolicy>& state)
{
MICM_PROFILE_FUNCTION();

Expand All @@ -173,10 +173,10 @@ namespace micm
}
}

template<template<class> class MatrixPolicy, class SparseMatrixPolicy>
requires(VectorizableDense<MatrixPolicy<double>>) void Process::UpdateState(
template<class DenseMatrixPolicy, class SparseMatrixPolicy>
requires(VectorizableDense<DenseMatrixPolicy>) void Process::UpdateState(
const std::vector<Process>& processes,
State<MatrixPolicy, SparseMatrixPolicy>& state)
State<DenseMatrixPolicy, SparseMatrixPolicy>& state)
{
MICM_PROFILE_FUNCTION();
const auto& v_custom_parameters = state.custom_rate_parameters_.AsVector();
Expand Down
75 changes: 36 additions & 39 deletions include/micm/process/process_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,33 +91,32 @@ namespace micm
/// @param rate_constants Current values for the process rate constants (grid cell, process)
/// @param state_variables Current state variable values (grid cell, state variable)
/// @param forcing Forcing terms for each state variable (grid cell, state variable)
template<template<class> typename MatrixPolicy>
requires(!VectorizableDense<MatrixPolicy<double>>) void AddForcingTerms(
const MatrixPolicy<double>& rate_constants,
const MatrixPolicy<double>& state_variables,
MatrixPolicy<double>& forcing) const;
template<template<class> typename MatrixPolicy>
requires VectorizableDense<MatrixPolicy<double>>
template<typename DenseMatrixPolicy>
requires(!VectorizableDense<DenseMatrixPolicy>) void AddForcingTerms(
const DenseMatrixPolicy& rate_constants,
const DenseMatrixPolicy& state_variables,
DenseMatrixPolicy& forcing) const;
template<typename DenseMatrixPolicy>
requires VectorizableDense<DenseMatrixPolicy>
void AddForcingTerms(
const MatrixPolicy<double>& rate_constants,
const MatrixPolicy<double>& state_variables,
MatrixPolicy<double>& forcing) const;
const DenseMatrixPolicy& rate_constants,
const DenseMatrixPolicy& state_variables,
DenseMatrixPolicy& forcing) const;

/// @brief Subtract Jacobian terms for the set of processes for the current conditions
/// @param rate_constants Current values for the process rate constants (grid cell, process)
/// @param state_variables Current state variable values (grid cell, state variable)
/// @param jacobian Jacobian matrix for the system (grid cell, dependent variable, independent variable)
// template<template<class> class MatrixPolicy, template<class> class SparseMatrixPolicy>
template<class MatrixPolicy, class SparseMatrixPolicy>
requires(!VectorizableDense<MatrixPolicy> || !VectorizableSparse<SparseMatrixPolicy>) void SubtractJacobianTerms(
const MatrixPolicy& rate_constants,
const MatrixPolicy& state_variables,
template<class DenseMatrixPolicy, class SparseMatrixPolicy>
requires(!VectorizableDense<DenseMatrixPolicy> || !VectorizableSparse<SparseMatrixPolicy>) void SubtractJacobianTerms(
const DenseMatrixPolicy& rate_constants,
const DenseMatrixPolicy& state_variables,
SparseMatrixPolicy& jacobian) const;
// template<template<class> class MatrixPolicy, template<class> class SparseMatrixPolicy>
template<class MatrixPolicy, class SparseMatrixPolicy>
requires(VectorizableDense<MatrixPolicy>&& VectorizableSparse<SparseMatrixPolicy>) void SubtractJacobianTerms(
const MatrixPolicy& rate_constants,
const MatrixPolicy& state_variables,
template<class DenseMatrixPolicy, class SparseMatrixPolicy>
requires(VectorizableDense<DenseMatrixPolicy>&& VectorizableSparse<SparseMatrixPolicy>) void SubtractJacobianTerms(
const DenseMatrixPolicy& rate_constants,
const DenseMatrixPolicy& state_variables,
SparseMatrixPolicy& jacobian) const;

/// @brief Returns the set of species used in a set of processes
Expand Down Expand Up @@ -217,11 +216,11 @@ namespace micm
}
}

template<template<class> typename MatrixPolicy>
requires(!VectorizableDense<MatrixPolicy<double>>) inline void ProcessSet::AddForcingTerms(
const MatrixPolicy<double>& rate_constants,
const MatrixPolicy<double>& state_variables,
MatrixPolicy<double>& forcing) const
template<typename DenseMatrixPolicy>
requires(!VectorizableDense<DenseMatrixPolicy>) inline void ProcessSet::AddForcingTerms(
const DenseMatrixPolicy& rate_constants,
const DenseMatrixPolicy& state_variables,
DenseMatrixPolicy& forcing) const
{
MICM_PROFILE_FUNCTION();

Expand Down Expand Up @@ -255,12 +254,12 @@ namespace micm
}
};

template<template<class> typename MatrixPolicy>
requires VectorizableDense<MatrixPolicy<double>>
template<typename DenseMatrixPolicy>
requires VectorizableDense<DenseMatrixPolicy>
inline void ProcessSet::AddForcingTerms(
const MatrixPolicy<double>& rate_constants,
const MatrixPolicy<double>& state_variables,
MatrixPolicy<double>& forcing) const
const DenseMatrixPolicy& rate_constants,
const DenseMatrixPolicy& state_variables,
DenseMatrixPolicy& forcing) const
{
MICM_PROFILE_FUNCTION();

Expand Down Expand Up @@ -300,12 +299,11 @@ namespace micm
}

// Forming the Jacobian matrix "J" and returning "-J" to be consistent with the CUDA implementation
// template<template<class> class MatrixPolicy, template<class> class SparseMatrixPolicy>
template<class MatrixPolicy, class SparseMatrixPolicy>
requires(!VectorizableDense<MatrixPolicy> || !VectorizableSparse<SparseMatrixPolicy>) inline void ProcessSet::
template<class DenseMatrixPolicy, class SparseMatrixPolicy>
requires(!VectorizableDense<DenseMatrixPolicy> || !VectorizableSparse<SparseMatrixPolicy>) inline void ProcessSet::
SubtractJacobianTerms(
const MatrixPolicy& rate_constants,
const MatrixPolicy& state_variables,
const DenseMatrixPolicy& rate_constants,
const DenseMatrixPolicy& state_variables,
SparseMatrixPolicy& jacobian) const
{
MICM_PROFILE_FUNCTION();
Expand Down Expand Up @@ -350,12 +348,11 @@ namespace micm
}

// Forming the Jacobian matrix "J" and returning "-J" to be consistent with the CUDA implementation
// template<template<class> class MatrixPolicy, template<class> class SparseMatrixPolicy>
template<class MatrixPolicy, class SparseMatrixPolicy>
requires(VectorizableDense<MatrixPolicy>&& VectorizableSparse<SparseMatrixPolicy>) inline void ProcessSet::
template<class DenseMatrixPolicy, class SparseMatrixPolicy>
requires(VectorizableDense<DenseMatrixPolicy>&& VectorizableSparse<SparseMatrixPolicy>) inline void ProcessSet::
SubtractJacobianTerms(
const MatrixPolicy& rate_constants,
const MatrixPolicy& state_variables,
const DenseMatrixPolicy& rate_constants,
const DenseMatrixPolicy& state_variables,
SparseMatrixPolicy& jacobian) const
{
MICM_PROFILE_FUNCTION();
Expand Down
8 changes: 4 additions & 4 deletions include/micm/solver/rosenbrock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ namespace micm

/// @brief Returns a state object for use with the solver
/// @return A object that can hold the full state of the chemical system
virtual State<MatrixPolicy, SparseMatrixPolicy> GetState() const;
virtual State<MatrixPolicy<double>, SparseMatrixPolicy> GetState() const;

/// @brief Advances the given step over the specified time step
/// @param time_step Time [s] to advance the state by
/// @return A struct containing results and a status code
SolverResult Solve(double time_step, State<MatrixPolicy, SparseMatrixPolicy>& state) noexcept;
SolverResult Solve(double time_step, State<MatrixPolicy<double>, SparseMatrixPolicy>& state) noexcept;

/// @brief Calculate a chemical forcing
/// @param rate_constants List of rate constants for each needed species
Expand All @@ -175,7 +175,7 @@ namespace micm

/// @brief Update the rate constants for the environment state
/// @param state The current state of the chemical system
void UpdateState(State<MatrixPolicy, SparseMatrixPolicy>& state);
void UpdateState(State<MatrixPolicy<double>, SparseMatrixPolicy>& state);

/// @brief Compute the derivative of the forcing w.r.t. each chemical, and return the negative jacobian
/// @param rate_constants List of rate constants for each needed species
Expand All @@ -198,7 +198,7 @@ namespace micm
bool& singular,
const MatrixPolicy<double>& number_densities,
SolverStats& stats,
State<MatrixPolicy, SparseMatrixPolicy>& state);
State<MatrixPolicy<double>, SparseMatrixPolicy>& state);

/// @brief Computes the scaled norm of the vector errors
/// @param y the original vector
Expand Down
12 changes: 6 additions & 6 deletions include/micm/solver/rosenbrock.inl
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ namespace micm
class SparseMatrixPolicy,
class LinearSolverPolicy,
class ProcessSetPolicy>
inline State<MatrixPolicy, SparseMatrixPolicy>
inline State<MatrixPolicy<double>, SparseMatrixPolicy>
RosenbrockSolver<MatrixPolicy, SparseMatrixPolicy, LinearSolverPolicy, ProcessSetPolicy>::GetState() const
{
return State<MatrixPolicy, SparseMatrixPolicy>{ state_parameters_ };
return State<MatrixPolicy<double>, SparseMatrixPolicy>{ state_parameters_ };
}

template<
Expand All @@ -252,7 +252,7 @@ namespace micm
inline typename RosenbrockSolver<MatrixPolicy, SparseMatrixPolicy, LinearSolverPolicy, ProcessSetPolicy>::SolverResult
RosenbrockSolver<MatrixPolicy, SparseMatrixPolicy, LinearSolverPolicy, ProcessSetPolicy>::Solve(
double time_step,
State<MatrixPolicy, SparseMatrixPolicy>& state) noexcept
State<MatrixPolicy<double>, SparseMatrixPolicy>& state) noexcept
{
MICM_PROFILE_FUNCTION();

Expand Down Expand Up @@ -460,7 +460,7 @@ namespace micm
{
MICM_PROFILE_FUNCTION();
std::fill(forcing.AsVector().begin(), forcing.AsVector().end(), 0.0);
process_set_.template AddForcingTerms<MatrixPolicy>(rate_constants, number_densities, forcing);
process_set_.template AddForcingTerms<MatrixPolicy<double>>(rate_constants, number_densities, forcing);
}

template<
Expand Down Expand Up @@ -530,7 +530,7 @@ namespace micm
class LinearSolverPolicy,
class ProcessSetPolicy>
inline void RosenbrockSolver<MatrixPolicy, SparseMatrixPolicy, LinearSolverPolicy, ProcessSetPolicy>::UpdateState(
State<MatrixPolicy, SparseMatrixPolicy>& state)
State<MatrixPolicy<double>, SparseMatrixPolicy>& state)
{
Process::UpdateState(processes_, state);
}
Expand All @@ -547,7 +547,7 @@ namespace micm
bool& singular,
const MatrixPolicy<double>& number_densities,
SolverStats& stats,
State<MatrixPolicy, SparseMatrixPolicy>& state)
State<MatrixPolicy<double>, SparseMatrixPolicy>& state)
{
MICM_PROFILE_FUNCTION();

Expand Down
20 changes: 10 additions & 10 deletions include/micm/solver/solver_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace micm
{
template<class DenseMatrixPolicy, class SparseMatrixPolicy>
class SolverBuilder
{
protected:
Expand Down Expand Up @@ -58,13 +59,12 @@ namespace micm

/// @brief
/// @return
template<class MatrixPolicy, class SparseMatrixPolicy>
Solver<State<MatrixPolicy, SparseMatrixPolicy>> Build();
Solver<State<DenseMatrixPolicy, SparseMatrixPolicy>> Build();

protected:
/// @brief
/// @return
virtual Solver BuildBackwardEulerSolver() = 0;
virtual Solver<State<DenseMatrixPolicy, SparseMatrixPolicy>> BuildBackwardEulerSolver() = 0;
virtual ~SolverBuilder() = default;

/// @brief
Expand All @@ -75,7 +75,7 @@ namespace micm

/// @brief Get a species map properly ordered
/// @return
template<class MatrixPolicy, class ProcessSetPolicy>
template<class ProcessSetPolicy>
std::map<std::string, std::size_t> GetSpeciesMap() const;

/// @brief Set the absolute tolerances per species
Expand All @@ -91,18 +91,18 @@ namespace micm
std::vector<std::size_t> GetJacobianDiagonalElements(auto jacobian) const;
};

template<class MatrixPolicy, class SparseMatrixPolicy>
class CpuSolverBuilder : public SolverBuilder
template<class DenseMatrixPolicy, class SparseMatrixPolicy>
class CpuSolverBuilder : public SolverBuilder<DenseMatrixPolicy, SparseMatrixPolicy>
{
public:
Solver BuildBackwardEulerSolver() override;
Solver<State<DenseMatrixPolicy, SparseMatrixPolicy>> BuildBackwardEulerSolver() override;
};

template<class MatrixPolicy, class SparseMatrixPolicy>
class GpuSolverBuilder : public SolverBuilder
template<class DenseMatrixPolicy, class SparseMatrixPolicy>
class GpuSolverBuilder : public SolverBuilder<DenseMatrixPolicy, SparseMatrixPolicy>
{
public:
Solver BuildBackwardEulerSolver() override;
Solver<State<DenseMatrixPolicy, SparseMatrixPolicy>> BuildBackwardEulerSolver() override;
};

} // namespace micm
Expand Down
Loading

0 comments on commit 100b3d6

Please sign in to comment.