26 #ifndef TILEDARRAY_EXPRESSIONS_BLK_TSR_ENGINE_H__INCLUDED 27 #define TILEDARRAY_EXPRESSIONS_BLK_TSR_ENGINE_H__INCLUDED 35 template <
typename,
typename>
class DistArray;
37 namespace expressions {
45 template <
typename Tile,
typename Policy,
typename Result,
bool Alias>
72 typedef typename policy::pmap_interface
75 static constexpr
bool consumable =
true;
76 static constexpr
unsigned int leaves = 1;
80 template <
typename Tile,
typename Policy,
typename Scalar,
typename Result>
107 typedef typename policy::pmap_interface
110 static constexpr
bool consumable =
true;
111 static constexpr
unsigned int leaves = 1;
117 template <
typename Derived>
167 template <
typename Array,
bool Alias>
173 template <
typename Array,
typename Scalar>
184 const unsigned int rank =
array_.trange().tiles_range().rank();
186 std::vector<TiledRange1> trange_data;
187 trange_data.reserve(rank);
188 std::vector<std::size_t> trange1_data;
191 const auto* MADNESS_RESTRICT
const trange =
array_.trange().data().data();
192 const auto* MADNESS_RESTRICT
const lower =
lower_bound_.data();
193 const auto* MADNESS_RESTRICT
const upper =
upper_bound_.data();
195 for(
unsigned int d = 0u; d < rank; ++d) {
197 const auto lower_d = lower[d];
198 const auto upper_d = upper[d];
202 const auto base_d =
trange[d].tile(i).first;
203 trange1_data.emplace_back(0ul);
204 for(; i < upper_d; ++i)
205 trange1_data.emplace_back(
trange[d].tile(i).second - base_d);
208 trange_data.emplace_back(trange1_data.begin(), trange1_data.end());
209 trange1_data.resize(0ul);
212 return TiledRange(trange_data.begin(), trange_data.end());
220 const unsigned int rank =
array_.trange().tiles_range().rank();
222 std::vector<TiledRange1> trange_data;
223 trange_data.reserve(rank);
224 std::vector<std::size_t> trange1_data;
227 const auto* MADNESS_RESTRICT
const trange =
array_.trange().data().data();
228 const auto* MADNESS_RESTRICT
const lower =
lower_bound_.data();
229 const auto* MADNESS_RESTRICT
const upper =
upper_bound_.data();
233 for(
unsigned int d = 0u; d < rank; ++d) {
234 const auto inv_perm_d = inv_perm[d];
237 const auto lower_i = lower[inv_perm_d];
238 const auto upper_i = upper[inv_perm_d];
242 const auto base_d =
trange[inv_perm_d].tile(i).first;
243 trange1_data.emplace_back(0ul);
244 for(; i < upper_i; ++i)
245 trange1_data.emplace_back(
trange[inv_perm_d].tile(i).second - base_d);
248 trange_data.emplace_back(trange1_data.begin(), trange1_data.end());
249 trange1_data.resize(0ul);
252 return TiledRange(trange_data.begin(), trange_data.end());
257 const std::shared_ptr<pmap_interface>&
pmap)
269 std::shared_ptr<impl_type> pimpl = std::make_shared<impl_type>(
280 std::stringstream ss;
298 template <
typename Array,
typename Result,
bool Alias>
299 class BlkTsrEngine :
public BlkTsrEngineBase<BlkTsrEngine<Array, Result, Alias> > {
302 typedef BlkTsrEngine<Array, Result, Alias>
353 template <
typename A>
377 const unsigned int rank =
trange_.tiles_range().rank();
380 std::vector<long> range_shift;
381 range_shift.reserve(rank);
384 const auto* MADNESS_RESTRICT
const trange =
array_.trange().data().data();
385 const auto* MADNESS_RESTRICT
const lower =
lower_bound_.data();
388 for(
unsigned int d = 0u; d < rank; ++d) {
389 const auto lower_d = lower[d];
390 const auto base_d =
trange[d].tile(lower_d).first;
391 range_shift.emplace_back(-base_d);
402 const unsigned int rank =
trange_.tiles_range().rank();
405 std::vector<long> range_shift(rank, 0l);
408 const auto* MADNESS_RESTRICT
const trange =
array_.trange().data().data();
409 const auto* MADNESS_RESTRICT
const lower =
lower_bound_.data();
412 for(
unsigned int d = 0u; d < rank; ++d) {
413 const auto perm_d =
perm[d];
414 const auto lower_d = lower[d];
415 const auto base_d =
trange[d].tile(lower_d).first;
416 range_shift[perm_d] = -base_d;
427 std::stringstream ss;
441 template <
typename Array,
typename Scalar,
typename Result>
442 class ScalBlkTsrEngine :
443 public BlkTsrEngineBase<ScalBlkTsrEngine<Array, Scalar, Result> >
447 typedef ScalBlkTsrEngine<Array, Scalar, Result>
492 template <
typename A,
typename S>
517 const unsigned int rank =
trange_.tiles_range().rank();
520 std::vector<long> range_shift;
521 range_shift.reserve(rank);
524 const auto* MADNESS_RESTRICT
const trange =
array_.trange().data().data();
525 const auto* MADNESS_RESTRICT
const lower =
lower_bound_.data();
528 for(
unsigned int d = 0u; d < rank; ++d) {
529 const auto lower_d = lower[d];
530 const auto base_d =
trange[d].tile(lower_d).first;
531 range_shift.emplace_back(-base_d);
542 const unsigned int rank =
trange_.tiles_range().rank();
545 std::vector<long> range_shift(rank, 0l);
548 const auto* MADNESS_RESTRICT
const trange =
array_.trange().data().data();
549 const auto* MADNESS_RESTRICT
const lower =
lower_bound_.data();
552 for(
unsigned int d = 0u; d < rank; ++d) {
553 const auto perm_d =
perm[d];
554 const auto lower_d = lower[d];
555 const auto base_d =
trange[d].tile(lower_d).first;
556 range_shift[perm_d] = -base_d;
567 std::stringstream ss;
568 ss <<
"[block] [" <<
factor_ <<
"] ";
578 #endif // TILEDARRAY_EXPRESSIONS_BLK_TSR_ENGINE_H__INCLUDED policy::shape_type shape_type
Shape type.
TiledArray::detail::LazyArrayTile< typename array_type::value_type, op_type > value_type
Tile type.
trange_type make_trange(const Permutation &perm) const
Permuting tiled range factory function.
Policy policy
Policy type.
array_type array_
The array object.
EngineTrait< ScalBlkTsrEngine_ >::value_type value_type
Tensor value type.
BlkTsrEngineBase< ScalBlkTsrEngine_ > BlkTsrEngineBase_
Block tensor base class type.
EngineTrait< BlkTsrEngine_ >::size_type size_type
Size type.
Scaled tensor block expression engine.
policy::trange_type trange_type
Tiled range type.
EngineTrait< Derived >::pmap_interface pmap_interface
Process map interface type.
trange_type trange_
The tiled range of the result tensor.
LeafEngine_::ExprEngine_ ExprEngine_
Expression engine base class.
const trange_type & trange() const
Tiled range accessor.
EngineTrait< ScalBlkTsrEngine_ >::pmap_interface pmap_interface
Process map interface type.
bool permute_tiles_
Result tile permutation flag (true == permute tile)
void init_distribution(World *world, const std::shared_ptr< pmap_interface > &pmap)
const Permutation & perm() const
Permutation accessor.
EngineTrait< Derived >::value_type value_type
Tensor value type.
policy::shape_type shape_type
Shape type.
BlkTsrEngineBase_::LeafEngine_ LeafEngine_
Leaf base class type.
Determine the object type used in the evaluation of tensor expressions.
TiledArray::detail::UnaryWrapper< op_base_type > op_type
The tile operation.
EngineTrait< ScalBlkTsrEngine_ >::scalar_type scalar_type
Tile scalar type.
policy::pmap_interface pmap_interface
Process map interface type.
BlkTsrEngineBase(const ScalBlkTsrExpr< Array, Scalar > &expr)
BlkTsrEngine(const BlkTsrExpr< A, Alias > &expr)
Tensor expression engine.
BlkTsrEngineBase< BlkTsrEngine_ > BlkTsrEngineBase_
Block tensor base class type.
EngineTrait< Derived >::shape_type shape_type
Tensor shape type.
trange_type make_trange() const
Non-permuting tiled range factory function.
shape_type make_shape()
Non-permuting shape factory function.
LeafEngine_::ExprEngine_ ExprEngine_
Expression engine base class.
World * world() const
World accessor.
std::string make_tag() const
Expression identification tag.
EngineTrait< ScalBlkTsrEngine_ >::policy policy
The result policy type.
LeafEngine< Derived > LeafEngine_
Leaf base class type.
op_type make_op() const
Tile operation factory function.
EngineTrait< BlkTsrEngine_ >::value_type value_type
Tensor value type.
EngineTrait< BlkTsrEngine_ >::op_type op_type
Tile operation type.
op_type make_tile_op(const Permutation &perm) const
Permuting tile operation factory function.
policy::pmap_interface pmap_interface
Process map interface type.
array_type array_
The array object.
Unary tile operation wrapper.
EngineTrait< BlkTsrEngine_ >::policy policy
The result policy type.
Type trait for extracting the scalar type of tensors and arrays.
shape_type make_shape(const Permutation &perm)
Permuting shape factory function.
EngineTrait< ScalBlkTsrEngine_ >::trange_type trange_type
Tiled range type type.
const std::shared_ptr< pmap_interface > & pmap() const
Process map accessor.
shape_type make_shape()
Non-permuting shape factory function.
VariableList vars_
The variable list of this expression.
EngineTrait< ScalBlkTsrEngine_ >::dist_eval_type dist_eval_type
This expression's distributed evaluator type.
EngineTrait< BlkTsrEngine_ >::dist_eval_type dist_eval_type
This expression's distributed evaluator type.
DistArray< Tile, Policy > array_type
The array type.
BlkTsrEngine< Array, Result, Alias > BlkTsrEngine_
This class type.
EngineTrait< ScalBlkTsrEngine_ >::size_type size_type
Size type.
Lazy tile for on-the-fly evaluation of array tiles.
EngineTrait< BlkTsrEngine_ >::pmap_interface pmap_interface
Process map interface type.
TiledArray::detail::UnaryWrapper< op_base_type > op_type
The tile operation.
eval_trait< value_type >::type eval_type
Evaluation tile type.
ScalBlkTsrEngine< Array, Scalar, Result > ScalBlkTsrEngine_
This class type.
Tensor expression object.
EngineTrait< BlkTsrEngine_ >::trange_type trange_type
Tiled range type type.
EngineTrait< Derived >::trange_type trange_type
Tiled range type type.
void print_array(std::ostream &out, const A &a, const std::size_t n)
Print the content of an array like object.
DistArray< Tile, Policy > array_type
The array type.
std::string make_tag() const
Expression identification tag.
std::string make_tag() const
Expression identification tag.
policy::trange_type trange_type
Tiled range type.
EngineTrait< Derived >::op_type op_type
Tile operation type.
LeafEngine_::ExprEngine_ ExprEngine_
Expression engine base class.
std::vector< std::size_t > upper_bound_
Upper bound of the tile block.
policy::size_type size_type
Size type.
EngineTrait< Derived >::size_type size_type
Size type.
EngineTrait< BlkTsrEngine_ >::shape_type shape_type
Tensor shape type.
policy::size_type size_type
Size type.
std::shared_ptr< pmap_interface > pmap_
The process map for the result tensor.
Range data of a tiled array.
TiledArray::detail::DistEval< value_type, policy > dist_eval_type
The distributed evaluator type.
EngineTrait< ScalBlkTsrEngine_ >::shape_type shape_type
Tensor shape type.
World * world_
The world where this expression will be evaluated.
Policy policy
Policy type.
op_type make_tile_op() const
Non-permuting tile operation factory function.
op_type make_tile_op() const
Non-permuting tile operation factory function.
BlkTsrEngineBase(const BlkTsrExpr< Array, Alias > &expr)
EngineTrait< Derived >::dist_eval_type dist_eval_type
This expression's distributed evaluator type.
EngineTrait< Derived >::policy policy
The result policy type.
Permutation of a sequence of objects indexed by base-0 indices.
EngineTrait< ScalBlkTsrEngine_ >::op_type op_type
Tile operation type.
op_type make_tile_op(const Permutation &perm) const
Permuting tile operation factory function.
EngineTrait< BlkTsrEngine_ >::array_type array_type
The input array type.
Permutation perm_
The permutation that will be applied to the result.
Distributed evaluator for TiledArray::Array objects.
TiledArray::detail::ScalShift< Result, typename TiledArray::eval_trait< typename array_type::value_type >::type, scalar_type, TiledArray::eval_trait< typename array_type::value_type >::is_consumable > op_base_type
The base tile operation.
void init_distribution(World *world, const std::shared_ptr< pmap_interface > &pmap)
Initialize result tensor distribution.
shape_type shape_
The shape of the result tensor.
TiledArray::detail::scalar_type< DistArray< Tile, Policy > >::type scalar_type
eval_trait< value_type >::type eval_type
Evaluation tile type.
TiledArray::detail::DistEval< value_type, policy > dist_eval_type
The distributed evaluator type.
EngineTrait< ScalBlkTsrEngine_ >::op_base_type op_base_type
Tile base operation type.
EngineTrait< Derived >::array_type array_type
The input array type.
ScalBlkTsrEngine(const ScalBlkTsrExpr< A, S > &expr)
BlkTsrEngineBase< Derived > BlkTsrEngineBase_
This class type.
EngineTrait< ScalBlkTsrEngine_ >::array_type array_type
The input array type.
BlkTsrEngineBase_::LeafEngine_ LeafEngine_
Leaf base class type.
dist_eval_type make_dist_eval() const
Construct the distributed evaluator for array.
An N-dimensional shallow copy wrapper for tile objects.
trange_type trange_
The tiled range of the result tensor.
TiledArray::detail::LazyArrayTile< typename array_type::value_type, op_type > value_type
Tile type.
shape_type make_shape(const Permutation &perm)
Permuting shape factory function.
std::vector< std::size_t > lower_bound_
Lower bound of the tile block.
EngineTrait< BlkTsrEngine_ >::op_base_type op_base_type
Tile base operation type.
Tensor expression engine.