20 const Eigen::VectorXd& vector)
22 const Eigen::Index n = lower.rows();
23 if (n <= 0 || lower.cols() != n || vector.size() != n ||
26 if (vector.isZero(0.0))
return true;
27 Eigen::VectorXd update = vector;
28 for (Eigen::Index j = 0; j < n; ++j) {
29 const double diagonal = lower(j, j);
30 const double radius = std::hypot(diagonal, update(j));
31 if (!(diagonal > 0.0) || !std::isfinite(radius))
return false;
32 const double cosine = diagonal / radius;
33 const double sine = update(j) / radius;
35 for (Eigen::Index i = j + 1; i < n; ++i) {
36 const double value = lower(i, j);
37 const double tail = update(i);
38 lower(i, j) = std::fma(sine, tail, cosine * value);
39 update(i) = std::fma(-sine, value, cosine * tail);
54#ifdef GPR_LINALG_SCALAPACK
56 const int n = state.cached_n();
57 if (!state.has_cached_L() || n <= 0 || vector.size() != n ||
60 if (vector.isZero(0.0))
return true;
61 state.invalidate_derived_cholesky();
62 const int block = state.block_size();
63 const bool linear = state.cached_L_desc()[1] == state.lin_context();
64 const int grid_rows = linear ? state.nprocs() : state.nprow();
65 const int grid_cols = linear ? 1 : state.npcol();
66 const int proc_row = linear ? state.lin_myrow() : state.myrow();
67 const int proc_col = linear ? state.lin_mycol() : state.mycol();
68 const int rows = linear ? state.lin_local_rows(n) : state.local_rows(n);
69 std::vector<int> global_rows;
70 global_rows.reserve(rows);
71 for (
int i = 0; i < n; ++i)
72 if ((i / block) % grid_rows == proc_row) global_rows.push_back(i);
73 Eigen::VectorXd update = vector;
74 std::vector<double> row_update(
static_cast<std::size_t
>(rows));
75 std::vector<double> rotations(
76 1 + 2 *
static_cast<std::size_t
>(std::min(block, n)));
79 const auto comms = state.tile_communicators(state.cached_L_desc()[1]);
80 double* factor = state.cached_L_mut();
82 for (
int first = 0; first < n;) {
83 const int width = std::min(block, n - first);
84 const int end = first + width;
85 const int owner_row = (first / block) % grid_rows;
86 const int owner_col = (first / block) % grid_cols;
87 const int local_first_col =
88 state.local_index_for_global(first, block, owner_col, grid_cols);
93 if (proc_row == owner_row && proc_col == owner_col) {
94 const int local_first_row = state.local_index_for_global(
95 first, block, owner_row, grid_rows);
96 for (
int offset = 0; offset < width; ++offset) {
97 const int j = first + offset;
100 static_cast<std::size_t
>(local_first_col + offset) * rows;
101 const double diagonal = column[local_first_row + offset];
102 const double radius = std::hypot(diagonal, update(j));
103 if (!(diagonal > 0.0) || !std::isfinite(radius)) {
107 const double cosine = diagonal / radius;
108 const double sine = update(j) / radius;
109 rotations[1 + 2 * offset] = cosine;
110 rotations[2 + 2 * offset] = sine;
111 column[local_first_row + offset] = radius;
112 for (
int i = offset + 1; i < width; ++i) {
113 const double value = column[local_first_row + i];
114 const double tail = update(first + i);
115 column[local_first_row + i] =
116 std::fma(sine, tail, cosine * value);
117 update(first + i) = std::fma(-sine, value, cosine * tail);
122 rotations.data(), 1 + 2 * width, MPI_DOUBLE,
123 comms.rank_of[
static_cast<std::size_t
>(owner_row) * grid_cols +
126 if (rotations[0] == 0.0) {
130 if (proc_col == owner_col && rows > 0) {
131 for (
int offset = 0; offset < width; ++offset) {
132 const double cosine = rotations[1 + 2 * offset];
133 const double sine = rotations[2 + 2 * offset];
136 static_cast<std::size_t
>(local_first_col + offset) * rows;
137 for (
int local_row = 0; local_row < rows; ++local_row) {
138 const int i = global_rows[local_row];
139 if (i < end)
continue;
140 const double value = column[local_row];
141 const double tail = update(i);
142 column[local_row] = std::fma(sine, tail, cosine * value);
143 update(i) = std::fma(-sine, value, cosine * tail);
146 for (
int local_row = 0; local_row < rows; ++local_row)
147 row_update[local_row] = update(global_rows[local_row]);
151 MPI_Bcast(row_update.data(), rows, MPI_DOUBLE, owner_col, comms.row);
152 for (
int local_row = 0; local_row < rows; ++local_row)
153 update(global_rows[local_row]) = row_update[local_row];
156 if (!valid) state.invalidate_L();