leaf_engine.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2014 Virginia Tech
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Justus Calvin
19  * Department of Chemistry, Virginia Tech
20  *
21  * leaf_engine.h
22  * Mar 31, 2014
23  *
24  */
25 
26 #ifndef TILEDARRAY_EXPRESSIONS_LEAF_ENGINE_H__INCLUDED
27 #define TILEDARRAY_EXPRESSIONS_LEAF_ENGINE_H__INCLUDED
28 
31 
32 namespace TiledArray {
33 namespace expressions {
34 
36 
38 template <typename Derived>
39 class LeafEngine : public ExprEngine<Derived> {
40  public:
41  // Class hierarchy typedefs
44 
45  // Argument typedefs
46  typedef typename EngineTrait<Derived>::array_type
48 
49  // Operational typedefs
50  typedef typename EngineTrait<Derived>::value_type
52  typedef
54  typedef
58 
59  // Meta data typedefs
61  typedef typename EngineTrait<Derived>::trange_type
63  typedef typename EngineTrait<Derived>::shape_type
67 
69  static constexpr unsigned int leaves = EngineTrait<Derived>::leaves;
70 
71  protected:
72  // Import base class variables to this scope
74  using ExprEngine_::perm_;
76  using ExprEngine_::pmap_;
77  using ExprEngine_::shape_;
79  using ExprEngine_::world_;
80 
82 
83  public:
85 
87  template <typename D>
88  LeafEngine(const Expr<D>& expr)
89  : ExprEngine_(expr), array_(expr.derived().array()) {
90  indices_ = BipartiteIndexList(expr.derived().annotation());
91  }
92 
93  // Import base class variables to this scope
95 
97 
100 
102 
105  void init_indices(const BipartiteIndexList& target_indices) {
106 #ifndef NDEBUG
107  if (!target_indices.is_permutation(indices_)) {
108  if (TiledArray::get_default_world().rank() == 0) {
110  "The array index list is not compatible with the expected "
111  "output:"
112  << "\n expected = " << target_indices
113  << "\n array = " << indices_);
114  }
115 
116  TA_EXCEPTION(
117  "Target index list is not a permutation of the given array index "
118  "list "
119  "list.");
120  }
121 #endif // NDEBUG
122  }
123 
125 
127  void init_indices() {}
128 
130  const std::shared_ptr<pmap_interface>& pmap) {
132  }
133 
135 
137  trange_type make_trange() const { return array_.trange(); }
138 
140 
144  return perm * array_.trange();
145  }
146 
148 
150  shape_type make_shape() { return array_.shape(); }
151 
153 
157  return array_.shape().perm(perm);
158  }
159 
162  // Define the distributed evaluator implementation type
164  impl_type;
165 
167  std::shared_ptr<impl_type> pimpl =
168  std::make_shared<impl_type>(array_, *world_, trange_, shape_, pmap_,
170 
171  return dist_eval_type(pimpl);
172  }
173 
174 }; // class LeafEngine
175 
176 } // namespace expressions
177 } // namespace TiledArray
178 
179 #endif // TILEDARRAY_EXPRESSIONS_LEAF_ENGINE_H__INCLUDED
LeafEngine< Derived > LeafEngine_
This class type.
Definition: leaf_engine.h:42
LeafEngine(const Expr< D > &expr)
Engine constructor.
Definition: leaf_engine.h:88
EngineTrait< Derived >::op_type op_type
Tile operation type.
Definition: leaf_engine.h:53
World * world() const
World accessor.
Definition: expr_engine.h:219
EngineTrait< Derived >::size_type size_type
Size type.
Definition: leaf_engine.h:60
EngineTrait< Derived >::shape_type shape_type
Tensor shape type.
Definition: expr_engine.h:65
derived_type & derived()
Cast this object to its derived type.
Definition: expr_engine.h:209
derived_type & derived()
Cast this object to its derived type.
Definition: expr_engine.h:209
trange_type trange_
The tiled range of the result tensor.
Definition: expr_engine.h:81
Permutation of a sequence of objects indexed by base-0 indices.
Definition: permutation.h:130
dist_eval_type make_dist_eval() const
Construct the distributed evaluator for array.
Definition: leaf_engine.h:161
auto outer(const IndexList &p)
Definition: index_list.h:879
std::shared_ptr< pmap_interface > pmap_
The process map for the result tensor.
Definition: expr_engine.h:84
EngineTrait< Derived >::policy policy
The result policy type.
Definition: leaf_engine.h:55
Distributed evaluator for TiledArray::Array objects.
Definition: array_eval.h:173
World * world_
The world where this expression will be evaluated.
Definition: expr_engine.h:73
static constexpr unsigned int leaves
Definition: leaf_engine.h:69
Base class for expression evaluation.
Definition: expr.h:97
#define TA_EXCEPTION(m)
Definition: error.h:83
Leaf expression engine.
Definition: leaf_engine.h:39
auto rank(const DistArray< Tile, Policy > &a)
Definition: dist_array.h:1617
EngineTrait< Derived >::dist_eval_type dist_eval_type
This expression's distributed evaluator type.
Definition: expr_engine.h:58
EngineTrait< Derived >::trange_type trange_type
Tiled range type type.
Definition: expr_engine.h:63
World & get_default_world()
Definition: madness.h:90
shape_type shape_
The shape of the result tensor.
Definition: expr_engine.h:82
shape_type make_shape()
Non-permuting shape factory function.
Definition: leaf_engine.h:150
EngineTrait< Derived >::shape_type shape_type
Tensor shape type.
Definition: leaf_engine.h:64
shape_type make_shape(const Permutation &perm)
Permuting shape factory function.
Definition: leaf_engine.h:156
const BipartitePermutation & perm() const
Permutation accessor.
Definition: expr_engine.h:229
EngineTrait< ScalBlkTsrEngine_ >::array_type array_type
The input array type.
EngineTrait< Derived >::pmap_interface pmap_interface
Process map interface type.
Definition: leaf_engine.h:66
void init_distribution(World *world, const std::shared_ptr< pmap_interface > &pmap)
Initialize result tensor distribution.
Definition: expr_engine.h:171
static constexpr bool consumable
Definition: leaf_engine.h:68
trange_type make_trange(const Permutation &perm) const
Permuting tiled range factory function.
Definition: leaf_engine.h:143
array_type array_
The array object.
Definition: leaf_engine.h:81
void init_distribution(World *world, const std::shared_ptr< pmap_interface > &pmap)
Definition: leaf_engine.h:129
EngineTrait< Derived >::array_type array_type
The left-hand expression type.
Definition: leaf_engine.h:47
World * world_
The world where this expression will be evaluated.
Definition: expr_engine.h:73
EngineTrait< Derived >::trange_type trange_type
Tiled range type type.
Definition: leaf_engine.h:62
std::shared_ptr< pmap_interface > pmap_
The process map for the result tensor.
Definition: expr_engine.h:84
void init_indices(const BipartiteIndexList &target_indices)
Initialize the index list of this expression.
Definition: leaf_engine.h:105
ExprEngine< Derived > ExprEngine_
Base class type.
Definition: leaf_engine.h:43
BipartitePermutation perm_
The permutation that will be applied to the outer tensor of tensors.
Definition: expr_engine.h:80
void init_indices()
Initialize the index list of this expression.
Definition: leaf_engine.h:127
#define TA_USER_ERROR_MESSAGE(m)
Definition: error.h:93
bool is_permutation(const BipartiteIndexList &other) const
Check that this index list is a permutation of other.
Definition: index_list.h:692
EngineTrait< Derived >::value_type value_type
Tensor value type.
Definition: leaf_engine.h:51
shape_type shape_
The shape of the result tensor.
Definition: expr_engine.h:82
op_type make_op() const
Tile operation factory function.
Definition: expr_engine.h:199
trange_type make_trange() const
Non-permuting tiled range factory function.
Definition: leaf_engine.h:137
EngineTrait< Derived >::dist_eval_type dist_eval_type
This expression's distributed evaluator type.
Definition: leaf_engine.h:57
const std::shared_ptr< pmap_interface > & pmap() const
Process map accessor.
Definition: expr_engine.h:244
trange_type trange_
The tiled range of the result tensor.
Definition: expr_engine.h:81
derived_type & derived()
Cast this object to its derived type.
Definition: expr.h:365
void perm_indices(const BipartiteIndexList &)
Set the index list for this expression.
Definition: leaf_engine.h:99
BipartitePermutation perm_
The permutation that will be applied to the outer tensor of tensors.
Definition: expr_engine.h:80