unary_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  * unary_engine.h
22  * Apr 1, 2014
23  *
24  */
25 
26 #ifndef TILEDARRAY_EXPRESSIONS_UNARY_ENGINE_H__INCLUDED
27 #define TILEDARRAY_EXPRESSIONS_UNARY_ENGINE_H__INCLUDED
28 
31 
32 namespace TiledArray {
33 namespace expressions {
34 
35 // Forward declarations
36 template <typename>
37 class UnaryExpr;
38 
39 template <typename Derived>
40 class UnaryEngine : ExprEngine<Derived> {
41  public:
42  // Class hierarchy typedefs
45 
46  // Argument typedefs
49 
50  // Operational typedefs
51  typedef typename EngineTrait<Derived>::value_type
53  typedef typename EngineTrait<Derived>::op_type
55  typedef
59 
60  // Meta data typedefs
62  typedef typename EngineTrait<Derived>::trange_type
67 
68  static constexpr bool consumable = true;
69  static constexpr unsigned int leaves = argument_type::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  private:
84  // Not allowed
85  UnaryEngine(const UnaryEngine_&);
86  UnaryEngine_& operator=(const UnaryEngine_&);
87 
88  public:
89  template <typename D>
90  UnaryEngine(const UnaryExpr<D>& expr) : ExprEngine_(expr), arg_(expr.arg()) {}
91 
92  // Pull base class functions into this class.
95 
97 
101  void perm_indices(const BipartiteIndexList& target_indices) {
103 
104  indices_ = target_indices;
105  if (arg_.indices() != target_indices) arg_.perm_indices(target_indices);
106  }
107 
109 
111  void init_indices(const BipartiteIndexList& target_indices) {
112  arg_.init_indices(target_indices);
113  perm_indices(target_indices);
114  }
115 
117  void init_indices() {
118  arg_.init_indices();
119  indices_ = arg_.indices();
120  }
121 
123 
127  void init_struct(const BipartiteIndexList& target_indices) {
128  arg_.init_struct(ExprEngine_::indices());
129  ExprEngine_::init_struct(target_indices);
130  }
131 
133 
139  const std::shared_ptr<pmap_interface>& pmap) {
140  arg_.init_distribution(world, pmap);
142  }
143 
145 
147  trange_type make_trange() const { return arg_.trange(); }
148 
150 
154  return perm ^ arg_.trange();
155  }
156 
158 
162  typename argument_type::dist_eval_type, typename Derived::op_type,
163  typename dist_eval_type::policy>
164  impl_type;
165 
166  // Construct left and right distributed evaluators
167  const typename argument_type::dist_eval_type arg = arg_.make_dist_eval();
168 
169  // Construct the distributed evaluator type
170  std::shared_ptr<impl_type> pimpl = std::make_shared<impl_type>(
172 
173  return dist_eval_type(pimpl);
174  }
175 
177 
180  void print(ExprOStream os, const BipartiteIndexList& target_indices) const {
181  ExprEngine_::print(os, target_indices);
182  os.inc();
183  arg_.print(os, indices_);
184  os.dec();
185  }
186 
187 }; // class UnaryEngine
188 
189 } // namespace expressions
190 } // namespace TiledArray
191 
192 #endif // TILEDARRAY_EXPRESSIONS_UNARY_ENGINE_H__INCLUDED
void init_struct(const BipartiteIndexList &target_indices)
Initialize result tensor structure.
Definition: expr_engine.h:150
EngineTrait< Derived >::value_type value_type
The result tile type.
Definition: unary_engine.h:52
void print(ExprOStream os, const BipartiteIndexList &target_indices) const
Expression print.
Definition: unary_engine.h:180
BipartitePermutation perm_
The permutation that will be applied to the outer tensor of tensors.
Definition: expr_engine.h:80
void inc()
Increment the number of tabs.
Definition: expr_trace.h:71
argument_type arg_
The argument.
Definition: unary_engine.h:81
World * world() const
World accessor.
Definition: expr_engine.h:219
UnaryEngine(const UnaryExpr< D > &expr)
Definition: unary_engine.h:90
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
EngineTrait< Derived >::argument_type argument_type
The argument expression engine type.
Definition: unary_engine.h:48
void init_indices(const BipartiteIndexList &target_indices)
Initialize the index list of this expression.
Definition: unary_engine.h:111
Permutation of a sequence of objects indexed by base-0 indices.
Definition: permutation.h:130
EngineTrait< Derived >::shape_type shape_type
Shape type.
Definition: unary_engine.h:64
Tensor that is composed from an argument tensor.
Definition: unary_eval.h:40
std::shared_ptr< pmap_interface > pmap_
The process map for the result tensor.
Definition: expr_engine.h:84
void init_distribution(World *world, const std::shared_ptr< pmap_interface > &pmap)
Initialize result tensor distribution.
Definition: unary_engine.h:138
World * world_
The world where this expression will be evaluated.
Definition: expr_engine.h:73
EngineTrait< Derived >::dist_eval_type dist_eval_type
The distributed evaluator type.
Definition: unary_engine.h:58
const BipartiteIndexList & indices() const
Index list accessor.
Definition: expr_engine.h:224
void perm_indices(const BipartiteIndexList &target_indices)
Set the index list for this expression.
Definition: unary_engine.h:101
EngineTrait< Derived >::trange_type trange_type
Tiled range type.
Definition: unary_engine.h:63
trange_type trange_
The tiled range of the result tensor.
Definition: expr_engine.h:81
EngineTrait< Derived >::dist_eval_type dist_eval_type
This expression's distributed evaluator type.
Definition: expr_engine.h:58
EngineTrait< Derived >::op_type op_type
The tile operation type.
Definition: unary_engine.h:54
EngineTrait< Derived >::policy policy
The result policy type.
Definition: unary_engine.h:56
EngineTrait< Derived >::trange_type trange_type
Tiled range type type.
Definition: expr_engine.h:63
#define TA_ASSERT(EXPR,...)
Definition: error.h:39
void init_indices()
Initialize the index list of this expression.
Definition: unary_engine.h:117
UnaryEngine< Derived > UnaryEngine_
This class type.
Definition: unary_engine.h:43
static constexpr bool consumable
Definition: unary_engine.h:68
const BipartitePermutation & perm() const
Permutation accessor.
Definition: expr_engine.h:229
EngineTrait< Derived >::size_type size_type
Size type.
Definition: unary_engine.h:61
static constexpr unsigned int leaves
Definition: unary_engine.h:69
void init_struct(const BipartiteIndexList &target_indices)
Initialize result tensor structure.
Definition: unary_engine.h:127
Expression output stream.
Definition: expr_trace.h:41
void init_distribution(World *world, const std::shared_ptr< pmap_interface > &pmap)
Initialize result tensor distribution.
Definition: expr_engine.h:171
void dec()
Decrement the number of tabs.
Definition: expr_trace.h:74
EngineTrait< Derived >::pmap_interface pmap_interface
Process map interface type.
Definition: unary_engine.h:66
trange_type make_trange(const Permutation &perm) const
Permuting tiled range factory function.
Definition: unary_engine.h:153
trange_type make_trange() const
Non-permuting tiled range factory function.
Definition: unary_engine.h:147
std::shared_ptr< pmap_interface > pmap_
The process map for the result tensor.
Definition: expr_engine.h:84
shape_type shape_
The shape of the result tensor.
Definition: expr_engine.h:82
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
World * world_
The world where this expression will be evaluated.
Definition: expr_engine.h:73
void print(ExprOStream &os, const BipartiteIndexList &target_indices) const
Expression print.
Definition: expr_engine.h:256
dist_eval_type make_dist_eval() const
Construct the distributed evaluator for this expression.
Definition: unary_engine.h:160
const std::shared_ptr< pmap_interface > & pmap() const
Process map accessor.
Definition: expr_engine.h:244
ExprEngine< Derived > ExprEngine_
Base class type.
Definition: unary_engine.h:44
BipartitePermutation perm_
The permutation that will be applied to the outer tensor of tensors.
Definition: expr_engine.h:80