24 static std::string
name() {
return "diagonal"; }
25 static std::string
doc() {
return "Direct diagonal solver (CSR scan)"; }
26 static std::string
schema() {
return "none"; }
31 auto start = std::chrono::steady_clock::now();
33 const auto rhs = sys.
rhs();
34 const auto mtx = sys.
matrix();
35 const auto mtxV = mtx.view();
36 auto [colIdx, rowOffs] = sys.
matrix().sparsity()->view();
37 auto [xV, bV] =
views(x, rhs);
39 NF_ASSERT(bV.size() + 1 == rowOffs.size(),
"Inconsistent rowOffs.size()");
44 const auto rowBegin = rowOffs[i];
45 const auto rowEnd = rowOffs[i + 1];
48 for (
localIdx k = rowBegin; k < rowEnd; ++k)
59 Kokkos::abort(
"DiagonalSolver: diagonal entry not found");
62 xV[i] = bV[i] / mtxV.values[diagIdx];
64 "DiagonalSolver::solve<scalar>"
69 auto end = std::chrono::steady_clock::now();
70 auto ms =
static_cast<scalar>(
71 std::chrono::duration_cast<std::chrono::microseconds>(end - start).count()
75 return {1, 0.0, 0.0, ms};
81 const auto rhs = sys.
rhs();
82 const auto mtx = sys.
matrix();
83 const auto mtxV = mtx.view();
84 auto [colIdx, rowOffs] = sys.
matrix().sparsity()->view();
86 auto [xV, bV] =
views(x, rhs);
92 const auto rowBegin = rowOffs[i];
93 const auto rowEnd = rowOffs[i + 1];
96 for (
localIdx k = rowBegin; k < rowEnd; ++k)
107 Kokkos::abort(
"DiagonalSolver<Vec3>: diagonal entry not found");
110 const Vec3& a = mtxV.values[diagIdx];
111 const Vec3& b = bV[i];
120 "DiagonalSolver::solve<Vec3>"
124 return {{1, 0.0, 0.0, 0.0}};
127 std::unique_ptr<SolverFactory>
clone()
const override
129 return std::make_unique<DiagonalSolver>(*
this);
A class representing a dictionary that stores key-value pairs.
A class for the representation of a 3D Vec3.
A class to contain the data and executors for a field and define some basic operations.
const Executor & exec() const
Gets the executor associated with the field.
SolverStats solve(const la::LinearSystem< Vec3 > &sys, Vector< Vec3 > &x) const override
DiagonalSolver(const Executor &exec, const Dictionary &)
std::unique_ptr< SolverFactory > clone() const override
static std::string schema()
SolverStats solve(const la::LinearSystem< scalar > &sys, Vector< scalar > &x) const override
static std::string name()
A class representing a linear system of equations.
Vector< RHSValueType > & rhs()
SystemMatrixType & matrix()
A template class for registering derived classes with a base class.
#define NF_ASSERT(condition, message)
Macro for asserting a condition and printing an error message if the condition is false.
void fence(const Executor &exec)
std::variant< SerialExecutor, CPUExecutor, GPUExecutor > Executor
void parallelFor(const ExecutorType &, std::pair< localIdx, localIdx > range, const Kernel &kernel, std::string name)
auto views(Types &... args)
Unpacks all views of the passed classes.