flow 1.4.0
Kokkos cut-cell IBM incompressible Navier-Stokes solver + pnm pore extraction
Loading...
Searching...
No Matches
mg_bottom_direct.hpp
Go to the documentation of this file.
1
40#pragma once
41
42#include <Kokkos_Core.hpp>
43
44#include "mac_cutcell.hpp"
45
46namespace peclet::flow {
47
48// Unrolling the single-accumulator dot loops keeps several independent loads in flight; it changes
49// no operation and no order (bitwise-neutral).
50#if defined(__CUDACC__) || defined(__HIPCC__)
51#define PECLET_BOTTOM_UNROLL _Pragma("unroll 16")
52#else
53#define PECLET_BOTTOM_UNROLL
54#endif
55// The host factor's lane loops (one output per iteration, no reduction): `omp simd` on a host
56// compiler. With -ffp-contract=off (the host flags) vectorizing them changes no bit.
57#if defined(__CUDACC__) || defined(__HIPCC__)
58#define PECLET_BOTTOM_HOST_SIMD
59#else
60#define PECLET_BOTTOM_HOST_SIMD PECLET_FLOW_OMP_SIMD
61#endif
62
63inline constexpr int kBottomMaxPlane = 192; // b cap (§13.9 Q-D5)
64inline constexpr int kBottomTile = 16; // Cholesky tile (compile time: it fixes the order)
65inline constexpr double kBottomPivotTol = 1e-6;
66inline constexpr int kBottomAttempts = 3; // shifts 0, 1e-4, 1e-2
67KOKKOS_INLINE_FUNCTION double bottomShift(int attempt) {
68 return attempt == 0 ? 0.0 : (attempt == 1 ? 1e-4 : 1e-2);
69}
70
71// The factor ordering, decided on the host at hierarchy build from the domain BC flags (§13.4.1).
72// Plane k = the coordinate along the slow axis s (P = n_s planes); the in-plane index is
73// q = c[a0] + n[a0] * c[a1] with a0 < a1 the other two axes; the factor-order index is k*b + q.
75 int s = -1; // slow axis; -1 = no axis gives b <= kBottomMaxPlane (ineligible)
76 int a0 = 0, a1 = 1;
77 int P = 0, b = 0;
78 int n[3] = {0, 0, 0}; // the bottom's inner dims
79 int bcf[6] = {0, 0, 0, 0, 0, 0}; // per face (-x,+x,-y,+y,-z,+z): 1 = non-periodic (excluded)
80 int border = 0; // periodic slow axis with P >= 3
81 KOKKOS_INLINE_FUNCTION bool valid() const { return s >= 0; }
82};
83
84// §13.4.1: the candidates are the non-periodic axes (all three if there are none); the longest
85// wins, a tie to the higher index (z > y > x). If its plane b = n / n_s exceeds kBottomMaxPlane,
86// the remaining axes are tried in decreasing length (the same tie rule); none fits -> s = -1.
87inline BottomPlanes bottomChoosePlanes(C3 inner, const int bc[6]) {
89 p.n[0] = inner.x;
90 p.n[1] = inner.y;
91 p.n[2] = inner.z;
92 int per[3];
93 for (int f = 0; f < 6; ++f)
94 p.bcf[f] = bc[f] != 0 ? 1 : 0;
95 for (int a = 0; a < 3; ++a)
96 per[a] = (bc[2 * a] == 0 && bc[2 * a + 1] == 0) ? 1 : 0;
97 const long ncell = (long)inner.x * inner.y * inner.z;
98 auto longer = [&](int a, int c) { return p.n[a] > p.n[c] || (p.n[a] == p.n[c] && a > c); };
99 int first = -1;
100 const bool anyWall = !per[0] || !per[1] || !per[2];
101 for (int a = 0; a < 3; ++a)
102 if ((!anyWall || !per[a]) && (first < 0 || longer(a, first)))
103 first = a;
104 auto fits = [&](int a) { return p.n[a] > 0 && ncell / p.n[a] <= kBottomMaxPlane; };
105 int s = -1;
106 if (fits(first)) {
107 s = first;
108 } else {
109 int r[2], m = 0;
110 for (int a = 0; a < 3; ++a)
111 if (a != first)
112 r[m++] = a;
113 if (longer(r[1], r[0])) {
114 const int t = r[0];
115 r[0] = r[1];
116 r[1] = t;
117 }
118 for (int i = 0; i < 2 && s < 0; ++i)
119 if (fits(r[i]))
120 s = r[i];
121 }
122 if (s < 0)
123 return p;
124 p.s = s;
125 p.a0 = (s == 0) ? 1 : 0;
126 p.a1 = (s == 2) ? 1 : 2;
127 p.P = p.n[s];
128 p.b = (int)(ncell / p.P);
129 p.border = (per[s] && p.P >= 3) ? 1 : 0;
130 return p;
131}
132
133// The direct engine's device storage and its M (§13.4.4, §13.4.7). Ghost width 1 (single rank).
134template <class FacReal>
136 using Mat = Kokkos::View<FacReal***, Kokkos::LayoutRight, CCMem>;
137 using Sq = Kokkos::View<FacReal**, Kokkos::LayoutRight, CCMem>;
139 C3 ext{0, 0, 0};
140 Mat Q; // [P][b][b]: Q(k, j, i) = (Sigma_k^{-1})_{ij} (symmetric, stored both ways)
141 Mat Y; // [P-1][b][b] (border only): Y(k, j, i) = Y_k(i, j)
142 Sq e; // [P][b]: e(k, q) = A~((q,k), (q,k-1)); e(0, .) the wrap coupling (border only)
143 Sq Sg, L, W; // [b][b] factor scratch: Sigma (lower), L, W = L^{-1} (both lower)
144 Kokkos::View<double*, CCMem> s; // [n] the scaling, factor order
145 Kokkos::View<FacReal*, CCMem> g, u; // [n] substitution vectors
146 // [0] facOk, [1] restarts, [2 + a] attempt a's fail flag (one slot per attempt: a flag that
147 // was reset for the next attempt could be read by a thread still leaving the last one)
148 Kokkos::View<int*, CCMem> stat;
149
151 BottomDirect d;
152 d.pl = p;
153 d.ext = ext;
154 if (!p.valid())
155 return d;
156 const int n = p.P * p.b;
157 d.Q = Mat("peclet::flow::mg_bottom_Q", p.P, p.b, p.b);
158 if (p.border)
159 d.Y = Mat("peclet::flow::mg_bottom_Y", p.P - 1, p.b, p.b);
160 d.e = Sq("peclet::flow::mg_bottom_e", p.P, p.b);
161 d.Sg = Sq("peclet::flow::mg_bottom_sigma", p.b, p.b);
162 d.L = Sq("peclet::flow::mg_bottom_L", p.b, p.b);
163 d.W = Sq("peclet::flow::mg_bottom_W", p.b, p.b);
164 d.s = Kokkos::View<double*, CCMem>("peclet::flow::mg_bottom_s", n);
165 d.g = Kokkos::View<FacReal*, CCMem>("peclet::flow::mg_bottom_g", n);
166 d.u = Kokkos::View<FacReal*, CCMem>("peclet::flow::mg_bottom_u", n);
167 d.stat = Kokkos::View<int*, CCMem>("peclet::flow::mg_bottom_stat", 2 + kBottomAttempts);
168 return d;
169 }
170 KOKKOS_INLINE_FUNCTION int n() const { return pl.P * pl.b; }
171 // factor index f -> inner coordinates (0-based) and the flat ext index
172 KOKKOS_INLINE_FUNCTION void coords(int f, int c[3]) const {
173 const int k = f / pl.b, q = f - k * pl.b;
174 const int c1 = q / pl.n[pl.a0];
175 c[pl.s] = k;
176 c[pl.a0] = q - c1 * pl.n[pl.a0];
177 c[pl.a1] = c1;
178 }
179 KOKKOS_INLINE_FUNCTION int extIndex(const int c[3]) const {
180 return (c[0] + 1) + (c[1] + 1) * ext.x + (c[2] + 1) * ext.x * ext.y;
181 }
182 KOKKOS_INLINE_FUNCTION int extOf(int f) const {
183 int c[3];
184 coords(f, c);
185 return extIndex(c);
186 }
187 KOKKOS_INLINE_FUNCTION int factorIndex(const int c[3]) const {
188 return c[pl.s] * pl.b + c[pl.a0] + pl.n[pl.a0] * c[pl.a1];
189 }
190 // Face f6 (0..5 = -x, +x, -y, +y, -z, +z) of the cell at c (ext index i): its coefficient (the
191 // A2 face form: the low face of i, or of i's +axis neighbour) and the neighbour's coordinates,
192 // wrapped on a periodic axis; false where it crosses a non-periodic domain face (GraphAMG's
193 // exclusion: no partner, and no part of the re-summed diagonal).
194 template <class OpV>
195 KOKKOS_INLINE_FUNCTION bool face(const OpV& AFX, const OpV& AFY, const OpV& AFZ, const int c[3],
196 int i, int f6, int nb[3], double& af) const {
197 const int a = f6 >> 1, side = f6 & 1;
198 nb[0] = c[0];
199 nb[1] = c[1];
200 nb[2] = c[2];
201 int v = c[a] + (side ? 1 : -1);
202 if (v < 0 || v >= pl.n[a]) {
203 if (pl.bcf[f6])
204 return false;
205 v = (v < 0) ? v + pl.n[a] : v - pl.n[a];
206 }
207 nb[a] = v;
208 const int st = (a == 0) ? 1 : (a == 1 ? ext.x : ext.x * ext.y);
209 const int slotIdx = side ? i + st : i;
210 af = (a == 0) ? (double)AFX(slotIdx) : (a == 1 ? (double)AFY(slotIdx) : (double)AFZ(slotIdx));
211 return true;
212 }
213
214 // M (§13.4.4): z = s * x~ on the fluid cells (comp >= 0), 0 on the other inner cells, where
215 // x~ = (A~')^{-1} FacReal(s r) by the stored factor. With `keep`, z's old inner values go there
216 // first (the FCG's z_prev), fused into the cast phase. The caller removes the component means.
217 //
218 // The substitution (u -> g = x~) has two schedules with the same bits. The TEAM schedule (every
219 // device backend; a host backend's oracle, `teamAlgorithm`) gives each row i a thread whose
220 // serial `acc += Q(k, j, i) * v_j` runs j = 0 .. b-1. The host LANE schedule (doc/
221 // vof_distributed_partition_design.md §5.3, B1) forms v_j once per plane with the same
222 // expression and runs the rows as SIMD lanes, j ascending: each acc[i] sees the same operands in
223 // the same order, so under -ffp-contract=off (the host flags) it is bitwise the team schedule.
224 // On a host backend the production launch has team size 1 (kBottomHostTeam); a larger team
225 // splits each plane's rows into contiguous shares.
226 static constexpr bool kHostLaneM = std::is_same_v<CCMem, Kokkos::HostSpace>;
227 template <class Member, class RV, class ZV, class CV>
228 KOKKOS_INLINE_FUNCTION void apply(const Member& t, const RV& r, const ZV& z, const CV& comp,
229 const ZV* keep, bool teamAlgorithm = false) const {
230 const int P = pl.P, b = pl.b, nn = P * b;
231 Kokkos::parallel_for(Kokkos::TeamThreadRange(t, nn), [&](int f) {
232 const int ei = extOf(f);
233 if (keep)
234 (*keep)(ei) = z(ei);
235 u(f) = (FacReal)(s(f) * r(ei));
236 });
237 t.team_barrier();
238 if constexpr (kHostLaneM) {
239 if (teamAlgorithm)
241 else
243 } else {
245 }
246 Kokkos::parallel_for(Kokkos::TeamThreadRange(t, nn), [&](int f) {
247 const int ei = extOf(f);
248 z(ei) = (comp(ei) >= 0) ? s(f) * (double)g(f) : 0.0;
249 });
250 t.team_barrier();
251 }
252 // acc[i] = sum_j x[j b + i] * v[j], j = 0 .. b-1 IN THAT ORDER from acc[i] = 0, lanes i in
253 // [lo, hi): four j per pass over the lanes (acc loaded and stored once per four terms), each lane
254 // still adding its terms one at a time in ascending j.
255 KOKKOS_INLINE_FUNCTION static void laneMatVec(FacReal* acc, const FacReal* x, const FacReal* v,
256 int b, int lo, int hi) {
258 for (int i = lo; i < hi; ++i)
259 acc[i] = 0;
260 int j = 0;
261 for (; j + 4 <= b; j += 4) {
262 const FacReal *x0 = x + j * b, *x1 = x0 + b, *x2 = x1 + b, *x3 = x2 + b;
263 const FacReal v0 = v[j], v1 = v[j + 1], v2 = v[j + 2], v3 = v[j + 3];
265 for (int i = lo; i < hi; ++i) {
266 FacReal a = acc[i];
267 a += x0[i] * v0;
268 a += x1[i] * v1;
269 a += x2[i] * v2;
270 a += x3[i] * v3;
271 acc[i] = a;
272 }
273 }
274 for (; j < b; ++j) {
275 const FacReal* xj = x + j * b;
276 const FacReal vj = v[j];
278 for (int i = lo; i < hi; ++i)
279 acc[i] += xj[i] * vj;
280 }
281 }
282 // The host lane schedule (B1). Q(k, j, .) and Y(k, j, .) are unit-stride in i (LayoutRight).
283 template <class Member>
284 KOKKOS_INLINE_FUNCTION void laneSubstitute(const Member& t) const {
285 const int P = pl.P, b = pl.b;
286 const int Pt = pl.border ? P - 1 : P;
287 const int rank = t.team_rank(), T = t.team_size();
288 const int lo = (int)((long)b * rank / T), hi = (int)((long)b * (rank + 1) / T);
289 FacReal* gp = g.data();
290 const FacReal* up = u.data();
291 FacReal acc[kBottomMaxPlane], v[kBottomMaxPlane];
292 for (int k = 0; k < Pt; ++k) { // forward
293 const int o = k * b, op = o - b;
294 if (k == 0) {
295 for (int j = 0; j < b; ++j)
296 v[j] = up[o + j];
297 } else {
298 for (int j = 0; j < b; ++j)
299 v[j] = up[o + j] - e(k, j) * gp[op + j];
300 }
301 laneMatVec(acc, &Q(k, 0, 0), v, b, lo, hi);
303 for (int i = lo; i < hi; ++i)
304 gp[o + i] = acc[i];
305 t.team_barrier();
306 }
307 for (int k = Pt - 2; k >= 0; --k) { // backward (in place: x~ overwrites g)
308 const int o = k * b, on = o + b;
309 for (int j = 0; j < b; ++j)
310 v[j] = e(k + 1, j) * gp[on + j];
311 laneMatVec(acc, &Q(k, 0, 0), v, b, lo, hi);
313 for (int i = lo; i < hi; ++i)
314 gp[o + i] = gp[o + i] - acc[i];
315 t.team_barrier();
316 }
317 if (pl.border) {
318 const int oB = (P - 1) * b, oL = (P - 2) * b;
319 for (int j = 0; j < b; ++j)
320 v[j] = (up[oB + j] - e(0, j) * gp[j]) - e(P - 1, j) * gp[oL + j];
321 laneMatVec(acc, &Q(P - 1, 0, 0), v, b, lo, hi);
323 for (int i = lo; i < hi; ++i)
324 gp[oB + i] = acc[i];
325 t.team_barrier();
326 for (int j = 0; j < b; ++j)
327 v[j] = gp[oB + j];
328 for (int k = 0; k < P - 1; ++k) {
329 const int o = k * b;
330 laneMatVec(acc, &Y(k, 0, 0), v, b, lo, hi);
332 for (int i = lo; i < hi; ++i)
333 gp[o + i] = gp[o + i] - acc[i];
334 }
335 t.team_barrier();
336 }
337 }
338 // The team schedule.
339 template <class Member>
340 KOKKOS_INLINE_FUNCTION void teamSubstitute(const Member& t) const {
341 const int P = pl.P, b = pl.b;
342 const int Pt = pl.border ? P - 1 : P;
343 for (int k = 0; k < Pt; ++k) { // forward
344 const int o = k * b, op = o - b;
345 Kokkos::parallel_for(Kokkos::TeamThreadRange(t, b), [&](int i) {
346 FacReal acc = 0;
347 if (k == 0) {
349 for (int j = 0; j < b; ++j)
350 acc += Q(k, j, i) * u(o + j);
351 } else {
353 for (int j = 0; j < b; ++j)
354 acc += Q(k, j, i) * (u(o + j) - e(k, j) * g(op + j));
355 }
356 g(o + i) = acc;
357 });
358 t.team_barrier();
359 }
360 for (int k = Pt - 2; k >= 0; --k) { // backward (in place: x~ overwrites g)
361 const int o = k * b, on = o + b;
362 Kokkos::parallel_for(Kokkos::TeamThreadRange(t, b), [&](int i) {
363 FacReal acc = 0;
365 for (int j = 0; j < b; ++j)
366 acc += Q(k, j, i) * (e(k + 1, j) * g(on + j));
367 g(o + i) = g(o + i) - acc;
368 });
369 t.team_barrier();
370 }
371 if (pl.border) { // x~_B = Q_B (r~_B - e_0 u_0 - e_{P-1} u_{P-2}); x~_k = u_k - Y_k x~_B
372 const int oB = (P - 1) * b, oL = (P - 2) * b;
373 Kokkos::parallel_for(Kokkos::TeamThreadRange(t, b), [&](int i) {
374 FacReal acc = 0;
376 for (int j = 0; j < b; ++j)
377 acc += Q(P - 1, j, i) * ((u(oB + j) - e(0, j) * g(j)) - e(P - 1, j) * g(oL + j));
378 g(oB + i) = acc;
379 });
380 t.team_barrier();
381 Kokkos::parallel_for(Kokkos::TeamThreadRange(t, oB), [&](int f) {
382 const int k = f / b, i = f - k * b;
383 FacReal acc = 0;
385 for (int j = 0; j < b; ++j)
386 acc += Y(k, j, i) * g(oB + j);
387 g(f) = g(f) - acc;
388 });
389 t.team_barrier();
390 }
391 }
392};
393
394// The factor launch (§13.4.3): one team, TeamPolicy(1, T). Inputs: the bottom level's face form,
395// its component labels (comp, ext-indexed; -1 = solid) and the per-component augmentation (kc =
396// the last plane, aug = 1/m_c; BottomLabelKernel). Output: D.Q, D.Y, D.e, D.s and D.stat.
397template <class FacReal, class OpV>
399 using Member = Kokkos::TeamPolicy<CCExec>::member_type;
400 // Level-0 (team) scratch, a bitwise-neutral staging of the factor's working set (§13.4.7): Ls =
401 // the current tile column of L (rows j0..b-1, the tile's columns; padded to kBottomTile + 1 so a
402 // warp's column reads hit distinct banks), St = the current diagonal tile of Sigma.
403 using SMat = Kokkos::View<FacReal**, Kokkos::LayoutRight, typename CCExec::scratch_memory_space,
404 Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
405 static std::size_t scratchBytes(int b) {
406 return SMat::shmem_size(b, kBottomTile + 1) + SMat::shmem_size(kBottomTile, kBottomTile + 1);
407 }
410 Kokkos::View<const int*, CCMem> comp, kc;
411 Kokkos::View<const double*, CCMem> aug;
412 double tauPiv0 = kBottomPivotTol; // the first attempt's pivot floor (a test hook raises it)
413 // A host backend runs the host schedule (hostAssemble / hostInvert / hostBorder) unless this
414 // test hook asks for the team algorithm, its bitwise oracle (ctest `bottom_direct` U8).
415 static constexpr bool kHostFactor = std::is_same_v<CCMem, Kokkos::HostSpace>;
417#ifdef PECLET_FLOW_BOTTOM_PROBE
418 // Phase-split probe of the team algorithm (doc/vof_gpu_coarse_tail_design.md §5.2 P2; compiled
419 // only into bench_bottom_factor): team rank 0 adds the clock ticks since the last mark to
420 // probe(cat) at each phase boundary; probe(kProbeLast) holds the last mark. Categories: 0
421 // scaling + couplings, 1 assemble, 2 diagonal tiles, 3 panel, 4 trailing, 5 W, 6 Q, 7 border.
422 static constexpr int kProbeLast = 15;
423 Kokkos::View<long long*, CCMem> probe;
424 KOKKOS_INLINE_FUNCTION void probeMark(const Member& t, int cat) const {
425 if (t.team_rank() == 0) {
426 const long long now = (long long)Kokkos::Impl::clock_tic();
427 if (cat >= 0)
428 probe(cat) += now - probe(kProbeLast);
429 probe(kProbeLast) = now;
430 }
431 }
432#define PECLET_BOTTOM_PROBE_MARK(t, cat) probeMark(t, cat)
433#else
434#define PECLET_BOTTOM_PROBE_MARK(t, cat)
435#endif
436
437 // s (§13.4.1): the re-summed diagonal and the scaling, one thread per cell
438 KOKKOS_INLINE_FUNCTION void scaling(const Member& t) const {
439 Kokkos::parallel_for(Kokkos::TeamThreadRange(t, D.n()), [&](int f) {
440 int c[3], nb[3];
441 D.coords(f, c);
442 const int i = D.extIndex(c);
443 double sum = 0.0, af = 0.0;
444 for (int f6 = 0; f6 < 6; ++f6)
445 if (D.face(AFX, AFY, AFZ, c, i, f6, nb, af))
446 sum += af;
447 const double d = -sum;
448 D.s(f) = (comp(i) >= 0 && d > 0.0) ? 1.0 / Kokkos::sqrt(d) : 0.0;
449 });
450 t.team_barrier();
451 }
452 // e (§13.4.1): e(k, q) accumulates, over cell (q,k)'s faces in order, s_i AF s_j for the faces
453 // whose neighbour lies in plane k-1 (mod P) != k -- for k = 0 only on a border axis. With P = 2
454 // on a periodic axis both faces of plane 1 land in e(1, .) and e(0, .) stays 0.
455 KOKKOS_INLINE_FUNCTION void couplings(const Member& t) const {
456 const int P = D.pl.P;
457 Kokkos::parallel_for(Kokkos::TeamThreadRange(t, D.n()), [&](int f) {
458 int c[3], nb[3];
459 D.coords(f, c);
460 const int i = D.extIndex(c), k = c[D.pl.s], q = f - k * D.pl.b;
461 const int km = (k - 1 + P) % P;
462 double v = 0.0, af = 0.0;
463 if (km != k && (k >= 1 || D.pl.border)) {
464 const double si = D.s(f);
465 for (int f6 = 0; f6 < 6; ++f6)
466 if (D.face(AFX, AFY, AFZ, c, i, f6, nb, af) && nb[D.pl.s] == km)
467 v += si * af * D.s(D.factorIndex(nb));
468 }
469 D.e(k, q) = (FacReal)v;
470 });
471 t.team_barrier();
472 }
473 // A^_k(i, j) in FP64 (§13.4.1-2): diagonal 1, + s_i AF s_j over cell i's faces whose neighbour
474 // is in-plane cell j (in order), + 1/m_c on component c's last plane, + delta on the diagonal.
475 KOKKOS_INLINE_FUNCTION double entry(int k, int i, int j, double delta) const {
476 const int b = D.pl.b, fi = k * b + i, fj = k * b + j;
477 int c[3], nb[3];
478 D.coords(fi, c);
479 const int ei = D.extIndex(c);
480 double v = (i == j) ? 1.0 : 0.0, af = 0.0;
481 const double si = D.s(fi);
482 for (int f6 = 0; f6 < 6; ++f6)
483 if (D.face(AFX, AFY, AFZ, c, ei, f6, nb, af) && D.factorIndex(nb) == fj)
484 v += si * af * D.s(fj);
485 const int ci = comp(ei);
486 if (ci >= 0 && ci < (int)kc.extent(0) && kc(ci) == k && comp(D.extOf(fj)) == ci)
487 v += aug(ci);
488 if (i == j)
489 v += delta;
490 return v;
491 }
492 // Sigma's lower triangle for plane k: mode 0 = A^_k; 1 = A^_k - diag(e_k) Q_{k-1} diag(e_k);
493 // 2 = the border A^_{P-1} - diag(e_0) Y_0 - diag(e_{P-1}) Y_{P-2}.
494 KOKKOS_INLINE_FUNCTION void assemble(const Member& t, int k, int mode, double delta,
495 const SMat& St) const {
496 const int b = D.pl.b, P = D.pl.P;
497 Kokkos::parallel_for(Kokkos::TeamThreadRange(t, b * b), [&](int idx) {
498 const int i = idx / b, j = idx - i * b;
499 if (j > i)
500 return;
501 FacReal a = (FacReal)entry(k, i, j, delta);
502 if (mode == 1)
503 a = a - D.e(k, i) * D.Q(k - 1, i, j) * D.e(k, j);
504 else if (mode == 2)
505 a = (a - D.e(0, i) * D.Y(0, j, i)) - D.e(P - 1, i) * D.Y(P - 2, j, i);
506 D.Sg(i, j) = a;
507 if (i < kBottomTile)
508 St(i, j) = a; // the first diagonal tile
509 });
510 t.team_barrier();
512 }
513 // Q(k) = Sigma^{-1} (§13.4.3, "Dense SPD inverse"). Returns false (team-uniform) on a pivot
514 // that is not > tauPiv (a NaN pivot included). Sigma's lower triangle is read from D.Sg and its
515 // current diagonal tile from St; the current tile column of L is kept in Ls (and stored to D.L
516 // for W). Each stored scalar is the same expression, in the same order, as without the staging.
517 KOKKOS_INLINE_FUNCTION bool invert(const Member& t, int k, double tauPiv, int flag,
518 const SMat& Ls, const SMat& St) const {
519 const int b = D.pl.b;
520 const auto& S = D.Sg;
521 const auto& L = D.L;
522 const auto& W = D.W;
523 for (int j0 = 0; j0 < b; j0 += kBottomTile) {
524 const int j1 = (j0 + kBottomTile < b) ? j0 + kBottomTile : b;
525 const int nc = j1 - j0;
526 // 1. the diagonal tile, column by column: row r of the tile (one thread) computes L(r, c)
527 // for every column c < r and, right after L(r, r - 1), its own pivot L(r, r) -- each
528 // scalar the single-thread column Cholesky's expression in its order; one barrier per
529 // column publishes the column.
530 for (int c = -1; c < nc; ++c) {
531 Kokkos::parallel_for(Kokkos::TeamThreadRange(t, nc), [&](int r) {
532 if (r <= c)
533 return;
534 const int i = j0 + r;
535 if (c >= 0) { // L(i, j) for j = j0 + c
536 const int j = j0 + c;
537 FacReal a2 = 0;
538 for (int m = 0; m < c; ++m)
539 a2 += Ls(i, m) * Ls(j, m);
540 const FacReal lij = (St(r, c) - a2) / Ls(j, c);
541 Ls(i, c) = lij;
542 L(i, j) = lij;
543 }
544 if (r == c + 1) { // the pivot of column r: every L(i, m < r) is this thread's own
545 FacReal acc = 0;
546 for (int m = 0; m < r; ++m)
547 acc += Ls(i, m) * Ls(i, m);
548 const FacReal p = St(r, r) - acc;
549 if (!((double)p > tauPiv))
550 D.stat(flag) = 1;
551 const FacReal lii = Kokkos::sqrt(p);
552 Ls(i, r) = lii;
553 L(i, i) = lii;
554 }
555 });
556 t.team_barrier();
557 }
559 if (D.stat(flag))
560 return false;
561 if (j1 < b) {
562 Kokkos::parallel_for(Kokkos::TeamThreadRange(t, j1, b), [&](int i) { // 2. the panel
563 for (int c = 0; c < nc; ++c) {
564 const int j = j0 + c;
565 FacReal acc = 0;
566 for (int m = 0; m < c; ++m)
567 acc += Ls(i, m) * Ls(j, m);
568 const FacReal lij = (S(i, j) - acc) / Ls(j, c);
569 Ls(i, c) = lij;
570 L(i, j) = lij;
571 }
572 });
573 t.team_barrier();
575 const int nt = b - j1; // 3. the trailing update, i >= j below the tile
576 Kokkos::parallel_for(Kokkos::TeamThreadRange(t, nt * nt), [&](int idx) {
577 const int i = j1 + idx / nt, j = j1 + (idx - (idx / nt) * nt);
578 if (j > i)
579 return;
580 FacReal acc = 0;
581 for (int m = 0; m < nc; ++m)
582 acc += Ls(i, m) * Ls(j, m);
583 const FacReal v = S(i, j) - acc;
584 S(i, j) = v;
585 if (i < j1 + kBottomTile)
586 St(i - j1, j - j1) = v; // the next diagonal tile
587 });
588 t.team_barrier();
590 }
591 }
592 // W = L^{-1}: W(j, j) = 1 / L(j, j), W(i, j) = -(sum_{m=j}^{i-1} L(i, m) W(m, j)) / L(i, i) in
593 // ascending m, by row blocks of kBottomTile: (1) every thread takes one (row i of the block,
594 // column j left of it) and sums the terms m < i0 into A(r, j) (Ls's storage); (2) thread j
595 // continues the SAME accumulator over the block's own rows (the L tile staged in St, its new
596 // W(m, j) in registers) -- each W(i, j) is the column recurrence's expression in its order.
597 const SMat A(Ls.data(), kBottomTile, b);
598 for (int i0 = 0; i0 < b; i0 += kBottomTile) {
599 const int i1 = (i0 + kBottomTile < b) ? i0 + kBottomTile : b;
600 const int nr = i1 - i0;
601 Kokkos::parallel_for(Kokkos::TeamThreadRange(t, nr * i0 + nr * nr), [&](int idx) {
602 if (idx < nr * i0) {
603 const int r = idx / i0, j = idx - r * i0, i = i0 + r;
604 FacReal acc = 0;
606 for (int m = j; m < i0; ++m)
607 acc += L(i, m) * W(m, j);
608 A(r, j) = acc;
609 } else {
610 const int q = idx - nr * i0, r = q / nr, c = q - r * nr;
611 if (c <= r)
612 St(r, c) = L(i0 + r, i0 + c);
613 }
614 });
615 t.team_barrier();
616 Kokkos::parallel_for(Kokkos::TeamThreadRange(t, i1), [&](int j) {
617 FacReal wb[kBottomTile]; // W(i0 + r, j) of this block, this column
618 for (int r = 0; r < kBottomTile; ++r) {
619 if (r >= nr)
620 break;
621 const int i = i0 + r;
622 if (j > i) {
623 wb[r] = 0;
624 continue;
625 }
626 if (j == i) {
627 wb[r] = FacReal(1) / St(r, r);
628 W(i, j) = wb[r];
629 continue;
630 }
631 FacReal acc = (j < i0) ? A(r, j) : FacReal(0);
632 const int m0 = (j > i0) ? j : i0;
633 for (int m = m0; m < i; ++m)
634 acc += St(r, m - i0) * wb[m - i0];
635 wb[r] = -acc / St(r, r);
636 W(i, j) = wb[r];
637 }
638 });
639 t.team_barrier();
640 }
642 Kokkos::parallel_for(Kokkos::TeamThreadRange(t, b * b), [&](int idx) { // Q = W^T W
643 const int i = idx / b, j = idx - i * b;
644 if (j > i)
645 return;
646 FacReal acc = 0;
648 for (int m = i; m < b; ++m)
649 acc += W(m, i) * W(m, j);
650 D.Q(k, i, j) = acc;
651 D.Q(k, j, i) = acc;
652 });
653 t.team_barrier();
655 return true;
656 }
657 // The border's Y = T^{-1} B by the solve's own substitution, one column c per (c, i) pair:
658 // B's block 0 = diag(e_0), block P-2 = diag(e_{P-1}).
659 KOKKOS_INLINE_FUNCTION void border(const Member& t) const {
660 const int P = D.pl.P, b = D.pl.b;
661 for (int k = 0; k <= P - 2; ++k) { // forward
662 Kokkos::parallel_for(Kokkos::TeamThreadRange(t, b * b), [&](int idx) {
663 const int c = idx / b, i = idx - c * b;
664 FacReal acc = 0;
666 for (int j = 0; j < b; ++j) {
667 FacReal bj = 0;
668 if (j == c)
669 bj = (k == 0 ? D.e(0, j) : FacReal(0)) + (k == P - 2 ? D.e(P - 1, j) : FacReal(0));
670 const FacReal br = (k == 0) ? bj : bj - D.e(k, j) * D.Y(k - 1, c, j);
671 acc += D.Q(k, j, i) * br;
672 }
673 D.Y(k, c, i) = acc;
674 });
675 t.team_barrier();
676 }
677 for (int k = P - 3; k >= 0; --k) { // backward
678 Kokkos::parallel_for(Kokkos::TeamThreadRange(t, b * b), [&](int idx) {
679 const int c = idx / b, i = idx - c * b;
680 FacReal acc = 0;
682 for (int j = 0; j < b; ++j)
683 acc += D.Q(k, j, i) * (D.e(k + 1, j) * D.Y(k + 1, c, j));
684 D.Y(k, c, i) = D.Y(k, c, i) - acc;
685 });
686 t.team_barrier();
687 }
689 }
690
691 // --- The host schedule (§14 H-1, A(b)) ------------------------------------------------------
692 // The same scalars as assemble / invert / border, each the same expression with its operands in
693 // the same order; what changes is who computes what between barriers. Scratch layouts (host
694 // only): Sg holds Sigma's lower triangle by COLUMNS, S[j b + i] = Sigma(i, j) for i >= j; L holds
695 // L by columns, Lt[m b + i] = L(i, m); W is row-major W(i, j) as on a device. A lane loop runs
696 // over independent outputs (rows i, or columns j), each lane continuing its own accumulator in
697 // ascending order, so vectorizing it reorders nothing. A thread takes a contiguous share of the
698 // outputs, balanced by their cost (hostShare), or every T-th column where columns are far apart.
699
700 // acc[i] += x[m b + i] * y[m b] for m = m0 .. m1-1 IN THAT ORDER, each lane i in [lo, hi): four
701 // m per pass over the lanes, so acc is loaded and stored once per four terms -- each lane still
702 // adds its terms one at a time in ascending m.
703 KOKKOS_INLINE_FUNCTION static void hostAccumulate(FacReal* acc, const FacReal* x,
704 const FacReal* y, int b, int m0, int m1, int lo,
705 int hi) {
706 int m = m0;
707 for (; m + 4 <= m1; m += 4) {
708 const FacReal *x0 = x + m * b, *x1 = x0 + b, *x2 = x1 + b, *x3 = x2 + b;
709 const FacReal y0 = y[m * b], y1 = y[(m + 1) * b], y2 = y[(m + 2) * b], y3 = y[(m + 3) * b];
711 for (int i = lo; i < hi; ++i) {
712 FacReal a = acc[i];
713 a += x0[i] * y0;
714 a += x1[i] * y1;
715 a += x2[i] * y2;
716 a += x3[i] * y3;
717 acc[i] = a;
718 }
719 }
720 for (; m < m1; ++m) {
721 const FacReal* xm = x + m * b;
722 const FacReal ym = y[m * b];
724 for (int i = lo; i < hi; ++i)
725 acc[i] += xm[i] * ym;
726 }
727 }
728 // [lo, hi): this thread's contiguous share of [0, n) when index i costs w(i) -- equal prefix
729 // shares of the total. Contiguous, not round-robin: neighbouring outputs share cache lines.
730 template <class Wf>
731 KOKKOS_INLINE_FUNCTION static void hostShare(const Member& t, int n, const Wf& w, int& lo,
732 int& hi) {
733 const int rank = t.team_rank(), T = t.team_size();
734 double tot = 0.0;
735 for (int i = 0; i < n; ++i)
736 tot += w(i);
737 lo = n;
738 hi = n;
739 double cum = 0.0;
740 for (int i = 0; i < n; ++i) {
741 if (lo == n && cum >= tot * rank / T)
742 lo = i;
743 if (cum >= tot * (rank + 1) / T) {
744 hi = i;
745 break;
746 }
747 cum += w(i);
748 }
749 if (lo > hi)
750 lo = hi;
751 }
752 // assemble: the team version's entry() per (i, j) re-scans cell i's six faces for every j; here
753 // a row's dense values start at entry()'s initial value and each face adds its term to its own
754 // partner j in face order -- per (i, j) the same additions in the same order -- then the
755 // augmentation, then delta on the diagonal, then the cast and the mode's update.
756 KOKKOS_INLINE_FUNCTION void hostAssemble(const Member& t, int k, int mode, double delta) const {
757 const int b = D.pl.b, P = D.pl.P, s = D.pl.s;
758 FacReal* S = D.Sg.data();
759 int lo, hi;
760 hostShare(t, b, [](int i) { return (double)(i + 1); }, lo, hi);
761 for (int i = lo; i < hi; ++i) {
762 double v[kBottomMaxPlane];
763 for (int j = 0; j < i; ++j)
764 v[j] = 0.0;
765 v[i] = 1.0;
766 const int fi = k * b + i;
767 int c[3], nb[3];
768 D.coords(fi, c);
769 const int ei = D.extIndex(c);
770 const double si = D.s(fi);
771 double af = 0.0;
772 for (int f6 = 0; f6 < 6; ++f6)
773 if (D.face(AFX, AFY, AFZ, c, ei, f6, nb, af) && nb[s] == k) {
774 const int fj = D.factorIndex(nb);
775 if (fj - k * b <= i)
776 v[fj - k * b] += si * af * D.s(fj);
777 }
778 const int ci = comp(ei);
779 if (ci >= 0 && ci < (int)kc.extent(0) && kc(ci) == k)
780 for (int j = 0; j <= i; ++j)
781 if (comp(D.extOf(k * b + j)) == ci)
782 v[j] += aug(ci);
783 v[i] += delta;
784 for (int j = 0; j <= i; ++j) {
785 FacReal a = (FacReal)v[j];
786 if (mode == 1)
787 a = a - D.e(k, i) * D.Q(k - 1, i, j) * D.e(k, j);
788 else if (mode == 2)
789 a = (a - D.e(0, i) * D.Y(0, j, i)) - D.e(P - 1, i) * D.Y(P - 2, j, i);
790 S[j * b + i] = a;
791 }
792 }
793 t.team_barrier();
794 }
795 // invert: per tile, ONE thread factors the diagonal tile (row by row: L(i, j) for j < i, then
796 // the pivot) and the panel below it (column by column, a lane per row), one barrier; the team
797 // applies the trailing update (a column per thread, a lane per row), one barrier. Then W = L^{-1}
798 // by rows (a lane per column; each thread a contiguous column range, rows in order) and Q = W^T W
799 // by rows (a lane per column) -- one barrier each. The lane loops are long (up to b), so the
800 // accumulators' loads and stores pipeline instead of forming a latency chain.
801 KOKKOS_INLINE_FUNCTION bool hostInvert(const Member& t, int k, double tauPiv, int flag) const {
802 const int b = D.pl.b, rank = t.team_rank(), T = t.team_size();
803 FacReal* S = D.Sg.data();
804 FacReal* Lt = D.L.data();
805 FacReal* W = D.W.data();
806 for (int j0 = 0; j0 < b; j0 += kBottomTile) {
807 const int j1 = (j0 + kBottomTile < b) ? j0 + kBottomTile : b;
808 const int nc = j1 - j0;
809 Kokkos::single(Kokkos::PerTeam(t), [&]() {
810 for (int r = 0; r < nc; ++r) { // 1. the diagonal tile
811 const int i = j0 + r;
812 for (int c = 0; c < r; ++c) {
813 const int j = j0 + c;
814 FacReal a2 = 0;
815 for (int m = 0; m < c; ++m)
816 a2 += Lt[(j0 + m) * b + i] * Lt[(j0 + m) * b + j];
817 Lt[j * b + i] = (S[j * b + i] - a2) / Lt[j * b + j];
818 }
819 FacReal acc = 0;
820 for (int m = 0; m < r; ++m)
821 acc += Lt[(j0 + m) * b + i] * Lt[(j0 + m) * b + i];
822 const FacReal p = S[i * b + i] - acc;
823 if (!((double)p > tauPiv))
824 D.stat(flag) = 1;
825 Lt[i * b + i] = Kokkos::sqrt(p);
826 }
827 if (D.stat(flag))
828 return;
829 for (int c = 0; c < nc; ++c) { // 2. the panel, rows j1..b-1
830 const int j = j0 + c;
831 FacReal acc[kBottomMaxPlane];
833 for (int i = j1; i < b; ++i)
834 acc[i] = 0;
835 hostAccumulate(acc, Lt + j0 * b, Lt + j0 * b + j, b, 0, c, j1, b);
836 const FacReal ljj = Lt[j * b + j];
837 FacReal* Lj = Lt + j * b;
838 const FacReal* Sj = S + j * b;
840 for (int i = j1; i < b; ++i)
841 Lj[i] = (Sj[i] - acc[i]) / ljj;
842 }
843 });
844 t.team_barrier();
845 if (D.stat(flag))
846 return false;
847 if (j1 < b) {
848 for (int j = j1 + rank; j < b; j += T) { // 3. the trailing update, column j, rows j..b-1
849 FacReal acc[kBottomMaxPlane];
851 for (int i = j; i < b; ++i)
852 acc[i] = 0;
853 hostAccumulate(acc, Lt + j0 * b, Lt + j0 * b + j, b, 0, nc, j, b);
854 FacReal* Sj = S + j * b;
856 for (int i = j; i < b; ++i)
857 Sj[i] = Sj[i] - acc[i];
858 }
859 t.team_barrier();
860 }
861 }
862 // W(i, j) = -(sum_{m=j}^{i-1} L(i, m) W(m, j)) / L(i, i), W(i, i) = 1 / L(i, i): row i of this
863 // thread's columns [ja, jz) (equal shares of the (b - j)^2 work) sums m = ja .. i-1 in order,
864 // lane j taking the term m once m >= j -- each lane's sum is m = j .. i-1, ascending.
865 int ja, jz;
866 hostShare(t, b, [&](int j) { return (double)(b - j) * (b - j); }, ja, jz);
867 for (int i = ja; i < b; ++i) {
868 FacReal acc[kBottomMaxPlane];
869 const int jt = (i < jz) ? i : jz; // lanes ja .. jt-1 lie left of the diagonal
871 for (int j = ja; j < jt; ++j)
872 acc[j] = 0;
873 int m = ja;
874 for (; m + 4 <= i; m += 4) { // terms m .. m+3: all four for the lanes j <= m, ...
875 hostAccumulate(acc, W, Lt + i, b, m, m + 4, ja, (m + 1 < jz) ? m + 1 : jz);
876 for (int d = 1; d < 4 && m + d < jz; ++d) // ... m+d .. m+3 for lane m+d (its first)
877 for (int q = m + d; q < m + 4; ++q)
878 acc[m + d] += Lt[q * b + i] * W[q * b + m + d];
879 }
880 for (; m < i; ++m)
881 hostAccumulate(acc, W, Lt + i, b, m, m + 1, ja, (m + 1 < jz) ? m + 1 : jz);
882 const FacReal lii = Lt[i * b + i];
883 FacReal* Wi = W + i * b;
885 for (int j = ja; j < jt; ++j)
886 Wi[j] = -acc[j] / lii;
887 if (i < jz)
888 Wi[i] = FacReal(1) / lii;
889 }
890 t.team_barrier();
891 FacReal* Qk = &D.Q(k, 0, 0);
892 int qa, qz;
893 hostShare(t, b, [&](int i) { return (double)(b - i) * (i + 1); }, qa, qz);
894 for (int i = qa; i < qz; ++i) { // Q(i, j <= i) = sum_{m >= i} W(m, i) W(m, j)
895 FacReal acc[kBottomMaxPlane];
897 for (int j = 0; j <= i; ++j)
898 acc[j] = 0;
899 hostAccumulate(acc, W, W + i, b, i, b, 0, i + 1);
900 for (int j = 0; j <= i; ++j) {
901 Qk[i * b + j] = acc[j];
902 Qk[j * b + i] = acc[j];
903 }
904 }
905 t.team_barrier();
906 return true;
907 }
908 // border: Y(., c, .) depends on its own column c only, so a thread runs one column through the
909 // whole forward and backward sweep (a lane per row i) with no barrier between the planes.
910 KOKKOS_INLINE_FUNCTION void hostBorder(const Member& t) const {
911 const int P = D.pl.P, b = D.pl.b, rank = t.team_rank(), T = t.team_size();
912 for (int c = rank; c < b; c += T) {
913 FacReal acc[kBottomMaxPlane], br[kBottomMaxPlane];
914 for (int k = 0; k <= P - 2; ++k) { // forward
915 for (int j = 0; j < b; ++j) {
916 FacReal bj = 0;
917 if (j == c)
918 bj = (k == 0 ? D.e(0, j) : FacReal(0)) + (k == P - 2 ? D.e(P - 1, j) : FacReal(0));
919 br[j] = (k == 0) ? bj : bj - D.e(k, j) * D.Y(k - 1, c, j);
920 }
922 for (int i = 0; i < b; ++i)
923 acc[i] = 0;
924 for (int j = 0; j < b; ++j) {
925 const FacReal* Qj = &D.Q(k, j, 0);
926 const FacReal bj = br[j];
928 for (int i = 0; i < b; ++i)
929 acc[i] += Qj[i] * bj;
930 }
931 FacReal* Yk = &D.Y(k, c, 0);
933 for (int i = 0; i < b; ++i)
934 Yk[i] = acc[i];
935 }
936 for (int k = P - 3; k >= 0; --k) { // backward
938 for (int i = 0; i < b; ++i)
939 acc[i] = 0;
940 for (int j = 0; j < b; ++j) {
941 const FacReal* Qj = &D.Q(k, j, 0);
942 const FacReal y = D.e(k + 1, j) * D.Y(k + 1, c, j);
944 for (int i = 0; i < b; ++i)
945 acc[i] += Qj[i] * y;
946 }
947 FacReal* Yk = &D.Y(k, c, 0);
949 for (int i = 0; i < b; ++i)
950 Yk[i] = Yk[i] - acc[i];
951 }
952 }
953 t.team_barrier();
954 }
955 // operator()'s control flow (attempts, shifts, flags) on the host schedule.
956 KOKKOS_INLINE_FUNCTION void hostFactor(const Member& t) const {
957 const int P = D.pl.P;
958 const int Pt = D.pl.border ? P - 1 : P;
959 Kokkos::single(Kokkos::PerTeam(t), [&]() {
960 for (int a = 0; a < kBottomAttempts; ++a)
961 D.stat(2 + a) = 0;
962 });
963 scaling(t); // (its barrier also publishes the cleared flags)
964 couplings(t);
965 int attempt = 0;
966 bool ok = false;
967 for (; attempt < kBottomAttempts && !ok; ++attempt) {
968 const double delta = bottomShift(attempt);
969 const double tauPiv = (attempt == 0) ? tauPiv0 : kBottomPivotTol;
970 ok = true;
971 for (int k = 0; k < Pt && ok; ++k) {
972 hostAssemble(t, k, k == 0 ? 0 : 1, delta);
973 ok = hostInvert(t, k, tauPiv, 2 + attempt);
974 }
975 if (ok && D.pl.border) {
976 hostBorder(t);
977 hostAssemble(t, P - 1, 2, delta);
978 ok = hostInvert(t, P - 1, tauPiv, 2 + attempt);
979 }
980 }
981 const int restarts = attempt - 1;
982 Kokkos::single(Kokkos::PerTeam(t), [&]() {
983 D.stat(0) = ok ? 1 : 0;
984 D.stat(1) = restarts;
985 });
986 }
987
988 KOKKOS_INLINE_FUNCTION void operator()(const Member& t) const {
989 const int P = D.pl.P;
990 const int Pt = D.pl.border ? P - 1 : P;
991 if constexpr (kHostFactor) {
992 if (!teamAlgorithm) {
993 hostFactor(t);
994 return;
995 }
996 }
997 const SMat Ls(t.team_scratch(0), D.pl.b, kBottomTile + 1);
998 const SMat St(t.team_scratch(0), kBottomTile, kBottomTile + 1);
999 Kokkos::single(Kokkos::PerTeam(t), [&]() {
1000 for (int a = 0; a < kBottomAttempts; ++a)
1001 D.stat(2 + a) = 0;
1002 });
1004 scaling(t); // (its barrier also publishes the cleared flags)
1005 couplings(t);
1007 int attempt = 0;
1008 bool ok = false;
1009 for (; attempt < kBottomAttempts && !ok; ++attempt) {
1010 const double delta = bottomShift(attempt);
1011 const double tauPiv = (attempt == 0) ? tauPiv0 : kBottomPivotTol;
1012 ok = true;
1013 for (int k = 0; k < Pt && ok; ++k) {
1014 assemble(t, k, k == 0 ? 0 : 1, delta, St);
1015 ok = invert(t, k, tauPiv, 2 + attempt, Ls, St);
1016 }
1017 if (ok && D.pl.border) {
1018 border(t);
1019 assemble(t, P - 1, 2, delta, St);
1020 ok = invert(t, P - 1, tauPiv, 2 + attempt, Ls, St);
1021 }
1022 }
1023 const int restarts = attempt - 1;
1024 Kokkos::single(Kokkos::PerTeam(t), [&]() {
1025 D.stat(0) = ok ? 1 : 0;
1026 D.stat(1) = restarts;
1027 });
1028 }
1029};
1030
1031} // namespace peclet::flow
flow — portable (Kokkos) cut-cell pressure-operator face openness from an SDF.
#define PECLET_BOTTOM_HOST_SIMD
#define PECLET_BOTTOM_PROBE_MARK(t, cat)
#define PECLET_BOTTOM_UNROLL
double bottomShift(int attempt)
constexpr int kBottomMaxPlane
BottomPlanes bottomChoosePlanes(C3 inner, const int bc[6])
constexpr int kBottomAttempts
constexpr int kBottomTile
constexpr double kBottomPivotTol
Kokkos::View< FacReal ***, Kokkos::LayoutRight, CCMem > Mat
static void laneMatVec(FacReal *acc, const FacReal *x, const FacReal *v, int b, int lo, int hi)
void teamSubstitute(const Member &t) const
int factorIndex(const int c[3]) const
Kokkos::View< FacReal *, CCMem > u
Kokkos::View< FacReal *, CCMem > g
void apply(const Member &t, const RV &r, const ZV &z, const CV &comp, const ZV *keep, bool teamAlgorithm=false) const
Kokkos::View< FacReal **, Kokkos::LayoutRight, CCMem > Sq
static BottomDirect allocate(const BottomPlanes &p, C3 ext)
Kokkos::View< double *, CCMem > s
void coords(int f, int c[3]) const
static constexpr bool kHostLaneM
void laneSubstitute(const Member &t) const
bool face(const OpV &AFX, const OpV &AFY, const OpV &AFZ, const int c[3], int i, int f6, int nb[3], double &af) const
Kokkos::View< int *, CCMem > stat
int extIndex(const int c[3]) const
Kokkos::View< const double *, CCMem > aug
Kokkos::View< const int *, CCMem > comp
void couplings(const Member &t) const
Kokkos::View< const int *, CCMem > kc
bool hostInvert(const Member &t, int k, double tauPiv, int flag) const
void assemble(const Member &t, int k, int mode, double delta, const SMat &St) const
Kokkos::TeamPolicy< CCExec >::member_type Member
Kokkos::View< FacReal **, Kokkos::LayoutRight, typename CCExec::scratch_memory_space, Kokkos::MemoryTraits< Kokkos::Unmanaged > > SMat
void hostAssemble(const Member &t, int k, int mode, double delta) const
void scaling(const Member &t) const
static void hostAccumulate(FacReal *acc, const FacReal *x, const FacReal *y, int b, int m0, int m1, int lo, int hi)
void operator()(const Member &t) const
void border(const Member &t) const
bool invert(const Member &t, int k, double tauPiv, int flag, const SMat &Ls, const SMat &St) const
static void hostShare(const Member &t, int n, const Wf &w, int &lo, int &hi)
static std::size_t scratchBytes(int b)
double entry(int k, int i, int j, double delta) const
void hostBorder(const Member &t) const
void hostFactor(const Member &t) const
Kokkos::View< double *, peclet::flow::CCMem > OpV