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