Skip to content

Commit

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

Co-authored-by: GitHub Actions <actions@github.com>
  • Loading branch information
github-actions[bot] and actions-user authored Jul 17, 2024
1 parent f8fc288 commit 03e8dcf
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 134 deletions.
14 changes: 9 additions & 5 deletions include/micm/jit/solver/jit_lu_decomposition.inl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace micm
.SetName(function_name)
.SetArguments({ { "A matrix", JitType::DoublePtr },
{ "lower matrix", JitType::DoublePtr },
{ "upper matrix", JitType::DoublePtr }})
{ "upper matrix", JitType::DoublePtr } })
.SetReturnType(JitType::Void);
llvm::Type *double_type = func.GetType(JitType::Double);
llvm::Value *zero = llvm::ConstantInt::get(*(func.context_), llvm::APInt(64, 0));
Expand Down Expand Up @@ -186,16 +186,20 @@ namespace micm

template<std::size_t L>
template<class SparseMatrixPolicy>
void JitLuDecomposition<L>::Decompose(const SparseMatrixPolicy &A, SparseMatrixPolicy &lower, SparseMatrixPolicy &upper, bool& is_singular) const
void JitLuDecomposition<L>::Decompose(
const SparseMatrixPolicy &A,
SparseMatrixPolicy &lower,
SparseMatrixPolicy &upper,
bool &is_singular) const
{
is_singular = false;
decompose_function_(A.AsVector().data(), lower.AsVector().data(), upper.AsVector().data());
for(size_t block = 0; block < A.NumberOfBlocks(); ++block)
for (size_t block = 0; block < A.NumberOfBlocks(); ++block)
{
auto diagonals = upper.DiagonalIndices(block);
for(const auto& diagonal : diagonals)
for (const auto &diagonal : diagonals)
{
if(upper.AsVector()[diagonal] == 0)
if (upper.AsVector()[diagonal] == 0)
{
is_singular = true;
return;
Expand Down
3 changes: 2 additions & 1 deletion include/micm/solver/lu_decomposition.inl
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ namespace micm
}
}
std::size_t uii_deref = *uii;
if (n_cells != A_GroupVectorSize) {
if (n_cells != A_GroupVectorSize)
{
// check the bottom right corner of the matrix
for (std::size_t i_cell = 0; i_cell < n_cells; ++i_cell)
{
Expand Down
40 changes: 20 additions & 20 deletions test/unit/cuda/solver/test_cuda_rosenbrock.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "../../solver/test_rosenbrock_solver_policy.hpp"

#include <micm/cuda/solver/cuda_rosenbrock.cuh>
#include <micm/cuda/solver/cuda_rosenbrock.hpp>
#include <micm/cuda/solver/cuda_solver_builder.hpp>
Expand All @@ -15,8 +17,6 @@

#include <iostream>

#include "../../solver/test_rosenbrock_solver_policy.hpp"

template<std::size_t L>
using GpuBuilder = micm::CudaSolverBuilder<micm::CudaRosenbrockSolverParameters, L>;

Expand Down Expand Up @@ -266,8 +266,8 @@ TEST(RosenbrockSolver, SingularSystemZeroInBottomRightOfU)
double k1 = -2;
double k2 = 1.0;

vector_state.SetCustomRateParameter("r1", {k1, k1, k1, k1});
vector_state.SetCustomRateParameter("r2", {k2, k2, k2, k2});
vector_state.SetCustomRateParameter("r1", { k1, k1, k1, k1 });
vector_state.SetCustomRateParameter("r2", { k2, k2, k2, k2 });

vector_state.variables_[0] = { 1.0, 1.0 };
vector_state.variables_[1] = { 1.0, 1.0 };
Expand All @@ -277,19 +277,19 @@ TEST(RosenbrockSolver, SingularSystemZeroInBottomRightOfU)
// to get a jacobian with an LU factorization that contains a zero on the diagonal
// of U, we need det(alpha * I - jacobian) = 0
// for the system above, that means we have to have alpha + k1 + k2 = 0
// in this case, one of the reaction rates will be negative but it's good enough to
// in this case, one of the reaction rates will be negative but it's good enough to
// test the singularity check
// alpha is 1 / (H * gamma), where H is the time step and gamma is the gamma value from
// alpha is 1 / (H * gamma), where H is the time step and gamma is the gamma value from
// the rosenbrock paramters
// so H needs to be 1 / ( (-k1 - k2) * gamma)
// since H is positive we need -k1 -k2 to be positive, hence the smaller, negative value for k1
double H = 1 / ( (-k1 - k2) * params.gamma_[0]);
double H = 1 / ((-k1 - k2) * params.gamma_[0]);
vector_solver.solver_.parameters_.h_start_ = H;

vector_solver.CalculateRateConstants(vector_state);
vector_state.SyncInputsToDevice();

auto vector_result = vector_solver.Solve(2*H, vector_state);
auto vector_result = vector_solver.Solve(2 * H, vector_state);
vector_state.SyncOutputsToHost();
EXPECT_NE(vector_result.stats_.singular_, 0);
}
Expand All @@ -305,30 +305,30 @@ TEST(RosenbrockSolver, SingularSystemZeroAlongDiagonalNotBottomRight)
// to get a jacobian with an LU factorization that contains a zero on the diagonal
// of U, we need det(alpha * I - jacobian) = 0
// for the system above, that means we have to set alpha = -k1, or alpha=-k2, or alpha=k3
double H = 1 / ( -k1* params.gamma_[0]);
double H = 1 / (-k1 * params.gamma_[0]);

params.check_singularity_ = true;
params.h_start_ = H;

auto vector = GpuBuilder<4>(params);

auto vector_solver = getSolverForSingularSystemOnDiagonal(vector).SetNumberOfGridCells(4).Build();

auto vector_state = vector_solver.GetState();

vector_state.SetCustomRateParameter("r1", {k1, k1, k1, k1});
vector_state.SetCustomRateParameter("r2", {k2, k2, k2, k2});
vector_state.SetCustomRateParameter("r3", {k3, k3, k3, k3});
vector_state.SetCustomRateParameter("r1", { k1, k1, k1, k1 });
vector_state.SetCustomRateParameter("r2", { k2, k2, k2, k2 });
vector_state.SetCustomRateParameter("r3", { k3, k3, k3, k3 });

vector_state.variables_[0] = { 1.0, 1.0, 1.0 };
vector_state.variables_[1] = { 1.0, 1.0, 1.0 };
vector_state.variables_[2] = { 1.0, 1.0, 1.0 };
vector_state.variables_[3] = { 1.0, 1.0, 1.0 };

vector_state.variables_[0] = { 1.0, 1.0, 1.0 };
vector_state.variables_[1] = { 1.0, 1.0, 1.0 };
vector_state.variables_[2] = { 1.0, 1.0, 1.0 };
vector_state.variables_[3] = { 1.0, 1.0, 1.0 };

vector_solver.CalculateRateConstants(vector_state);
vector_state.SyncInputsToDevice();

auto vector_result = vector_solver.Solve(2*H, vector_state);
auto vector_result = vector_solver.Solve(2 * H, vector_state);
vector_state.SyncOutputsToHost();
EXPECT_NE(vector_result.stats_.singular_, 0);
}
40 changes: 20 additions & 20 deletions test/unit/jit/solver/test_jit_rosenbrock.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "../../solver/test_rosenbrock_solver_policy.hpp"

#include <micm/configure/solver_config.hpp>
#include <micm/jit/jit_compiler.hpp>
#include <micm/jit/solver/jit_rosenbrock.hpp>
Expand All @@ -12,8 +14,6 @@

#include <gtest/gtest.h>

#include "../../solver/test_rosenbrock_solver_policy.hpp"

void run_solver(auto& solver)
{
auto state = solver.GetState();
Expand Down Expand Up @@ -87,8 +87,8 @@ TEST(JitRosenbrockSolver, SingularSystemZeroInBottomRightOfU)
double k1 = -2;
double k2 = 1.0;

vector_state.SetCustomRateParameter("r1", {k1, k1, k1, k1});
vector_state.SetCustomRateParameter("r2", {k2, k2, k2, k2});
vector_state.SetCustomRateParameter("r1", { k1, k1, k1, k1 });
vector_state.SetCustomRateParameter("r2", { k2, k2, k2, k2 });

vector_state.variables_[0] = { 1.0, 1.0 };
vector_state.variables_[1] = { 1.0, 1.0 };
Expand All @@ -98,18 +98,18 @@ TEST(JitRosenbrockSolver, SingularSystemZeroInBottomRightOfU)
// to get a jacobian with an LU factorization that contains a zero on the diagonal
// of U, we need det(alpha * I - jacobian) = 0
// for the system above, that means we have to have alpha + k1 + k2 = 0
// in this case, one of the reaction rates will be negative but it's good enough to
// in this case, one of the reaction rates will be negative but it's good enough to
// test the singularity check
// alpha is 1 / (H * gamma), where H is the time step and gamma is the gamma value from
// alpha is 1 / (H * gamma), where H is the time step and gamma is the gamma value from
// the rosenbrock paramters
// so H needs to be 1 / ( (-k1 - k2) * gamma)
// since H is positive we need -k1 -k2 to be positive, hence the smaller, negative value for k1
double H = 1 / ( (-k1 - k2) * params.gamma_[0]);
double H = 1 / ((-k1 - k2) * params.gamma_[0]);
vector_solver.solver_.parameters_.h_start_ = H;

vector_solver.CalculateRateConstants(vector_state);

auto vector_result = vector_solver.Solve(2*H, vector_state);
auto vector_result = vector_solver.Solve(2 * H, vector_state);
EXPECT_NE(vector_result.stats_.singular_, 0);
}

Expand All @@ -124,28 +124,28 @@ TEST(JitRosenbrockSolver, SingularSystemZeroAlongDiagonalNotBottomRight)
// to get a jacobian with an LU factorization that contains a zero on the diagonal
// of U, we need det(alpha * I - jacobian) = 0
// for the system above, that means we have to set alpha = -k1, or alpha=-k2, or alpha=k3
double H = 1 / ( -k1* params.gamma_[0]);
double H = 1 / (-k1 * params.gamma_[0]);

params.check_singularity_ = true;
params.h_start_ = H;

auto vector = JitBuilder<4>(params);

auto vector_solver = getSolverForSingularSystemOnDiagonal(vector).SetNumberOfGridCells(4).Build();

auto vector_state = vector_solver.GetState();

vector_state.SetCustomRateParameter("r1", {k1, k1, k1, k1});
vector_state.SetCustomRateParameter("r2", {k2, k2, k2, k2});
vector_state.SetCustomRateParameter("r3", {k3, k3, k3, k3});
vector_state.SetCustomRateParameter("r1", { k1, k1, k1, k1 });
vector_state.SetCustomRateParameter("r2", { k2, k2, k2, k2 });
vector_state.SetCustomRateParameter("r3", { k3, k3, k3, k3 });

vector_state.variables_[0] = { 1.0, 1.0, 1.0 };
vector_state.variables_[1] = { 1.0, 1.0, 1.0 };
vector_state.variables_[2] = { 1.0, 1.0, 1.0 };
vector_state.variables_[3] = { 1.0, 1.0, 1.0 };

vector_state.variables_[0] = { 1.0, 1.0, 1.0 };
vector_state.variables_[1] = { 1.0, 1.0, 1.0 };
vector_state.variables_[2] = { 1.0, 1.0, 1.0 };
vector_state.variables_[3] = { 1.0, 1.0, 1.0 };

vector_solver.CalculateRateConstants(vector_state);

auto vector_result = vector_solver.Solve(2*H, vector_state);
auto vector_result = vector_solver.Solve(2 * H, vector_state);
EXPECT_NE(vector_result.stats_.singular_, 0);
}
Loading

0 comments on commit 03e8dcf

Please sign in to comment.