TiledArray  0.7.0
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
47 
48  // Operational typedefs
53 
54  // Meta data typedefs
59 
61  static constexpr unsigned int leaves = EngineTrait<Derived>::leaves;
62 
63  protected:
64 
65  // Import base class variables to this scope
66  using ExprEngine_::world_;
67  using ExprEngine_::vars_;
68  using ExprEngine_::perm_;
70  using ExprEngine_::shape_;
71  using ExprEngine_::pmap_;
73 
75 
76  public:
77 
79 
81  template <typename D>
82  LeafEngine(const Expr<D>& expr) :
83  ExprEngine_(expr),
84  array_(expr.derived().array())
85  {
86  vars_ = VariableList(expr.derived().vars());
87  }
88 
89  // Import base class variables to this scope
91 
93 
95  void perm_vars(const VariableList&) { }
96 
98 
101  void init_vars(const VariableList& target_vars) {
102 #ifndef NDEBUG
103  if(! target_vars.is_permutation(vars_)) {
104  if(TiledArray::get_default_world().rank() == 0) {
106  "The array variable list is not compatible with the expected output:" \
107  << "\n expected = " << target_vars \
108  << "\n array = " << vars_ );
109  }
110 
111  TA_EXCEPTION("Target variable is not a permutation of the given array variable list.");
112  }
113 #endif // NDEBUG
114  }
115 
116 
118 
120  void init_vars() { }
121 
123  const std::shared_ptr<pmap_interface>& pmap)
124  {
126  }
127 
128 
130 
132  trange_type make_trange() const { return array_.trange(); }
133 
135 
139  return perm * array_.trange();
140  }
141 
143 
145  shape_type make_shape() { return array_.shape(); }
146 
148 
151  shape_type
152  make_shape(const Permutation& perm) { return array_.shape().perm(perm); }
153 
154 
157  // Define the distributed evaluator implementation type
159 
161  std::shared_ptr<impl_type> pimpl =
162  std::make_shared<impl_type>(array_, *world_, trange_, shape_, pmap_,
164 
165  return dist_eval_type(pimpl);
166  }
167 
168  }; // class LeafEngine
169 
170  } // namespace expressions
171 } // namespace TiledArray
172 
173 #endif // TILEDARRAY_EXPRESSIONS_LEAF_ENGINE_H__INCLUDED
EngineTrait< Derived >::size_type size_type
Size type.
Definition: leaf_engine.h:55
shape_type make_shape()
Non-permuting shape factory function.
Definition: leaf_engine.h:145
bool permute_tiles_
Result tile permutation flag (true == permute tile)
Definition: expr_engine.h:65
const Permutation & perm() const
Permutation accessor.
Definition: expr_engine.h:204
static constexpr bool consumable
Definition: leaf_engine.h:60
trange_type make_trange(const Permutation &perm) const
Permuting tiled range factory function.
Definition: leaf_engine.h:138
World * world() const
World accessor.
Definition: expr_engine.h:194
void perm_vars(const VariableList &)
Set the variable list for this expression.
Definition: leaf_engine.h:95
static constexpr unsigned int leaves
Definition: leaf_engine.h:61
op_type make_op() const
Tile operation factory function.
Definition: expr_engine.h:178
EngineTrait< Derived >::array_type array_type
The left-hand expression type.
Definition: leaf_engine.h:46
EngineTrait< Derived >::trange_type trange_type
Tiled range type type.
Definition: leaf_engine.h:56
EngineTrait< Derived >::dist_eval_type dist_eval_type
This expression&#39;s distributed evaluator type.
Definition: leaf_engine.h:52
array_type array_
The array object.
Definition: leaf_engine.h:74
EngineTrait< Derived >::op_type op_type
Tile operation type.
Definition: leaf_engine.h:50
EngineTrait< Derived >::shape_type shape_type
Tensor shape type.
Definition: leaf_engine.h:57
derived_type & derived()
Cast this object to it&#39;s derived type.
Definition: expr_engine.h:186
EngineTrait< Derived >::pmap_interface pmap_interface
Process map interface type.
Definition: leaf_engine.h:58
const std::shared_ptr< pmap_interface > & pmap() const
Process map accessor.
Definition: expr_engine.h:219
VariableList vars_
The variable list of this expression.
Definition: expr_engine.h:64
EngineTrait< Derived >::policy policy
The result policy type.
Definition: leaf_engine.h:51
LeafEngine< Derived > LeafEngine_
This class type.
Definition: leaf_engine.h:42
LeafEngine(const Expr< D > &expr)
Engine constructor.
Definition: leaf_engine.h:82
EngineTrait< ScalBlkTsrEngine< Array, Scalar, Result > >::trange_type trange_type
Tiled range type type.
Definition: expr_engine.h:55
ExprEngine< Derived > ExprEngine_
Base class type.
Definition: leaf_engine.h:43
EngineTrait< ScalBlkTsrEngine< Array, Scalar, Result > >::shape_type shape_type
Tensor shape type.
Definition: expr_engine.h:56
Variable list manages a list variable strings.
shape_type make_shape(const Permutation &perm)
Permuting shape factory function.
Definition: leaf_engine.h:152
void init_vars()
Initialize the variable list of this expression.
Definition: leaf_engine.h:120
EngineTrait< ScalBlkTsrEngine< Array, Scalar, Result > >::dist_eval_type dist_eval_type
This expression&#39;s distributed evaluator type.
Definition: expr_engine.h:51
std::shared_ptr< pmap_interface > pmap_
The process map for the result tensor.
Definition: expr_engine.h:69
Base class for expression evaluation.
Definition: expr.h:81
derived_type & derived()
Cast this object to it&#39;s derived type.
Definition: expr.h:273
trange_type make_trange() const
Non-permuting tiled range factory function.
Definition: leaf_engine.h:132
World * world_
The world where this expression will be evaluated.
Definition: expr_engine.h:63
void init_distribution(World *world, const std::shared_ptr< pmap_interface > &pmap)
Definition: leaf_engine.h:122
bool is_permutation(const VariableList &other) const
Check that this variable list is a permutation of other.
Permutation of a sequence of objects indexed by base-0 indices.
Definition: permutation.h:119
#define TA_EXCEPTION(m)
Definition: error.h:72
Permutation perm_
The permutation that will be applied to the result.
Definition: expr_engine.h:66
Distributed evaluator for TiledArray::Array objects.
Definition: array_eval.h:138
void init_distribution(World *world, const std::shared_ptr< pmap_interface > &pmap)
Initialize result tensor distribution.
Definition: expr_engine.h:151
shape_type shape_
The shape of the result tensor.
Definition: expr_engine.h:68
void init_vars(const VariableList &target_vars)
Initialize the variable list of this expression.
Definition: leaf_engine.h:101
EngineTrait< Derived >::value_type value_type
Tensor value type.
Definition: leaf_engine.h:49
trange_type trange_
The tiled range of the result tensor.
Definition: expr_engine.h:67
dist_eval_type make_dist_eval() const
Construct the distributed evaluator for array.
Definition: leaf_engine.h:156
#define TA_USER_ERROR_MESSAGE(m)
Definition: error.h:118
Leaf expression engine.
Definition: leaf_engine.h:39