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