FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
krylov_orthogonalizer.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
9#include <kernel/lafem/arch/batched_vector_apply.hpp>
10#include <kernel/lafem/base.hpp>
11#include <kernel/lafem/dense_vector.hpp>
12#include <kernel/lafem/dense_vector_blocked.hpp>
13#include <kernel/lafem/tuple_vector.hpp>
14#include <kernel/global/gate.hpp>
15#include <kernel/global/vector.hpp>
17#include <kernel/util/math.hpp>
18
19#include <vector>
20
21namespace FEAT::Solver
22{
23 namespace Intern
24 {
25
26 template<typename VectorType_>
27 class BatchedHelper;
28 }
29
34 {
43 cgs2
44 };
45
49 template<typename Vector_>
51 {
52 public:
53 typedef Vector_ VectorType;
54 typedef typename Vector_::DataType DataType;
55
56 protected:
58 std::vector<VectorType> _subspace;
61
62
63 public:
64
65 KrylovSubspaceOrthogonalizer(const VectorType& vec_ref, Index krylov_dimension) :
66 _krylov_dimension(krylov_dimension)
67 {
69 for(std::size_t n = 0; n <= krylov_dimension; ++n)
70 {
71 _subspace.emplace_back(vec_ref.clone(LAFEM::CloneMode::Layout));
72 }
73 }
74
75 explicit KrylovSubspaceOrthogonalizer() = default;
80
81 virtual ~KrylovSubspaceOrthogonalizer()=default;
82
95 virtual DataType orthogonalize(DataType* dot_products, const Index target_index) = 0;
96
100 virtual void correct_vector(VectorType& target, const DataType* local_scales, const Index num_axpy, const DataType alpha) const
101 {
102 XASSERT(num_axpy <= _krylov_dimension);
103 for(Index k = 0; k < num_axpy; ++k)
104 {
105 target.axpy(_subspace[k], alpha * local_scales[k]);
106 }
107 }
108
113 {
114 return _krylov_dimension;
115 }
116
120 std::vector<VectorType>& get_subspace()
121 {
122 return _subspace;
123 }
124
125 const std::vector<VectorType>& get_subspace() const
126 {
127 return _subspace;
128 }
129
130 VectorType& at(const Index idx)
131 {
132 return _subspace.at(idx);
133 }
134
135 const VectorType& at(const Index idx) const
136 {
137 return _subspace.at(idx);
138 }
139 }; // class KrylovSubspaceOrthogonalizer<...>
140
144 template<typename Vector_>
146 {
147 public:
149 typedef typename BaseClass::VectorType VectorType;
150 typedef typename BaseClass::DataType DataType;
151
152 public:
153 explicit ModifiedGramSchmidtOrthogonalizer() = default;
154
155 ModifiedGramSchmidtOrthogonalizer(const Vector_& vec_ref, Index krylov_dimension) :
156 BaseClass(vec_ref, krylov_dimension)
157 {
158 }
159
164
165 virtual ~ModifiedGramSchmidtOrthogonalizer()=default;
166
167 DataType orthogonalize(DataType* dot_products, const Index target_index) override
168 {
169 XASSERT(target_index <= this->_krylov_dimension);
170 // Gram-Schmidt process
171 for(Index k(0); k < target_index; ++k)
172 {
173 const auto dot = this->_subspace[target_index].dot(this->_subspace[k]);
174 this->_subspace[target_index].axpy(this->_subspace[k], -dot);
175 dot_products[k] = dot;
176 }
177 return this->_subspace[target_index].norm2();
178 }
179 };
180
196 template<typename Vector_>
198 {
199 public:
201 typedef typename BaseClass::VectorType VectorType;
202 typedef typename BaseClass::DataType DataType;
203
204 protected:
206 std::vector<Memory::Arbiter const*> _vec_arbiter;
210
223 void _compute_dots(const VectorType& target, const Index num_basis, DataType* dot_out, DataType& self_dot)
224 {
225 // zero the accumulation arbiter on all locations, then accumulate the batched dots onto it
226 _dots.format();
227 // the batched dot also picks up the self-dot: target == _subspace[num_basis], so slot num_basis
228 // of the reduction holds <target,target>
230 _dots, target, _vec_arbiter.data(), num_basis + 1, this->_subspace.size());
231
232 // read the results back into the host output (triggers a device->host copy if needed)
234 const DataType* dp = dv.get_r();
235 for(Index k(0); k < num_basis; ++k)
236 dot_out[k] = dp[k];
237 self_dot = dp[num_basis];
238 }
239
243 DataType _finalize_norm(const DataType nrm_sqr, const VectorType& target) const
244 {
245 // trust the algebraic norm only when it is safely positive; otherwise fall back to an explicit
246 // norm2 (accurate, and guarantees a positive result so the normalization cannot produce a NaN)
247 if(nrm_sqr <= Math::Limits<DataType>::epsilon() * DataType(100))
248 return target.norm2();
249 return Math::sqrt(nrm_sqr);
250 }
251
252 public:
253 explicit ClassicGramSchmidtOrthogonalizer() = default;
254
255 ClassicGramSchmidtOrthogonalizer(const Vector_& vec_ref, Index krylov_dimension) :
256 BaseClass(vec_ref, krylov_dimension)
257 {
258 // one slot per basis vector plus one for the appended self-dot <w,w>; the largest reduction
259 // projects against all krylov_dimension basis vectors, so krylov_dimension+1 slots suffice
260 _dots = Memory::Arbiter((this->_krylov_dimension + 1) * sizeof(DataType));
261 // pass pointers to the persistent krylov basis vectors; gather_arbiter records the addresses
262 // of their (nested) element arbiters, which must remain valid for the solver's lifetime
263 std::vector<const VectorType*> vec_v_ptrs;
264 vec_v_ptrs.reserve(this->_subspace.size());
265 for(const auto& v : this->_subspace)
266 vec_v_ptrs.push_back(&v);
267 Intern::BatchedHelper<VectorType>::gather_arbiter(_vec_arbiter, vec_v_ptrs.data(), this->_subspace.size());
268 }
269
270 ClassicGramSchmidtOrthogonalizer(const ClassicGramSchmidtOrthogonalizer&) = delete;
271 ClassicGramSchmidtOrthogonalizer& operator=(const ClassicGramSchmidtOrthogonalizer&) = delete;
272 ClassicGramSchmidtOrthogonalizer(ClassicGramSchmidtOrthogonalizer&&) = default;
273 ClassicGramSchmidtOrthogonalizer& operator=(ClassicGramSchmidtOrthogonalizer&&) = default;
274
275 virtual ~ClassicGramSchmidtOrthogonalizer()=default;
276
277 DataType orthogonalize(DataType* dot_products, const Index target_index) override
278 {
279 XASSERT(target_index <= this->_krylov_dimension);
280 // orthogonalize against the target_index leading basis vectors v_0,...,v_{target_index-1}
281 const Index num_basis = target_index;
282 VectorType& target = this->_subspace[target_index];
283
284 // a single batched reduction yields the orthogonalization dots h[0..num_basis) and the self-dot
285 DataType self_dot(0);
286 _compute_dots(target, num_basis, dot_products, self_dot);
287
288 DataType sum_sqr(0);
289 for(Index k(0); k < num_basis; ++k)
290 sum_sqr += Math::sqr(dot_products[k]);
291
292 // subtract the projection in a single batched cumulative axpy: target -= sum_k h[k] * v[k]
293 this->correct_vector(target, dot_products, num_basis, DataType(-1));
294
295 // recover the post-orthogonalization norm algebraically (with a norm2 fallback)
296 return _finalize_norm(self_dot - sum_sqr, target);
297 }
298
302 void correct_vector(VectorType& target, const DataType* local_scales, const Index num_axpy, const DataType alpha) const override
303 {
304 XASSERT(num_axpy <= this->_krylov_dimension);
305 Intern::BatchedHelper<VectorType>::template cumulative_axpy<DataType>(
306 target, _vec_arbiter.data(), local_scales, num_axpy, alpha, this->_subspace.size());
307 }
308 };
309
325 template<typename Vector_>
327 {
328 public:
330 typedef typename BaseClass::VectorType VectorType;
331 typedef typename BaseClass::DataType DataType;
332
333 protected:
335 std::vector<DataType> _corr;
338 DataType _reortho_tol = DataType(0.3);
340 bool _force_reortho = false;
341
342 public:
343 explicit CGS2Orthogonalizer() = default;
344
345 CGS2Orthogonalizer(const Vector_& vec_ref, Index krylov_dimension) :
346 BaseClass(vec_ref, krylov_dimension)
347 {
348 _corr.resize(krylov_dimension);
349 }
350
351 CGS2Orthogonalizer(const CGS2Orthogonalizer&) = delete;
352 CGS2Orthogonalizer& operator=(const CGS2Orthogonalizer&) = delete;
354 CGS2Orthogonalizer& operator=(CGS2Orthogonalizer&&) = default;
355
356 virtual ~CGS2Orthogonalizer()=default;
357
359 void set_reortho_tol(DataType tol)
360 {
361 XASSERT(tol >= DataType(0));
362 _reortho_tol = tol;
363 }
364
366 void set_force_reortho(bool force)
367 {
368 _force_reortho = force;
369 }
370
371 DataType orthogonalize(DataType* dot_products, const Index target_index) override
372 {
373 XASSERT(target_index <= this->_krylov_dimension);
374 const Index num_basis = target_index;
375 VectorType& target = this->_subspace[target_index];
376
377 // first classical Gram-Schmidt sweep (batched dots + self-dot, then batched subtraction)
378 DataType self_dot(0);
379 this->_compute_dots(target, num_basis, dot_products, self_dot);
380 DataType sum_sqr(0);
381 for(Index k(0); k < num_basis; ++k)
382 sum_sqr += Math::sqr(dot_products[k]);
383 this->correct_vector(target, dot_products, num_basis, DataType(-1));
384 DataType nrm_sqr = self_dot - sum_sqr;
385
386 // corrective reorthogonalization (CGS2), forced or when heavy cancellation is detected; the
387 // second batched reduction supplies both the corrections and the updated self-dot, so the
388 // corrected norm is again obtained without an extra reduction
389 if(_force_reortho || (nrm_sqr < Math::sqr(_reortho_tol) * self_dot))
390 {
391 DataType self_dot2(0);
392 this->_compute_dots(target, num_basis, _corr.data(), self_dot2);
393 DataType sum_sqr2(0);
394 for(Index k(0); k < num_basis; ++k)
395 {
396 dot_products[k] += _corr[k];
397 sum_sqr2 += Math::sqr(_corr[k]);
398 }
399 this->correct_vector(target, _corr.data(), num_basis, DataType(-1));
400 nrm_sqr = self_dot2 - sum_sqr2;
401 }
402
403 return this->_finalize_norm(nrm_sqr, target);
404 }
405 };
406
407
408
409
410 namespace Intern
411 {
412
413 #ifdef DOXY
414 template<typename VectorType_>
416 {
417 public:
438 template<typename DT_>
439 static void batched_dot(Memory::Arbiter& local_dots, const VectorType_& target, Memory::Arbiter const * const * vectors, Index size, Index stride);
440
456 template<typename DT_>
457 static void cumulative_axpy(VectorType_& target, Memory::Arbiter const * const * vectors, DT_ const * const local_scales, Index size, DT_ alpha, Index stride);
458
459 template<typename DT_>
460 static void gather_arbiter(std::vector<Memory::Arbiter const*>& arbiter, VectorType_ const * const * vectors, Index size);
461 };
462 #endif
463
464 template<typename LocalVector_, typename Mirror_>
465 class BatchedHelper<Global::Vector<LocalVector_, Mirror_>>
466 {
467 public:
469
470 template<typename DT_>
471 static void batched_dot(Memory::Arbiter& local_dots, const VectorType& target, Memory::Arbiter const * const * vectors, Index size, Index stride)
472 {
473 // create vector of local vectors
474 if(!target.get_comm() || target.get_comm()->size() == 1)
475 {
476 // call local batched dot
477 BatchedHelper<LocalVector_>::template batched_dot<DT_>(local_dots, target.local(), vectors, size, stride);
478 }
479 else
480 {
481 BatchedHelper<LocalVector_>::template batched_triple_dot<DT_>(local_dots, target.local(), vectors, target.get_gate()->get_freqs(), size, stride);
482
483 {
484 // and now synchronize dots on the host: acquire the main-memory view (triggers a device->host
485 // copy if the local dots were just computed on the device) and all-reduce in place
487 DT_* dots_ptr = dots_view.get_w();
488 target.get_comm()->allreduce(dots_ptr, dots_ptr, size, Dist::op_sum);
489 }
490 // TODO: allreduce should decide itself where the communication should take place... can the view simply be on the last most update point?
491 // Simply take the backend?
492
493 }
494 }
495
496 template<typename DT_>
497 static void cumulative_axpy(VectorType& target, Memory::Arbiter const * const * vectors, DT_ const * const local_scales, Index size, DT_ alpha, Index stride)
498 {
499 // call local batched dot
500 BatchedHelper<LocalVector_>::cumulative_axpy(target.local(), vectors, local_scales, size, alpha, stride);
501 }
502
503 static void gather_arbiter(std::vector<Memory::Arbiter const*>& arbiter, VectorType const * const * vectors, Index size)
504 {
505 // collect pointers into the persistent local vectors; no cloning, so the arbiter addresses
506 // we gather remain valid for the lifetime of the originals
507 std::vector<const LocalVector_*> locals;
508 locals.reserve(size);
509 for(Index k = 0; k < size; ++k)
510 {
511 locals.push_back(&vectors[k]->local());
512 }
513 BatchedHelper<LocalVector_>::gather_arbiter(arbiter, locals.data(), size);
514 }
515 };
516
517 template<typename First_, typename... Rest_>
518 class BatchedHelper<LAFEM::TupleVector<First_, Rest_...>>
519 {
520 public:
521 typedef LAFEM::TupleVector<First_, Rest_...> VectorType;
522
523 template<typename DT_>
524 static void batched_dot(Memory::Arbiter& local_dots, const VectorType& target, Memory::Arbiter const * const * vectors, Index size, Index stride)
525 {
526 {
527 BatchedHelper<First_>::template batched_dot<DT_>(local_dots, target.first(), vectors, size, stride);
528 }
529 {
530 BatchedHelper<LAFEM::TupleVector<Rest_...>>::template batched_dot<DT_>(local_dots, target.rest(), vectors+stride, size, stride);
531 }
532 }
533
534 template<typename DT_>
535 static void batched_triple_dot(Memory::Arbiter& local_dots, const VectorType& target, Memory::Arbiter const * const * vectors, const VectorType& freqs, Index size, Index stride)
536 {
537 {
538 BatchedHelper<First_>::template batched_triple_dot<DT_>(local_dots, target.first(), vectors, freqs.first(), size, stride);
539 }
540 {
541 BatchedHelper<LAFEM::TupleVector<Rest_...>>::template batched_triple_dot<DT_>(local_dots, target.rest(), vectors+stride, freqs.rest(), size, stride);
542 }
543 }
544
545 template<typename DT_>
546 static void cumulative_axpy(VectorType& target, Memory::Arbiter const * const * vectors, DT_ const * const local_scales, Index size, DT_ alpha, Index stride)
547 {
548 BatchedHelper<First_>::cumulative_axpy(target.first(), vectors, local_scales, size, alpha, stride);
549 BatchedHelper<LAFEM::TupleVector<Rest_...>>::cumulative_axpy(target.rest(), vectors+stride, local_scales, size, alpha, stride);
550 }
551
552 static void gather_arbiter(std::vector<Memory::Arbiter const*>& arbiter, VectorType const * const * vectors, Index size)
553 {
554 {
555 std::vector<const First_*> firsts;
556 firsts.reserve(size);
557 for(Index k = 0; k < size; ++k)
558 {
559 firsts.push_back(&vectors[k]->first());
560 }
561 BatchedHelper<First_>::gather_arbiter(arbiter, firsts.data(), size);
562 }
563 {
564 std::vector<const LAFEM::TupleVector<Rest_...>*> rests;
565 rests.reserve(size);
566 for(Index k = 0; k < size; ++k)
567 {
568 rests.push_back(&vectors[k]->rest());
569 }
570 BatchedHelper<LAFEM::TupleVector<Rest_...>>::gather_arbiter(arbiter, rests.data(), size);
571 }
572 }
573 };
574
575 template<typename First_>
576 class BatchedHelper<LAFEM::TupleVector<First_>>
577 {
578 public:
580
581 template<typename DT_>
582 static void batched_dot(Memory::Arbiter& local_dots, const VectorType& target, Memory::Arbiter const * const * vectors, Index size, Index stride)
583 {
584 {
585 BatchedHelper<First_>::template batched_dot<DT_>(local_dots, target.first(), vectors, size, stride);
586 }
587 }
588
589 template<typename DT_>
590 static void batched_triple_dot(Memory::Arbiter& local_dots, const VectorType& target, Memory::Arbiter const * const * vectors, const VectorType& freqs, Index size, Index stride)
591 {
592 {
593 BatchedHelper<First_>::template batched_triple_dot<DT_>(local_dots, target.first(), vectors, freqs.first(), size, stride);
594 }
595 }
596
597 template<typename DT_>
598 static void cumulative_axpy(VectorType& target, Memory::Arbiter const * const * vectors, DT_ const * const local_scales, Index size, DT_ alpha, Index stride)
599 {
600 BatchedHelper<First_>::cumulative_axpy(target.first(), vectors, local_scales, size, alpha, stride);
601 }
602
603 static void gather_arbiter(std::vector<Memory::Arbiter const*>& arbiter, VectorType const * const * vectors, Index size)
604 {
605 {
606 std::vector<const First_*> firsts;
607 firsts.reserve(size);
608 for(Index k = 0; k < size; ++k)
609 {
610 firsts.push_back(&vectors[k]->first());
611 }
612 BatchedHelper<First_>::gather_arbiter(arbiter, firsts.data(), size);
613 }
614 }
615 };
616
617 template<typename DTT_, typename ITT_>
618 class BatchedHelper<LAFEM::DenseVector<DTT_, ITT_>>
619 {
620 public:
622
623 template<typename DT_>
624 static void batched_dot(Memory::Arbiter& local_dots, const VectorType& target, Memory::Arbiter const * const * vectors, Index size, Index /*stride*/)
625 {
626 if(size == 0u)
627 return;
628 LAFEM::Arch::BatchedDotProduct::exec<DT_, DTT_>(local_dots, target.elements_arbiter(), target.size(), vectors, size);
629 }
630
631 template<typename DT_>
632 static void batched_triple_dot(Memory::Arbiter& local_dots, const VectorType& target, Memory::Arbiter const * const * vectors, const VectorType& freqs, Index size, Index /*stride*/)
633 {
634 if(size == 0u)
635 return;
636 LAFEM::Arch::BatchedTripleDotProduct::exec<DT_, DTT_>(local_dots, target.elements_arbiter(), target.size(), vectors, freqs.elements_arbiter(), size);
637 }
638
639 template<typename DT_>
640 static void cumulative_axpy(VectorType& target, Memory::Arbiter const * const * vectors, DT_ const * const local_scales, Index size, DT_ alpha, Index /*stride*/)
641 {
642 if(size == 0u)
643 return;
644 LAFEM::Arch::CumulativeAxpy::exec<DT_>(target.elements_arbiter(), target.size(), vectors, local_scales, size, alpha);
645 }
646
647 static void gather_arbiter(std::vector<Memory::Arbiter const*>& arbiter, VectorType const * const * vectors, Index size)
648 {
649 for(Index k = 0; k < size; ++k)
650 {
651 arbiter.emplace_back(&vectors[k]->elements_arbiter());
652 }
653 }
654 };
655
656 template<typename DTT_, typename ITT_, int dim_>
657 class BatchedHelper<LAFEM::DenseVectorBlocked<DTT_, ITT_, dim_>>
658 {
659 public:
661
662 template<typename DT_>
663 static void batched_dot(Memory::Arbiter& local_dots, const VectorType& target, Memory::Arbiter const * const * vectors, Index size, Index /*stride*/)
664 {
665 if(size == 0u)
666 return;
667 // pass the element arbiters down; the kernel acquires the (pod-typed) views for its backend itself
668 LAFEM::Arch::BatchedDotProduct::exec<DT_, DTT_>(local_dots, target.elements_arbiter(), target.size_raw(), vectors, size);
669 }
670
671 template<typename DT_>
672 static void batched_triple_dot(Memory::Arbiter& local_dots, const VectorType& target, Memory::Arbiter const * const * vectors, const VectorType& freqs, Index size, Index /*stride*/)
673 {
674 if(size == 0u)
675 return;
676 LAFEM::Arch::BatchedTripleDotProduct::exec<DT_, DTT_>(local_dots, target.elements_arbiter(), target.size_raw(),
677 vectors, freqs.elements_arbiter(), size);
678 }
679
680 template<typename DT_>
681 static void cumulative_axpy(VectorType& target, Memory::Arbiter const * const * vectors, DT_ const * const local_scales, Index size, DT_ alpha, Index /*stride*/)
682 {
683 if(size == 0u)
684 return;
685 LAFEM::Arch::CumulativeAxpy::exec<DT_>(target.elements_arbiter(), target.size_raw(), vectors, local_scales, size, alpha);
686 }
687
688 static void gather_arbiter(std::vector<Memory::Arbiter const*>& arbiter, VectorType const * const * vectors, Index size)
689 {
690 for(Index k = 0; k < size; ++k)
691 {
692 arbiter.emplace_back(&vectors[k]->elements_arbiter());
693 }
694 }
695 };
696
697 }
698}
#define XASSERT(expr)
Assertion macro definition.
Definition: assertion.hpp:262
FEAT Kernel base header.
void allreduce(const void *sendbuf, void *recvbuf, std::size_t count, const Datatype &datatype, const Operation &op) const
Blocking All-Reduce.
Definition: dist.cpp:658
int size() const
Returns the size of this communicator.
Definition: dist.hpp:1814
const LocalVector_ & get_freqs() const
Returns a const reference to the frequencies vector.
Definition: gate.hpp:226
Global vector wrapper class template.
Definition: vector.hpp:68
const Dist::Comm * get_comm() const
Returns a const pointer to the internal communicator of the gate of the vector.
Definition: vector.hpp:159
const GateType * get_gate() const
Returns a const pointer to the internal gate of the vector.
Definition: vector.hpp:149
LocalVector_ & local()
Returns a reference to the internal local LAFEM vector object.
Definition: vector.hpp:122
Blocked Dense data vector class template.
Memory::Arbiter & elements_arbiter()
Returns a reference to the element array arbiter.
Index size_raw() const
Returns the size of this vector in scalar data type entries, i.e. its number of entries multiplied by...
Dense data vector class template.
Memory::Arbiter & elements_arbiter()
Returns a reference to the element array arbiter.
Index size() const
Returns the size of this vector, i.e. its number of entries.
Variadic TupleVector class template.
Math Limits class template.
Definition: math.hpp:1475
Memory arbiter class.
View view(Location mem_loc, Access access)
Maps a raw view to a memory block.
void format(Location mem_loc=Location::none)
Formats the memory block to zero.
Typed memory view class.
const T_ * get_r() const
Returns a const typed pointer to the array that grants read access.
T_ * get_w()
Returns a typed pointer to the array that grants write (and read) access.
Classical Gram-Schmidt with a (conditional) reorthogonalization sweep (CGS2)
std::vector< DataType > _corr
scratch for the corrective sweep's dot products, kept separate from the accumulated h[k]
void set_reortho_tol(DataType tol)
Sets the DGKS norm-ratio threshold that triggers a corrective reorthogonalization sweep.
void set_force_reortho(bool force)
Forces (or unforces) a corrective reorthogonalization sweep in every step.
bool _force_reortho
if set, always perform the corrective reorthogonalization sweep regardless of the criterion
Abstraction of the classical Gram-Schmidt procedure with a batched reduction.
DataType orthogonalize(DataType *dot_products, const Index target_index) override
Orthogonalizes v_[ti] against v_0,...v_{ti-1}.
void correct_vector(VectorType &target, const DataType *local_scales, const Index num_axpy, const DataType alpha) const override
Batched cumulative axpy: target += alpha * sum_k local_scales[k] * v[k].
std::vector< Memory::Arbiter const * > _vec_arbiter
flattened element arbiters of the persistent basis vectors, consumed by the batched kernels
void _compute_dots(const VectorType &target, const Index num_basis, DataType *dot_out, DataType &self_dot)
Computes the batched dot products of target against the leading basis vectors.
DataType _finalize_norm(const DataType nrm_sqr, const VectorType &target) const
Recovers the orthogonalized norm from the algebraic identity with a norm2 fallback.
static void batched_dot(Memory::Arbiter &local_dots, const VectorType_ &target, Memory::Arbiter const *const *vectors, Index size, Index stride)
Calculates the dot products of target with all members of vectors in a batched manner.
static void cumulative_axpy(VectorType_ &target, Memory::Arbiter const *const *vectors, DT_ const *const local_scales, Index size, DT_ alpha, Index stride)
Calculates the commulative axpy onto target with all members of vectors in a batched manner.
Base class for orthogonlizing a vector of a Krylov subspace.
virtual void correct_vector(VectorType &target, const DataType *local_scales, const Index num_axpy, const DataType alpha) const
Performs the commulative sum on vector target with the internal vector array.
virtual DataType orthogonalize(DataType *dot_products, const Index target_index)=0
Orthogonalizes v_[ti] against v_0,...v_{ti-1}.
Index get_krylov_dim() const
The krylov dimension.
std::vector< VectorType > & get_subspace()
Get a reference to the subspace vectors.
std::vector< VectorType > _subspace
The component holds the krylov subspace (and potentially additonal helper vectors)
Simple abstraction of the modified Gram Schmidt procedure.
DataType orthogonalize(DataType *dot_products, const Index target_index) override
Orthogonalizes v_[ti] against v_0,...v_{ti-1}.
LAFEM common type definitions.
const Operation op_sum(MPI_SUM)
Operation wrapper for MPI_SUM.
Definition: dist.hpp:571
T_ sqrt(T_ x)
Returns the square-root of a value.
Definition: math.hpp:300
T_ sqr(T_ x)
Returns the square of a value.
Definition: math.hpp:95
@ read_write
read-write access
@ read
read-only access
Solver namespace.
@ rest
restriction (multigrid)
KrylovOrthogonalizerType
Enumeration of the available Krylov subspace orthogonalization strategies.
std::uint64_t Index
Index data type.