Skip to content

Commit

Permalink
Auto-format code changes (#692)
Browse files Browse the repository at this point in the history
Auto-format code using Clang-Format

Co-authored-by: GitHub Actions <[email protected]>
  • Loading branch information
github-actions[bot] and actions-user authored Dec 13, 2024
1 parent 0576ed8 commit cdfd2e7
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 82 deletions.
4 changes: 2 additions & 2 deletions include/micm/cuda/solver/cuda_linear_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include <micm/cuda/solver/cuda_lu_decomposition.hpp>
#include <micm/cuda/solver/cuda_linear_solver.cuh>
#include <micm/cuda/solver/cuda_lu_decomposition.hpp>
#include <micm/cuda/util/cuda_param.hpp>
#include <micm/solver/lu_decomposition.hpp>
#include <micm/solver/linear_solver.hpp>
#include <micm/solver/lu_decomposition.hpp>

namespace micm
{
Expand Down
2 changes: 1 addition & 1 deletion include/micm/cuda/solver/cuda_lu_decomposition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ namespace micm
{
/// @brief Alias for the default CUDA LU decomposition algorithm
using CudaLuDecomposition = CudaLuDecompositionDoolittle;
}
} // namespace micm
2 changes: 1 addition & 1 deletion include/micm/cuda/solver/cuda_solver_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#pragma once

#include <micm/cuda/process/cuda_process_set.hpp>
#include <micm/cuda/solver/cuda_lu_decomposition.hpp>
#include <micm/cuda/solver/cuda_linear_solver.hpp>
#include <micm/cuda/solver/cuda_lu_decomposition.hpp>
#include <micm/cuda/solver/cuda_state.hpp>
#include <micm/cuda/util/cuda_dense_matrix.hpp>
#include <micm/cuda/util/cuda_sparse_matrix.hpp>
Expand Down
2 changes: 1 addition & 1 deletion include/micm/jit/solver/jit_lu_decomposition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ namespace micm
/// @brief Alias for the default JIT LU decomposition algorithm
template<std::size_t L = MICM_DEFAULT_VECTOR_SIZE>
using JitLuDecomposition = JitLuDecompositionDoolittle<L>;
}
} // namespace micm
2 changes: 1 addition & 1 deletion include/micm/jit/solver/jit_solver_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#pragma once

#include <micm/jit/process/jit_process_set.hpp>
#include <micm/jit/solver/jit_lu_decomposition.hpp>
#include <micm/jit/solver/jit_linear_solver.hpp>
#include <micm/jit/solver/jit_lu_decomposition.hpp>
#include <micm/solver/solver_builder.hpp>

namespace micm
Expand Down
2 changes: 1 addition & 1 deletion include/micm/solver/lu_decomposition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ namespace micm
{
/// @brief Alias for the default LU decomposition algorithm
using LuDecomposition = LuDecompositionDoolittle;
}
} // namespace micm
3 changes: 2 additions & 1 deletion include/micm/solver/lu_decomposition_doolittle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ namespace micm
/// @brief Create an LU decomposition algorithm for a given sparse matrix policy
/// @param matrix Sparse matrix
template<class SparseMatrixPolicy>
requires(SparseMatrixConcept<SparseMatrixPolicy>) static LuDecompositionDoolittle Create(const SparseMatrixPolicy& matrix);
requires(SparseMatrixConcept<SparseMatrixPolicy>) static LuDecompositionDoolittle
Create(const SparseMatrixPolicy& matrix);

/// @brief Create sparse L and U matrices for a given A matrix
/// @param A Sparse matrix that will be decomposed
Expand Down
10 changes: 6 additions & 4 deletions include/micm/solver/lu_decomposition_doolittle.inl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace micm
}

template<class SparseMatrixPolicy>
requires(SparseMatrixConcept<SparseMatrixPolicy>) inline LuDecompositionDoolittle::LuDecompositionDoolittle(const SparseMatrixPolicy& matrix)
requires(SparseMatrixConcept<SparseMatrixPolicy>) inline LuDecompositionDoolittle::LuDecompositionDoolittle(
const SparseMatrixPolicy& matrix)
{
Initialize<SparseMatrixPolicy>(matrix, typename SparseMatrixPolicy::value_type());
}
Expand Down Expand Up @@ -103,9 +104,10 @@ namespace micm
}

template<class SparseMatrixPolicy>
requires(
SparseMatrixConcept<SparseMatrixPolicy>) inline std::pair<SparseMatrixPolicy, SparseMatrixPolicy> LuDecompositionDoolittle::
GetLUMatrices(const SparseMatrixPolicy& A, typename SparseMatrixPolicy::value_type initial_value)
requires(SparseMatrixConcept<SparseMatrixPolicy>) inline std::
pair<SparseMatrixPolicy, SparseMatrixPolicy> LuDecompositionDoolittle::GetLUMatrices(
const SparseMatrixPolicy& A,
typename SparseMatrixPolicy::value_type initial_value)
{
MICM_PROFILE_FUNCTION();

Expand Down
8 changes: 4 additions & 4 deletions include/micm/solver/lu_decomposition_mozart.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ namespace micm

/// @brief LU decomposer for SparseMatrix following the algorithm from the MOZART model
///
/// This LU decomposition uses the algorithm from the MOZART chemistry preprocessor at:
/// This LU decomposition uses the algorithm from the MOZART chemistry preprocessor at:
/// https://github.com/ESCOMP/CHEM_PREPROCESSOR/blob/f923081508f4264e61fcef2753a9898e55d1598e/src/cam_chempp/make_lu_fac.f#L127-L214
///
/// The MOZART function overwrote the A matrix with the L and U matrices. The pseudo-code
/// in C++ for the corresponding dense matrix algorithm for matrix A (inline change) would be:
/// in C++ for the corresponding dense matrix algorithm for matrix A (inline change) would be:
///
/// for i = 0...n-1 // Outer loop over columns of the sparse matrix A
/// for j = i+1...n-1 // Multiply column below diagonal
/// A[j][i] = A[j][i] / A[i][i]
/// for k = i+1...n-1 // Modify sub-matrix
/// for j = i+1...n-1
/// A[j][k] = A[j][k] – A[j][i] * A[i][k]
///
///
/// The pseudo-code in C++ for the corresponding dense matrix algorithm for matrix A
/// and separate lower (upper) triangular matrix L(U) would be:
///
///
/// for i = 0...n-1 // Initialize U and L matrices to the A values
/// for j = i...n-1 // Initialize U matrix including diagonal
/// U[i][j] = A[i][j]
Expand Down
38 changes: 20 additions & 18 deletions include/micm/solver/lu_decomposition_mozart.inl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace micm
}

template<class SparseMatrixPolicy>
requires(SparseMatrixConcept<SparseMatrixPolicy>) inline LuDecompositionMozart::LuDecompositionMozart(const SparseMatrixPolicy& matrix)
requires(SparseMatrixConcept<SparseMatrixPolicy>) inline LuDecompositionMozart::LuDecompositionMozart(
const SparseMatrixPolicy& matrix)
{
Initialize<SparseMatrixPolicy>(matrix, typename SparseMatrixPolicy::value_type());
}
Expand Down Expand Up @@ -79,7 +80,7 @@ namespace micm
++(std::get<1>(uii_nj_nk));
}
// middle k loop to set U[j][k] and L[j][k]
for (std::size_t k = i+1; k < n; ++k)
for (std::size_t k = i + 1; k < n; ++k)
{
if (LU.second.IsZero(i, k))
continue;
Expand Down Expand Up @@ -115,9 +116,10 @@ namespace micm
}

template<class SparseMatrixPolicy>
requires(
SparseMatrixConcept<SparseMatrixPolicy>) inline std::pair<SparseMatrixPolicy, SparseMatrixPolicy> LuDecompositionMozart::
GetLUMatrices(const SparseMatrixPolicy& A, typename SparseMatrixPolicy::value_type initial_value)
requires(SparseMatrixConcept<SparseMatrixPolicy>) inline std::
pair<SparseMatrixPolicy, SparseMatrixPolicy> LuDecompositionMozart::GetLUMatrices(
const SparseMatrixPolicy& A,
typename SparseMatrixPolicy::value_type initial_value)
{
MICM_PROFILE_FUNCTION();

Expand Down Expand Up @@ -147,10 +149,10 @@ namespace micm
if (!(std::find(U_ids.begin(), U_ids.end(), std::make_pair(i, k)) != U_ids.end()))
continue;
for (std::size_t j = i + 1; j <= k; ++j)
if(std::find(L_ids.begin(), L_ids.end(), std::make_pair(j, i)) != L_ids.end())
if (std::find(L_ids.begin(), L_ids.end(), std::make_pair(j, i)) != L_ids.end())
U_ids.insert(std::make_pair(j, k));
for (std::size_t j = k + 1; j < n; ++j)
if(std::find(L_ids.begin(), L_ids.end(), std::make_pair(j, i)) != L_ids.end())
if (std::find(L_ids.begin(), L_ids.end(), std::make_pair(j, i)) != L_ids.end())
L_ids.insert(std::make_pair(j, k));
}
}
Expand Down Expand Up @@ -190,7 +192,7 @@ namespace micm
auto nujk_nljk_uik = nujk_nljk_uik_.begin();
auto ujk_lji = ujk_lji_.begin();
auto ljk_lji = ljk_lji_.begin();

for (auto& lii_nuij_nlij : lii_nuij_nlij_)
{
for (std::size_t i = 0; i < std::get<1>(lii_nuij_nlij); ++i)
Expand Down Expand Up @@ -225,7 +227,7 @@ namespace micm
U_vector[ujk_lji->first] -= L_vector[ujk_lji->second] * U_vector[uik];
++ujk_lji;
}
for (std::size_t ij = 0 ; ij < std::get<1>(*nujk_nljk_uik); ++ij)
for (std::size_t ij = 0; ij < std::get<1>(*nujk_nljk_uik); ++ij)
{
L_vector[ljk_lji->first] -= L_vector[ljk_lji->second] * U_vector[uik];
++ljk_lji;
Expand Down Expand Up @@ -272,32 +274,32 @@ namespace micm
for (std::size_t i = 0; i < std::get<1>(lii_nuij_nlij); ++i)
{
for (std::size_t i_cell = 0; i_cell < n_cells; ++i_cell)
U_vector[uij_aij->first+i_cell] = A_vector[uij_aij->second+i_cell];
U_vector[uij_aij->first + i_cell] = A_vector[uij_aij->second + i_cell];
++uij_aij;
}
for (std::size_t i_cell = 0; i_cell < n_cells; ++i_cell)
L_vector[std::get<0>(lii_nuij_nlij)+i_cell] = 1.0;
L_vector[std::get<0>(lii_nuij_nlij) + i_cell] = 1.0;
for (std::size_t i = 0; i < std::get<2>(lii_nuij_nlij); ++i)
{
for (std::size_t i_cell = 0; i_cell < n_cells; ++i_cell)
L_vector[lij_aij->first+i_cell] = A_vector[lij_aij->second+i_cell];
L_vector[lij_aij->first + i_cell] = A_vector[lij_aij->second + i_cell];
++lij_aij;
}
}
for (auto& fill_uij : fill_uij_)
for (std::size_t i_cell = 0; i_cell < n_cells; ++i_cell)
U_vector[fill_uij+i_cell] = 0;
U_vector[fill_uij + i_cell] = 0;
for (auto& fill_lij : fill_lij_)
for (std::size_t i_cell = 0; i_cell < n_cells; ++i_cell)
L_vector[fill_lij+i_cell] = 0;
L_vector[fill_lij + i_cell] = 0;
for (std::size_t i = 0; i < n; ++i)
{
for (std::size_t i_cell = 0; i_cell < n_cells; ++i_cell)
Uii_inverse[i_cell] = 1.0 / U_vector[std::get<0>(*uii_nj_nk)+i_cell];
Uii_inverse[i_cell] = 1.0 / U_vector[std::get<0>(*uii_nj_nk) + i_cell];
for (std::size_t ij = 0; ij < std::get<1>(*uii_nj_nk); ++ij)
{
for (std::size_t i_cell = 0; i_cell < n_cells; ++i_cell)
L_vector[*lji+i_cell] = L_vector[*lji+i_cell] * Uii_inverse[i_cell];
L_vector[*lji + i_cell] = L_vector[*lji + i_cell] * Uii_inverse[i_cell];
++lji;
}
for (std::size_t ik = 0; ik < std::get<2>(*uii_nj_nk); ++ik)
Expand All @@ -306,13 +308,13 @@ namespace micm
for (std::size_t ij = 0; ij < std::get<0>(*nujk_nljk_uik); ++ij)
{
for (std::size_t i_cell = 0; i_cell < n_cells; ++i_cell)
U_vector[ujk_lji->first+i_cell] -= L_vector[ujk_lji->second+i_cell] * U_vector[uik+i_cell];
U_vector[ujk_lji->first + i_cell] -= L_vector[ujk_lji->second + i_cell] * U_vector[uik + i_cell];
++ujk_lji;
}
for (std::size_t ij = 0; ij < std::get<1>(*nujk_nljk_uik); ++ij)
{
for (std::size_t i_cell = 0; i_cell < n_cells; ++i_cell)
L_vector[ljk_lji->first+i_cell] -= L_vector[ljk_lji->second+i_cell] * U_vector[uik+i_cell];
L_vector[ljk_lji->first + i_cell] -= L_vector[ljk_lji->second + i_cell] * U_vector[uik + i_cell];
++ljk_lji;
}
++nujk_nljk_uik;
Expand Down
2 changes: 1 addition & 1 deletion include/micm/solver/solver_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <micm/process/process_set.hpp>
#include <micm/solver/backward_euler.hpp>
#include <micm/solver/backward_euler_solver_parameters.hpp>
#include <micm/solver/lu_decomposition.hpp>
#include <micm/solver/linear_solver.hpp>
#include <micm/solver/lu_decomposition.hpp>
#include <micm/solver/rosenbrock_solver_parameters.hpp>
#include <micm/solver/solver.hpp>
#include <micm/system/conditions.hpp>
Expand Down
5 changes: 4 additions & 1 deletion include/micm/solver/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ namespace micm
std::set<std::pair<std::size_t, std::size_t>> nonzero_jacobian_elements_{};
};

template<class DenseMatrixPolicy = StandardDenseMatrix, class SparseMatrixPolicy = StandardSparseMatrix, class LuDecompositionPolicy = LuDecomposition>
template<
class DenseMatrixPolicy = StandardDenseMatrix,
class SparseMatrixPolicy = StandardSparseMatrix,
class LuDecompositionPolicy = LuDecomposition>
struct State
{
/// Type of the DenseMatrixPolicy
Expand Down
8 changes: 6 additions & 2 deletions include/micm/solver/state.inl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ namespace micm
}

template<class DenseMatrixPolicy, class SparseMatrixPolicy, class LuDecompositionPolicy>
inline void State<DenseMatrixPolicy, SparseMatrixPolicy, LuDecompositionPolicy>::SetConcentration(const Species& species, double concentration)
inline void State<DenseMatrixPolicy, SparseMatrixPolicy, LuDecompositionPolicy>::SetConcentration(
const Species& species,
double concentration)
{
auto var = variable_map_.find(species.name_);
if (var == variable_map_.end())
Expand Down Expand Up @@ -160,7 +162,9 @@ namespace micm
}

template<class DenseMatrixPolicy, class SparseMatrixPolicy, class LuDecompositionPolicy>
inline void State<DenseMatrixPolicy, SparseMatrixPolicy, LuDecompositionPolicy>::SetCustomRateParameter(const std::string& label, double value)
inline void State<DenseMatrixPolicy, SparseMatrixPolicy, LuDecompositionPolicy>::SetCustomRateParameter(
const std::string& label,
double value)
{
auto param = custom_rate_parameter_map_.find(label);
if (param == custom_rate_parameter_map_.end())
Expand Down
10 changes: 8 additions & 2 deletions test/integration/cuda/test_cuda_analytical_rosenbrock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

constexpr std::size_t L = 3;
using builderType = micm::CudaSolverBuilder<micm::CudaRosenbrockSolverParameters, L>;
using stateType = micm::CudaState<builderType::DenseMatrixPolicyType, builderType::SparseMatrixPolicyType, builderType::LuDecompositionPolicyType>;
using stateType = micm::CudaState<
builderType::DenseMatrixPolicyType,
builderType::SparseMatrixPolicyType,
builderType::LuDecompositionPolicyType>;

auto two = builderType(micm::RosenbrockSolverParameters::TwoStageRosenbrockParameters());
auto three = builderType(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters());
Expand All @@ -22,7 +25,10 @@ auto four_da = builderType(micm::RosenbrockSolverParameters::FourStageDifferenti
auto six_da = builderType(micm::RosenbrockSolverParameters::SixStageDifferentialAlgebraicRosenbrockParameters());

using builderType1Cell = micm::CudaSolverBuilder<micm::CudaRosenbrockSolverParameters, 1>;
using stateType1Cell = micm::CudaState<builderType1Cell::DenseMatrixPolicyType, builderType1Cell::SparseMatrixPolicyType, builderType::LuDecompositionPolicyType>;
using stateType1Cell = micm::CudaState<
builderType1Cell::DenseMatrixPolicyType,
builderType1Cell::SparseMatrixPolicyType,
builderType::LuDecompositionPolicyType>;

auto two_1_cell = builderType1Cell(micm::RosenbrockSolverParameters::TwoStageRosenbrockParameters());
auto three_1_cell = builderType1Cell(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters());
Expand Down
6 changes: 4 additions & 2 deletions test/integration/jit/test_jit_analytical_rosenbrock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
template<std::size_t L>
using BuilderType = micm::JitSolverBuilder<micm::JitRosenbrockSolverParameters, L>;
template<std::size_t L>
using StateType =
micm::State<micm::VectorMatrix<double, L>, micm::SparseMatrix<double, micm::SparseMatrixVectorOrdering<L>>, micm::JitLuDecomposition<L>>;
using StateType = micm::State<
micm::VectorMatrix<double, L>,
micm::SparseMatrix<double, micm::SparseMatrixVectorOrdering<L>>,
micm::JitLuDecomposition<L>>;

auto two = BuilderType<1>(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters());
auto three = BuilderType<1>(micm::RosenbrockSolverParameters::ThreeStageRosenbrockParameters());
Expand Down
Loading

0 comments on commit cdfd2e7

Please sign in to comment.