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