MPQC  3.0.0-alpha
forward.hpp
1 #ifndef MPQC_ARRAY_FORWARD_HPP
2 #define MPQC_ARRAY_FORWARD_HPP
3 
4 #include "mpqc/range.hpp"
5  #include "mpqc/utility/debug.hpp"
6 
7 namespace mpqc {
8 
9  template<typename T>
10  struct Array;
11 
12 }
13 
14 namespace mpqc {
15 namespace detail {
16 
17  template<typename T, typename Driver>
18  struct array_impl;
19 
20  template<typename T, class Driver>
22 
23  struct ArrayBase {
24 
25  public:
26 
27  template<typename U>
28  static range extent(U n) {
29  return range(0,n);
30  }
31 
32  static range extent(range r) {
33  return r;
34  }
35 
36  protected:
37 
38  virtual void _put(const std::vector<range> &r, const void *buffer) = 0;
39  virtual void _get(const std::vector<range> &r, void *buffer) const = 0;
40 
41  public:
42 
43  virtual ~ArrayBase() {}
44  virtual void sync() = 0;
45 
46  template<typename Extent>
47  ArrayBase(const std::string &name,
48  const std::vector<Extent> &extents)
49  {
50  name_ = name;
51  for (size_t i = 0; i < extents.size(); ++i) {
52  range r = extent(extents.at(i));
53  base_.push_back(*r.begin());
54  dims_.push_back(r.size());
55  }
56  }
57 
58  const std::string name() const {
59  return this->name_;
60  }
61 
62  size_t rank() const {
63  MPQC_ASSERT(dims_.size() == base_.size());
64  return dims_.size();
65  }
66 
67  size_t size() const {
68  size_t size = 1;
69  for (size_t i = 0; i < dims_.size(); ++i) {
70  size *= dims_.at(i);
71  }
72  return size;
73  }
74 
75  void put(const std::vector<range> &r, const void *buffer) {
76  _put(rebase(r), buffer);
77  }
78 
79  void get(const std::vector<range> &r, void *buffer) const {
80  _get(rebase(r), buffer);
81  }
82 
83  protected:
84 
85  std::string name_;
86  std::vector<size_t> dims_;
87  std::vector<size_t> base_;
88 
89  void check_range(const std::vector<range> &R) const {
90  MPQC_ASSERT(this->rank() == R.size());
91  for (size_t i = 0; i < this->rank(); ++i) {
92  range r = R.at(i);
93  //std::cout << "range = " << r << "base = " << base_.at(i) << std::endl;
94  MPQC_ASSERT(base_.at(i) <= *r.begin());
95  MPQC_ASSERT(*r.end() <= base_.at(i) + dims_.at(i));
96  }
97  }
98 
99  std::vector<range> rebase(std::vector<range> R) const {
100  check_range(R);
101  for (size_t i = 0; i < R.size(); ++i) {
102  range r = R.at(i);
103  size_t base = base_.at(i);
104  R.at(i) = range(*r.begin()-base, *r.end()-base);
105  }
106  return R;
107  }
108 
109  };
110 
111 
112 } // namespace detail
113 } // namespace mpqc
114 
115 
116 #endif /* MPQC_ARRAY_FORWARD_HPP */
mpqc::detail::array_impl
Definition: forward.hpp:18
mpqc
Contains new MPQC code since version 3.
Definition: integralenginepool.hpp:37
mpqc::range
Definition: range.hpp:23
mpqc::Array
Array implementation.
Definition: forward.hpp:10
mpqc::detail::array_parallel_impl
Definition: forward.hpp:21
mpqc::detail::ArrayBase
Definition: forward.hpp:23

Generated at Sun Jan 26 2020 23:24:01 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.