13#ifndef JACOBI_PRECONDITIONER_HH
14#define JACOBI_PRECONDITIONER_HH
16#include "dune/istl/preconditioners.hh"
17#include "dune/istl/solvercategory.hh"
31 namespace JacobiPreconditionerDetail
33 template <
class Entry,
int row=0,
int col=0>
44 template <
class Matrix,
class Weight>
48 assert(mat.N() == mat.M());
50 for (
size_t i=0; i<nodes; ++i)
55 for (
auto ri=mat.begin(); ri!=mat.end(); ++ri)
57 auto const i = ri.index();
63 std::cerr <<
"i=" << i <<
" nodes=" << nodes <<
" node=" << node <<
" k=" << k <<
" => i=" << k + (node*
size)/nodes <<
" diag[node].size=" <<
diag[node].
size() <<
" n=" <<
size <<
"\n";
67 auto ci = ri->begin();
68 auto cend = ri->end();
69 for (; ci!=cend && ci.index()!=i; ++ci)
71 Entry& a =
diag[node][k];
88 template <
class X,
class Y>
95 std::fill(dps.begin(),dps.end(),0.0);
100 auto const& d = this->
diag[node];
101 size_t const n = d.size();
103 for (
size_t k=0; k<n; ++k)
105 size_t const i = k + start;
109 this->dps[node] = dp;
111 return std::accumulate(dps.begin(),dps.end(),0.0);
121 std::vector<std::vector<Entry,NumaAllocator<Entry>>>
diag;
124 mutable std::vector<field_type> dps;
137 template <
class Block>
139 typedef typename std::remove_reference<Block>::type
B;
159 static int const category = Dune::SolverCategory::sequential;
191 return diag.
apply(x,y);
211 template <
class Operator>
213 typename Operator::domain_type,
214 typename Operator::range_type>
228 :
Base(op.getmat(),w)
237 template <
class Operator>
240 static Deprecated dummy(
"makeJacobiPreconditioner() is deprecated, call JacobiPreconditioner(A) directly",2020);
250 template <
class Entry,
class Index>
295 template <
class Assembler,
296 int firstRow,
int lastRow,
297 int firstCol,
int lastCol,
301 :
public SymmetricPreconditioner<typename AssembledGalerkinOperator<Assembler,firstRow,lastRow,firstCol,lastCol,BlockFilter,symmetric>::Domain,
302 typename AssembledGalerkinOperator<Assembler,firstRow,lastRow,firstCol,lastCol,BlockFilter,symmetric>::Range>
310 struct DiagonalFilter {
311 template <
class Block>
struct apply {
typedef boost::mpl::bool_<Block::rowId==Block::colId>
type; };
316 static int const category = Dune::SolverCategory::sequential;
325 blocks(
boost::fusion::transform(
326 boost::fusion::filter_if<DiagonalFilter>(
328 IstlInterfaceDetail::Translate<firstRow,firstCol>())),
329 JacobiPreconditionerDetail::ExtractDiagonal(w)))
337 virtual void apply (Domain& x, Range
const& y)
347 virtual Scalar
applyDp (Domain& x, Range
const& y)
350 boost::fusion::for_each(blocks,ApplyJacobi(x,y,dp));
365 typename boost::fusion::result_of::as_vector<
366 typename boost::fusion::result_of::transform<
367 typename boost::fusion::result_of::filter_if<
368 typename boost::fusion::result_of::transform<
369 typename boost::fusion::result_of::filter_if<typename IstlInterfaceDetail::AllBlocks<typename Operator::Assembler>::result,
BlockFilter>::type,
370 IstlInterfaceDetail::Translate<firstRow,firstCol> >::type,
371 DiagonalFilter>::type,
376 ApplyJacobi(Domain& x_, Range
const& y_, Scalar& dp): x(x_), y(y_), dualPairing(dp) {}
378 template <
class Block>
379 void operator()(Block
const& mb)
const
382 dualPairing += mb.apply(at_c<Block::colId>(x.data),at_c<Block::rowId>(y.data));
An adaptor presenting a Dune::LinearOperator <domain_type,range_type> interface to a contiguous sub-b...
typename Assembler::AnsatzVariableSetDescription::template CoefficientVector< firstCol, lastCol > Domain
typename Assembler::TestVariableSetDescription::template CoefficientVector< firstRow, lastRow > Range
Convenience class for marking deprecated functions. A static object of this class can be created insi...
virtual Scalar applyDp(Domain &x, Range const &y)
Computes Jacobi step and for and linear equation .
virtual void apply(Domain &x, Range const &y)
Computes Jacobi step for and linear equation .
JacobiPreconditioner(Operator const &op, Scalar w=1.0)
Constructs a Jacobi preconditioner.
virtual bool requiresInitializedInput() const
Returns true if the target vector x has to be initialized to zero before calling apply or applyDp.
typename Base::field_type field_type
JacobiPreconditioner & operator=(JacobiPreconditioner &&)=default
JacobiPreconditioner()=default
Default constructor.
JacobiPreconditioner(JacobiPreconditioner &&)=default
JacobiPreconditioner(NumaBCRSMatrix< Entry, Index > const &mat, double w=1.0)
Constructor.
virtual field_type applyDp(domain_type &x, range_type const &y)
JacobiPreconditionerBase & operator=(JacobiPreconditionerBase &&)=default
typename Matrix::field_type field_type
virtual void apply(domain_type &x, range_type const &b)
virtual bool requiresInitializedInput() const
Returns true if the target vector x has to be initialized to zero before calling apply or applyDp.
JacobiPreconditionerBase(Matrix const &mat, double w=1.0)
Constructor.
JacobiPreconditionerBase(JacobiPreconditionerBase &&)=default
JacobiPreconditionerBase()=default
Default constructor.
static int const category
JacobiPreconditioner(Operator const &op, double w=1.0)
Constructor.
An STL allocator that uses memory of a specific NUMA node only.
A NUMA-aware compressed row storage matrix adhering mostly to the Dune ISTL interface (to complete....
Implementation of thread pools suitable for parallelization of (more or less) memory-bound algorithms...
static NumaThreadPool & instance(int maxThreads=std::numeric_limits< int >::max())
Returns a globally unique thread pool instance.
int nodes() const
Reports the number of NUMA nodes (i.e., memory interfaces/CPU sockets)
Interface for symmetric preconditioners.
This file contains various utility functions that augment the basic functionality of Dune.
auto makeJacobiPreconditioner(Operator const &op, double w=1.0)
DEPRECATED, use JacobiPreconditioner(A) directly.
Index uniformWeightRangeStart(BlockIndex i, BlockIndex n, Index m)
Computes partitioning points of ranges for uniform weight distributions.
void parallelForNodes(Func const &f, int maxTasks=std::numeric_limits< int >::max())
A parallel for loop that executes the given functor in parallel on different NUMA nodes.
Index uniformWeightRange(Index j, Index n, Index m)
Computes the range in which an index is to be found when partitioned for uniform weights.
A block filter specifying which subblocks of a stiffness matrix or right hand side shall be assembled...
boost::mpl::bool_< Block::rowId==Block::colId > type
DiagonalBlock(DiagonalBlock &&other)=default
std::vector< std::vector< Entry, NumaAllocator< Entry > > > diag
typename Entry::field_type field_type
DiagonalBlock(Matrix const &mat, Weight w)
DiagonalBlock & operator=(DiagonalBlock &&other)=default
field_type apply(X &x, Y const &y) const
Computes and returns .
void NaturalRange
The natural range type.