4 #include "mpqc/range.hpp"
5 #include "mpqc/range/operator.hpp"
6 #include "mpqc/mpi.hpp"
8 #include "mpqc/array/core.hpp"
9 #include "mpqc/array/file.hpp"
11 #include "mpqc/array/parallel.hpp"
14 #include "mpqc/utility/check.hpp"
15 #include <boost/foreach.hpp>
16 #include "mpqc/utility/exception.hpp"
32 template<
typename Extent>
34 const std::vector<Extent> &extents,
37 initialize(name, extents, ARRAY_CORE, comm);
41 template<
typename Extent,
class Driver>
43 const std::vector<Extent> &extents,
47 initialize(name, extents, driver, comm);
61 void put(
const T *buffer) {
62 impl_->put(this->range_, buffer);
67 void get(T *buffer)
const {
68 impl_->get(this->range_, buffer);
75 const std::vector<size_t>& dims()
const {
83 operator vector<T>()
const {
84 vector<T> p(range_[0].size());
89 operator matrix<T>()
const {
90 matrix<T> p(range_[0].size(), range_[1].size());
95 Array operator()(
const std::vector<range> &r) {
96 MPQC_CHECK(this->rank() == r.size());
97 return Array(*
this, r);
100 Array operator()(
const std::vector<range> &r)
const {
101 MPQC_CHECK(this->rank() == r.size());
102 return Array(*
this, r);
114 template<
class R, ...>
115 Array operator()(
const R &r, ...);
118 Array operator()(
const range::tie<S> &t) {
119 return this->operator()(std::vector<range>(t));
122 Array operator()(
const range::tie<S> &t)
const {
123 return this->operator()(std::vector<range>(t));
131 template<
class Extent,
class Driver>
132 void initialize(
const std::string &name,
133 const std::vector<Extent> &extents,
134 Driver driver, MPI::Comm comm) {
136 BOOST_FOREACH (
auto e, extents) {
137 range_.push_back(detail::ArrayBase::extent(e));
138 dims_.push_back(range_.back().size());
142 detail::ArrayBase *impl = NULL;
143 if (comm == MPI::Comm::Self()) {
144 impl =
new detail::array_impl<T, Driver>(name, dims_);
148 impl =
new detail::array_parallel_impl<T, Driver>(name, dims_, comm);
151 "library was compiled without proper MPI support");
155 this->impl_.reset(impl);
158 Array(
const Array &A,
const std::vector<range> &r)
160 MPQC_CHECK(A.rank() == r.size());
162 BOOST_FOREACH (range r, range_) {
164 dims_.push_back(r.size());
170 size_t block()
const {
171 MPQC_ASSERT(this->rank() == 2);
172 range ri = range_[0];
173 return std::max<size_t>((8 << 20)/(
sizeof(T)*ri.size()), 1);
177 std::vector<range> range_;
178 std::vector<size_t> dims_;
179 std::shared_ptr<detail::ArrayBase> impl_;
190 template<
typename T,
class V>
203 template<
typename T,
class V>