Loading...
Searching...
No Matches
gpr::linalg::CholeskyPanels Class Reference

#include <gpr/linalg/CholeskyPanels.h>

Public Member Functions

 CholeskyPanels ()=default
 CholeskyPanels (Eigen::Index order, Eigen::Index width=panel_columns)
Eigen::MatrixXd toLower () const
Eigen::Index panelCount () const noexcept
Eigen::Map< Eigen::MatrixXd > panel (Eigen::Index index)
Eigen::Map< const Eigen::MatrixXd > panel (Eigen::Index index) const
Eigen::Index rows () const noexcept
Eigen::Index storedElements () const noexcept
bool hasSharedStorage () const noexcept
 Immutable factor storage shared by MPI ranks on the same host.
template<typename Derived>
void forwardSolveInPlace (Eigen::MatrixBase< Derived > &right) const
template<typename Derived>
void solveInPlace (Eigen::MatrixBase< Derived > &right) const

Static Public Member Functions

static CholeskyPanels fromLower (const Eigen::MatrixXd &lower)

Static Public Attributes

static constexpr Eigen::Index panel_columns = 64
static constexpr Eigen::Index row_block = 512

Friends

class ScalapackPDPotrfInverse

Detailed Description

Lower Cholesky columns stored in panels, without the unused upper blocks. Solves use dense triangular diagonal blocks and matrix products below them.

Definition at line 21 of file CholeskyPanels.h.

Constructor & Destructor Documentation

◆ CholeskyPanels() [1/2]

gpr::linalg::CholeskyPanels::CholeskyPanels ( )
default

◆ CholeskyPanels() [2/2]

gpr::linalg::CholeskyPanels::CholeskyPanels ( Eigen::Index order,
Eigen::Index width = panel_columns )
inlineexplicit

Definition at line 31 of file CholeskyPanels.h.

33 : CholeskyPanels(order, width, {})
34 {
35 }

Member Function Documentation

◆ forwardSolveInPlace()

template<typename Derived>
void gpr::linalg::CholeskyPanels::forwardSolveInPlace ( Eigen::MatrixBase< Derived > & right) const
inline

Definition at line 136 of file CholeskyPanels.h.

137 {
138 if (right.rows() != order_)
139 throw std::invalid_argument("invalid Cholesky solve dimensions");
140 // Eigen's triangular solve always forms coeffRef(0, 0), which binds
141 // a null reference when a panel or the right-hand side is empty,
142 // and a later panel's middleRows would offset that null pointer.
143 if (order_ == 0 || right.cols() == 0) return;
144 Eigen::Index first = 0;
145 for (Eigen::Index i = 0; i < panelCount(); ++i) {
146 const auto block = panel(i);
147 const Eigen::Index columns = block.cols();
148 const Eigen::Index trailing = block.rows() - columns;
149 auto current = right.derived().middleRows(first, columns);
150 block.topRows(columns).triangularView<Eigen::Lower>().solveInPlace(
151 current);
152 if (trailing > 0) {
153 // Disjoint row blocks of the update run on the tile threads.
154 const Eigen::Index begin = first + columns;
155 const Eigen::Index chunks = blockCount(begin);
156 parallelFor(static_cast<long>(chunks), [&](long c) {
157 Eigen::Index r0, r1;
158 blockRange(begin, c, r0, r1);
159 right.derived().middleRows(r0, r1 - r0).noalias() -=
160 block.middleRows(r0 - first, r1 - r0) * current;
161 });
162 }
163 first += columns;
164 }
165 }
Eigen::Map< Eigen::MatrixXd > panel(Eigen::Index index)
void solveInPlace(Eigen::MatrixBase< Derived > &right) const
Eigen::Index panelCount() const noexcept
void parallelFor(long count, F &&fn)
parallelFor(count, fn): see TilePool::run.

◆ fromLower()

CholeskyPanels gpr::linalg::CholeskyPanels::fromLower ( const Eigen::MatrixXd & lower)
inlinestatic

Definition at line 65 of file CholeskyPanels.h.

66 {
67 if (lower.rows() != lower.cols())
68 throw std::invalid_argument("Cholesky factor must be square");
69 CholeskyPanels result(lower.rows());
70 for (Eigen::Index i = 0; i < result.panelCount(); ++i) {
71 const auto& part = result.panels_[i];
72 result.panel(i) =
73 lower.block(part.first, part.first, lower.rows() - part.first,
74 part.columns);
75 }
76 return result;
77 }

◆ hasSharedStorage()

bool gpr::linalg::CholeskyPanels::hasSharedStorage ( ) const
inlinenodiscardnoexcept

Immutable factor storage shared by MPI ranks on the same host.

Definition at line 130 of file CholeskyPanels.h.

131 {
132 return shared_values_ != nullptr;
133 }

◆ panel() [1/2]

Eigen::Map< Eigen::MatrixXd > gpr::linalg::CholeskyPanels::panel ( Eigen::Index index)
inlinenodiscard

Definition at line 97 of file CholeskyPanels.h.

98 {
99 const auto& part = panels_.at(static_cast<std::size_t>(index));
100 if (shared_values_ && shared_read_only_) {
101 values_ = Eigen::Map<const Eigen::VectorXd>(shared_values_.get(),
102 entries_);
103 shared_values_.reset();
104 shared_read_only_ = false;
105 }
106 double* data = shared_values_ ? shared_values_.get() : values_.data();
107 return {data + part.offset, order_ - part.first, part.columns};
108 }

◆ panel() [2/2]

Eigen::Map< const Eigen::MatrixXd > gpr::linalg::CholeskyPanels::panel ( Eigen::Index index) const
inlinenodiscard

Definition at line 110 of file CholeskyPanels.h.

112 {
113 const auto& part = panels_.at(static_cast<std::size_t>(index));
114 const double* data =
115 shared_values_ ? shared_values_.get() : values_.data();
116 return {data + part.offset, order_ - part.first, part.columns};
117 }

◆ panelCount()

Eigen::Index gpr::linalg::CholeskyPanels::panelCount ( ) const
inlinenodiscardnoexcept

Definition at line 92 of file CholeskyPanels.h.

93 {
94 return static_cast<Eigen::Index>(panels_.size());
95 }

◆ rows()

Eigen::Index gpr::linalg::CholeskyPanels::rows ( ) const
inlinenodiscardnoexcept

Definition at line 119 of file CholeskyPanels.h.

120 {
121 return order_;
122 }

◆ solveInPlace()

template<typename Derived>
void gpr::linalg::CholeskyPanels::solveInPlace ( Eigen::MatrixBase< Derived > & right) const
inline

Definition at line 168 of file CholeskyPanels.h.

169 {
170 forwardSolveInPlace(right);
171 if (order_ == 0 || right.cols() == 0) return;
172 Eigen::Index first = order_;
173 std::vector<Eigen::MatrixXd> partial;
174 for (Eigen::Index i = panelCount(); i > 0;) {
175 const auto block = panel(--i);
176 const Eigen::Index columns = block.cols();
177 const Eigen::Index trailing = block.rows() - columns;
178 first -= columns;
179 auto current = right.derived().middleRows(first, columns);
180 if (trailing > 0) {
181 // The sum over the trailing rows splits into row blocks whose
182 // products are taken independently and subtracted in
183 // ascending block order.
184 const Eigen::Index begin = first + columns;
185 const Eigen::Index chunks = blockCount(begin);
186 if (static_cast<Eigen::Index>(partial.size()) < chunks)
187 partial.resize(static_cast<std::size_t>(chunks));
188 parallelFor(static_cast<long>(chunks), [&](long c) {
189 Eigen::Index r0, r1;
190 blockRange(begin, c, r0, r1);
191 partial[static_cast<std::size_t>(c)].noalias() =
192 block.middleRows(r0 - first, r1 - r0).transpose() *
193 right.derived().middleRows(r0, r1 - r0);
194 });
195 for (Eigen::Index c = 0; c < chunks; ++c)
196 current -= partial[static_cast<std::size_t>(c)];
197 }
198 block.topRows(columns)
199 .transpose()
200 .triangularView<Eigen::Upper>()
201 .solveInPlace(current);
202 }
203 }
void forwardSolveInPlace(Eigen::MatrixBase< Derived > &right) const

◆ storedElements()

Eigen::Index gpr::linalg::CholeskyPanels::storedElements ( ) const
inlinenodiscardnoexcept

Definition at line 124 of file CholeskyPanels.h.

125 {
126 return entries_;
127 }

◆ toLower()

Eigen::MatrixXd gpr::linalg::CholeskyPanels::toLower ( ) const
inlinenodiscard

The dense lower factor, zero above the diagonal. O(n^2) storage, so for conditioning estimates and tests, not for solves.

Definition at line 81 of file CholeskyPanels.h.

82 {
83 Eigen::MatrixXd lower = Eigen::MatrixXd::Zero(order_, order_);
84 for (Eigen::Index i = 0; i < panelCount(); ++i) {
85 const auto& part = panels_[static_cast<std::size_t>(i)];
86 lower.block(part.first, part.first, order_ - part.first,
87 part.columns) = panel(i);
88 }
89 return lower;
90 }

◆ ScalapackPDPotrfInverse

friend class ScalapackPDPotrfInverse
friend

Definition at line 38 of file CholeskyPanels.h.

Member Data Documentation

◆ panel_columns

Eigen::Index gpr::linalg::CholeskyPanels::panel_columns = 64
staticconstexpr

Definition at line 23 of file CholeskyPanels.h.

◆ row_block

Eigen::Index gpr::linalg::CholeskyPanels::row_block = 512
staticconstexpr

Rows per independent block of the trailing products. Block edges lie on multiples of this count of the factor's row index, so the products do not depend on the thread count.

Definition at line 27 of file CholeskyPanels.h.


The documentation for this class was generated from the following file: