TiledArray  0.7.0
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 
36  // Forward declarations
37  template <typename> class UnaryExpr;
38 
39 
40  template <typename Derived>
41  class UnaryEngine : ExprEngine<Derived> {
42  public:
43  // Class hierarchy typedefs
46 
47  // Argument typedefs
49 
50  // Operational typedefs
55 
56  // Meta data typedefs
61 
62 
63  static constexpr bool consumable = true;
64  static constexpr unsigned int leaves = argument_type::leaves;
65 
66  protected:
67 
68  // Import base class variables to this scope
69  using ExprEngine_::world_;
70  using ExprEngine_::vars_;
71  using ExprEngine_::perm_;
73  using ExprEngine_::shape_;
74  using ExprEngine_::pmap_;
76 
78 
79  private:
80 
81  // Not allowed
82  UnaryEngine(const UnaryEngine_&);
83  UnaryEngine_& operator=(const UnaryEngine_&);
84 
85  public:
86 
87  template <typename D>
88  UnaryEngine(const UnaryExpr<D>& expr) :
89  ExprEngine_(expr), arg_(expr.arg())
90  { }
91 
92  // Pull base class functions into this class.
94  using ExprEngine_::vars;
95 
97 
101  void perm_vars(const VariableList& target_vars) {
103 
104  vars_ = target_vars;
105  if(arg_.vars() != target_vars)
106  arg_.perm_vars(target_vars);
107  }
108 
110 
112  void init_vars(const VariableList& target_vars) {
113  arg_.init_vars(target_vars);
114  perm_vars(target_vars);
115  }
116 
118  void init_vars() {
119  arg_.init_vars();
120  vars_ = arg_.vars();
121  }
122 
123 
125 
129  void init_struct(const VariableList& target_vars) {
130  arg_.init_struct(ExprEngine_::vars());
131  ExprEngine_::init_struct(target_vars);
132  }
133 
135 
141  const std::shared_ptr<pmap_interface>& pmap)
142  {
143  arg_.init_distribution(world, pmap);
145  }
146 
148 
150  trange_type make_trange() const { return arg_.trange(); }
151 
153 
157  return perm ^ arg_.trange();
158  }
159 
161 
164  typedef TiledArray::detail::UnaryEvalImpl<typename argument_type::dist_eval_type,
165  typename Derived::op_type, typename dist_eval_type::policy> impl_type;
166 
167  // Construct left and right distributed evaluators
168  const typename argument_type::dist_eval_type arg = arg_.make_dist_eval();
169 
170  // Construct the distributed evaluator type
171  std::shared_ptr<impl_type> pimpl =
172  std::make_shared<impl_type>(arg, *world_, trange_, shape_, pmap_,
174 
175  return dist_eval_type(pimpl);
176  }
177 
179 
182  void print(ExprOStream os, const VariableList& target_vars) const {
183  ExprEngine_::print(os, target_vars);
184  os.inc();
185  arg_.print(os, vars_);
186  os.dec();
187  }
188 
189  }; // class UnaryEngine
190 
191  } // namespace expressions
192 } // namespace TiledArray
193 
194 #endif // TILEDARRAY_EXPRESSIONS_UNARY_ENGINE_H__INCLUDED
trange_type make_trange() const
Non-permuting tiled range factory function.
Definition: unary_engine.h:150
UnaryEngine(const UnaryExpr< D > &expr)
Definition: unary_engine.h:88
ExprEngine< Derived > ExprEngine_
Base class type.
Definition: unary_engine.h:45
static constexpr unsigned int leaves
Definition: unary_engine.h:64
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
EngineTrait< Derived >::size_type size_type
Size type.
Definition: unary_engine.h:57
World * world() const
World accessor.
Definition: expr_engine.h:194
op_type make_op() const
Tile operation factory function.
Definition: expr_engine.h:178
derived_type & derived()
Cast this object to it&#39;s derived type.
Definition: expr_engine.h:186
argument_type arg_
The argument.
Definition: unary_engine.h:77
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
void perm_vars(const VariableList &target_vars)
Set the variable list for this expression.
Definition: unary_engine.h:101
EngineTrait< Derived >::shape_type shape_type
Shape type.
Definition: unary_engine.h:59
const VariableList & vars() const
Variable list accessor.
Definition: expr_engine.h:199
void init_struct(const VariableList &target_vars)
Initialize result tensor structure.
Definition: expr_engine.h:130
EngineTrait< Derived >::dist_eval_type dist_eval_type
The distributed evaluator type.
Definition: unary_engine.h:54
EngineTrait< ScalEngine< Arg, Scalar, Result > >::trange_type trange_type
Tiled range type type.
Definition: expr_engine.h:55
static constexpr bool consumable
Definition: unary_engine.h:63
Variable list manages a list variable strings.
#define TA_ASSERT(a)
Definition: error.h:107
Tensor that is composed from an argument tensor.
Definition: unary_eval.h:36
EngineTrait< Derived >::trange_type trange_type
Tiled range type.
Definition: unary_engine.h:58
EngineTrait< ScalEngine< Arg, 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
EngineTrait< Derived >::op_type op_type
The tile operation type.
Definition: unary_engine.h:52
dist_eval_type make_dist_eval() const
Construct the distributed evaluator for this expression.
Definition: unary_engine.h:163
EngineTrait< Derived >::policy policy
The result policy type.
Definition: unary_engine.h:53
World * world_
The world where this expression will be evaluated.
Definition: expr_engine.h:63
void inc()
Increment the number of tabs.
Definition: expr_trace.h:70
UnaryEngine< Derived > UnaryEngine_
This class type.
Definition: unary_engine.h:44
EngineTrait< Derived >::pmap_interface pmap_interface
Process map interface type.
Definition: unary_engine.h:60
Permutation of a sequence of objects indexed by base-0 indices.
Definition: permutation.h:119
void init_struct(const VariableList &target_vars)
Initialize result tensor structure.
Definition: unary_engine.h:129
Permutation perm_
The permutation that will be applied to the result.
Definition: expr_engine.h:66
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
EngineTrait< Derived >::value_type value_type
The result tile type.
Definition: unary_engine.h:51
trange_type make_trange(const Permutation &perm) const
Permuting tiled range factory function.
Definition: unary_engine.h:156
void init_distribution(World *world, const std::shared_ptr< pmap_interface > &pmap)
Initialize result tensor distribution.
Definition: unary_engine.h:140
Expression output stream.
Definition: expr_trace.h:39
EngineTrait< Derived >::argument_type argument_type
The argument expression engine type.
Definition: unary_engine.h:48
void init_vars()
Initialize the variable list of this expression.
Definition: unary_engine.h:118
trange_type trange_
The tiled range of the result tensor.
Definition: expr_engine.h:67
void print(ExprOStream os, const VariableList &target_vars) const
Expression print.
Definition: unary_engine.h:182
void print(ExprOStream &os, const VariableList &target_vars) const
Expression print.
Definition: expr_engine.h:230
void init_vars(const VariableList &target_vars)
Initialize the variable list of this expression.
Definition: unary_engine.h:112
void dec()
Decrement the number of tabs.
Definition: expr_trace.h:73