iterative-solver 0.0
ArrayHandlerDDiskDistr.h
1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERDDISKDISTR_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERDDISKDISTR_H
3
4#include <map>
5#include <molpro/linalg/array/ArrayHandler.h>
6#include <molpro/linalg/array/util/gemm.h>
7
8namespace molpro::linalg::array {
11
12template <class AL, class AR = AL>
13class ArrayHandlerDDiskDistr : public ArrayHandler<AL, AR> {
14public:
20
22 : ArrayHandler<AL, AR>(), m_copy_func([](const AR &source) { return AL::CreateTempCopy(source); }) {}
23
32 ArrayHandlerDDiskDistr(std::function<AL(const AR &)> copy_func)
33 : ArrayHandler<AL, AR>(), m_copy_func(std::move(copy_func)){};
34
35 ProxyHandle lazy_handle() override { return this->lazy_handle(*this); };
36
37 using ArrayHandler<AL, AR>::lazy_handle;
38 using ArrayHandler<AL, AR>::error;
39
40 AL copy(const AR &source) override {
41 this->m_counter->copy++;
42 return m_copy_func(source);
43 };
44
45 void copy(AL &x, const AR &y) override {
46 this->m_counter->copy++;
47 x.copy(y);
48 };
49
50 void scal(value_type alpha, AL &x) override {
51 this->m_counter->scal++;
52 x.scal(alpha);
53 }
54
55 void fill(value_type alpha, AL &x) override { x.fill(alpha); }
56
57 void axpy(value_type alpha, const AR &x, AL &y) override {
58 this->m_counter->axpy++;
59 y.axpy(alpha, x);
60 }
61
62 value_type dot(const AL &x, const AR &y) override {
63 this->m_counter->dot++;
64 return x.dot(y);
65 }
66
67 void gemm_outer(const Matrix<value_type> alphas, const CVecRef<AR> &xx, const VecRef<AL> &yy) override {
68 this->m_counter->gemm_outer++;
69 gemm_outer_distr_distr(alphas, xx, yy);
70 }
71
72 Matrix<value_type> gemm_inner(const CVecRef<AL> &xx, const CVecRef<AR> &yy) override {
73 auto prof = molpro::Profiler::single()->push("ArrayHandlerDDiskDistr::gemm_inner");
74 this->m_counter->gemm_inner++;
75 return gemm_inner_distr_distr(xx, yy);
76 }
77
78 std::map<size_t, value_type_abs> select_max_dot(size_t n, const AL &x, const AR &y) override {
79 return x.select_max_dot(n, y);
80 }
81
82 std::map<size_t, value_type_abs> select(size_t n, const AL &x, bool max = false, bool ignore_sign = false) override {
83 return x.select(n, max, ignore_sign);
84 }
85
86protected:
87 std::function<AL(const AR &)> m_copy_func;
88};
89
90} // namespace molpro::linalg::array
91
92#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_ARRAYHANDLERDDISKDISTR_H
Definition: ArrayHandlerDDiskDistr.h:13
ArrayHandlerDDiskDistr()
Definition: ArrayHandlerDDiskDistr.h:21
Matrix< value_type > gemm_inner(const CVecRef< AL > &xx, const CVecRef< AR > &yy) override
Definition: ArrayHandlerDDiskDistr.h:72
AL copy(const AR &source) override
Definition: ArrayHandlerDDiskDistr.h:40
void axpy(value_type alpha, const AR &x, AL &y) override
Definition: ArrayHandlerDDiskDistr.h:57
void scal(value_type alpha, AL &x) override
Definition: ArrayHandlerDDiskDistr.h:50
void gemm_outer(const Matrix< value_type > alphas, const CVecRef< AR > &xx, const VecRef< AL > &yy) override
Definition: ArrayHandlerDDiskDistr.h:67
void copy(AL &x, const AR &y) override
Definition: ArrayHandlerDDiskDistr.h:45
std::function< AL(const AR &)> m_copy_func
function for making a copy
Definition: ArrayHandlerDDiskDistr.h:87
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: ArrayHandlerDDiskDistr.h:82
void fill(value_type alpha, AL &x) override
Definition: ArrayHandlerDDiskDistr.h:55
std::map< size_t, value_type_abs > select_max_dot(size_t n, const AL &x, const AR &y) override
Definition: ArrayHandlerDDiskDistr.h:78
ProxyHandle lazy_handle() override
Returns a lazy handle. Most implementations simply need to call the overload: return lazy_handle(*thi...
Definition: ArrayHandlerDDiskDistr.h:35
value_type dot(const AL &x, const AR &y) override
Definition: ArrayHandlerDDiskDistr.h:62
ArrayHandlerDDiskDistr(std::function< AL(const AR &)> copy_func)
Constructor taking a copy function.
Definition: ArrayHandlerDDiskDistr.h:32
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
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:30
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:18