iterative-solver 0.0
ArrayHandlerDistr.h
1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERDISTR_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERDISTR_H
3
4#include <molpro/Profiler.h>
5#include <molpro/linalg/array/ArrayHandler.h>
6#include <molpro/linalg/array/util/gemm.h>
7
10
11namespace molpro::linalg::array {
12
13template <class AL, class AR = AL>
14class ArrayHandlerDistr : public ArrayHandler<AL, AR> {
15public:
21
22 ProxyHandle lazy_handle() override { return this->lazy_handle(*this); };
23
24 using ArrayHandler<AL, AR>::lazy_handle;
25 using ArrayHandler<AL, AR>::error;
26 using ArrayHandler<AL, AR>::counter;
27
28 AL copy(const AR &source) override {
29 this->m_counter->copy++;
30 return AL{source};
31 };
32
33 void copy(AL &x, const AR &y) override {
34 this->m_counter->copy++;
35 x.copy(y);
36 };
37
38 void scal(value_type alpha, AL &x) override {
39 this->m_counter->scal++;
40 x.scal(alpha);
41 }
42
43 void fill(value_type alpha, AL &x) override { x.fill(alpha); }
44
45 void axpy(value_type alpha, const AR &x, AL &y) override {
46 this->m_counter->axpy++;
47 y.axpy(alpha, x);
48 }
49
50 value_type dot(const AL &x, const AR &y) override {
51 this->m_counter->dot++;
52 return x.dot(y);
53 }
54
55 void gemm_outer(const Matrix<value_type> alphas, const CVecRef<AR> &xx, const VecRef<AL> &yy) override {
56 this->m_counter->gemm_outer++;
57 gemm_outer_distr_distr(alphas, xx, yy);
58 }
59
60 Matrix<value_type> gemm_inner(const CVecRef<AL> &xx, const CVecRef<AR> &yy) override {
61 this->m_counter->gemm_inner++;
62 auto prof = molpro::Profiler::single()->push("ArrayHandlerDistr::gemm_inner");
63 return gemm_inner_distr_distr(xx, yy);
64 }
65
66 std::map<size_t, value_type_abs> select_max_dot(size_t n, const AL &x, const AR &y) override {
67 return x.select_max_dot(n, y);
68 }
69
70 std::map<size_t, value_type_abs> select(size_t n, const AL &x, bool max = false, bool ignore_sign = false) override {
71 return x.select(n, max, ignore_sign);
72 }
73};
74
75} // namespace molpro::linalg::array
76#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERDISTR_H
Definition: ArrayHandlerDistr.h:14
ProxyHandle lazy_handle() override
Returns a lazy handle. Most implementations simply need to call the overload: return lazy_handle(*thi...
Definition: ArrayHandlerDistr.h:22
std::map< size_t, value_type_abs > select_max_dot(size_t n, const AL &x, const AR &y) override
Definition: ArrayHandlerDistr.h:66
void copy(AL &x, const AR &y) override
Definition: ArrayHandlerDistr.h:33
AL copy(const AR &source) override
Definition: ArrayHandlerDistr.h:28
Matrix< value_type > gemm_inner(const CVecRef< AL > &xx, const CVecRef< AR > &yy) override
Definition: ArrayHandlerDistr.h:60
std::map< size_t, value_type_abs > select(size_t n, const AL &x, bool max=false, bool ignore_sign=false) override
Select n indices with largest (or smallest) actual (or absolute) value.
Definition: ArrayHandlerDistr.h:70
void axpy(value_type alpha, const AR &x, AL &y) override
Definition: ArrayHandlerDistr.h:45
void fill(value_type alpha, AL &x) override
Definition: ArrayHandlerDistr.h:43
void scal(value_type alpha, AL &x) override
Definition: ArrayHandlerDistr.h:38
void gemm_outer(const Matrix< value_type > alphas, const CVecRef< AR > &xx, const VecRef< AL > &yy) override
Definition: ArrayHandlerDistr.h:55
value_type dot(const AL &x, const AR &y) override
Definition: ArrayHandlerDistr.h:50
Enhances various operations between pairs of arrays and allows dynamic code injection with uniform in...
Definition: ArrayHandler.h:162
std::unique_ptr< Counter > m_counter
Definition: ArrayHandler.h:176
decltype(value_type_L{} *value_type_R{}) value_type
Definition: ArrayHandler.h:181
const Counter & counter() const
Definition: ArrayHandler.h:224
virtual void error(const std::string &message)
Throws an error.
Definition: ArrayHandler.h:268
Matrix container that allows simple data access, slicing, copying and resizing without loosing data.
Definition: Matrix.h:28
static std::shared_ptr< Profiler > single()
void gemm_outer_distr_distr(const Matrix< typename array::mapped_or_value_type_t< AL > > alphas, const CVecRef< DistrArrayFile > &xx, const VecRef< AL > &yy)
Definition: gemm.h:59
Matrix< typename array::mapped_or_value_type_t< AL > > gemm_inner_distr_distr(const CVecRef< AL > &yy, const CVecRef< DistrArrayFile > &xx)
Definition: gemm.h:32
Definition: ArrayHandler.h:22