OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
Assign.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 #ifndef ASSIGN_H
12 #define ASSIGN_H
13 
14 // include files
15 #include "PETE/IpplExpressions.h"
16 #include <complex>
17 
18 // forward declarations
19 template<class T, unsigned Dim> class BareField;
20 template<class T, unsigned Dim> class LField;
21 template<class T, unsigned Dim, unsigned Brackets> class IndexedBareField;
22 
23 // a debugging output message macro for assign functions. This is
24 // only enabled if you specificall add -DDEBUG_ASSIGN somewhere.
25 #ifdef DEBUG_ASSIGN
26 #define ASSIGNMSG(x) x
27 #else
28 #define ASSIGNMSG(x)
29 #endif
30 
31 
33 //
34 // Currently, some of the assignment algorithms depend
35 // on knowing that there is just one Field on the rhs.
36 // We detect these here by building a simple tag class ExprTag
37 // that has a bool template argument. The arg is true
38 // if the the assign should deal with general expressions,
39 // and false if it can use the special purpose single field version.
40 //
41 // This wouldn't be needed if we had partial specialization,
42 // but this will disambiguate expressions even without it.
43 //
45 
46 template <bool IsExpr>
47 class ExprTag
48 {
49 };
50 
52 
53 // BareField = Expression
54 template<class T, unsigned Dim, class RHS, class OP>
55 void
56 assign(const BareField<T,Dim>& a, RHS b, OP op, ExprTag<true>);
57 
58 // IndexedBareField = Expression
59 template<class T1, unsigned Dim, class RHS, class OP>
60 void
62  bool fillGC); // tjw added fillGC 12/16/1997 new BC hack
63 
64 // IndexedBareField = Expression
65 template<class T1, unsigned Dim, class RHS, class OP>
66 inline void
68  assign(a, b, op, et, true);
69 }
70 
71 // Component = Expression
72 template<class A, class RHS, class OP, class Tag, class TP>
73 void
74 assign(PETE_TUTree<OpParens<TP>,A> lhs, RHS rhs, OP op, Tag,
75  bool fillGC=true); // tjw added fillGC 12/16/1997 new BC hack
76 
77 // BareField = BareField, with communication.
78 template<class T1, unsigned D1, class RHS, class Op>
79 void
80 assign(const BareField<T1,D1>& lhs, RHS rhs, Op op, ExprTag<false>);
81 
82 // IndexedBareField = IndexedBareField, different dimensions.
83 template<class T1, unsigned D1, class RHS, class Op>
84 void
86 
88 
89 // Expression = constant;
90 template<class T, unsigned D, class OP>
91 inline void
93 {
95 }
96 
97 template<class T, unsigned D, class OP>
98 inline void
100 {
101  assign(a, PETE_Scalar<T>(b), op, ExprTag<true>());
102 }
103 
105 
106 template<class T> struct IsExprTrait { enum { IsExpr = T::IsExpr } ; };
107 template<> struct IsExprTrait<double> { enum { IsExpr = 1 }; };
108 template<> struct IsExprTrait<std::complex<double>> { enum { IsExpr = 1 }; };
109 template<> struct IsExprTrait<float> { enum { IsExpr = 1 }; };
110 template<> struct IsExprTrait<short> { enum { IsExpr = 1 }; };
111 template<> struct IsExprTrait<int> { enum { IsExpr = 1 }; };
112 template<> struct IsExprTrait<long> { enum { IsExpr = 1 }; };
113 template<> struct IsExprTrait<Index> { enum { IsExpr = 1 }; };
114 
115 #define ASSIGNMENT_OPERATORS(FUNC,OP) \
116  \
117 template<class LHS, class RHS> \
118 inline void \
119 FUNC(const PETE_Expr<LHS>& lhs, const PETE_Expr<RHS>& rhs) \
120 { \
121  assign(lhs.PETE_unwrap(), rhs.PETE_unwrap().MakeExpression(), \
122  OP(),ExprTag< IsExprTrait<RHS>::IsExpr >()); \
123 } \
124  \
125 template<class T, unsigned D> \
126 inline void \
127 FUNC(const IndexedBareField<T,D,D>& lhs, const T& rhs) \
128 { \
129  assign(lhs,PETE_Scalar<T>(rhs), OP(),ExprTag<true>(),true); \
130 } \
131  \
132 template<class T, unsigned D> \
133 inline void \
134 FUNC(const BareField<T,D>& lhs, const T& rhs) \
135 { \
136  assign(lhs,PETE_Scalar<T>(rhs),OP(),ExprTag<true>()); \
137 } \
138  \
139 template<class A, class TP> \
140 inline void \
141 FUNC(const PETE_TUTree<OpParens<TP>,A>& lhs, const bool& rhs) \
142 { \
143  assign(lhs,PETE_Scalar<bool>(rhs),OP(),ExprTag<true>()); \
144 } \
145 template<class A, class TP> \
146 inline void \
147 FUNC(const PETE_TUTree<OpParens<TP>,A>& lhs, const char& rhs) \
148 { \
149  assign(lhs,PETE_Scalar<char>(rhs),OP(),ExprTag<true>()); \
150 } \
151 template<class A, class TP> \
152 inline void \
153 FUNC(const PETE_TUTree<OpParens<TP>,A>& lhs, const int& rhs) \
154 { \
155  assign(lhs,PETE_Scalar<int>(rhs),OP(),ExprTag<true>()); \
156 } \
157 template<class A,class TP> \
158 inline void \
159 FUNC(const PETE_TUTree<OpParens<TP>,A>& lhs, const float& rhs) \
160 { \
161  assign(lhs,PETE_Scalar<float>(rhs),OP(),ExprTag<true>()); \
162 } \
163 template<class A, class TP> \
164 inline void \
165 FUNC(const PETE_TUTree<OpParens<TP>,A>& lhs, const double& rhs) \
166 { \
167  assign(lhs,PETE_Scalar<double>(rhs),OP(),ExprTag<true>()); \
168 } \
169 template<class A, class TP> \
170 inline void \
171 FUNC(const PETE_TUTree<OpParens<TP>,A>& lhs, const std::complex<double>& rhs)\
172 { \
173  assign(lhs,PETE_Scalar<std::complex<double>>(rhs),OP(),ExprTag<true>()); \
174 }
175 
184 
185 
186 // Determine whether to compress or uncompress the
187 // left hand side given information about the expression.
188 // This prototype is defined here because the SubField assignment
189 // files need this functionality as well.
190 template<class T, unsigned Dim, class A, class Op>
191 bool TryCompressLHS(LField<T,Dim>&, A&, Op, const NDIndex<Dim>&);
192 
193 
194 // Include the .cpp function definitions.
195 #include "Field/Assign.hpp"
196 #include "Field/AssignGeneralBF.hpp"
198 
199 #endif // ASSIGN_H
200 
201 /***************************************************************************
202  * $RCSfile: Assign.h,v $ $Author: adelmann $
203  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:26 $
204  * IPPL_VERSION_ID: $Id: Assign.h,v 1.1.1.1 2003/01/23 07:40:26 adelmann Exp $
205  ***************************************************************************/
const unsigned Dim
void mineq(const PETE_Expr< LHS > &lhs, const PETE_Expr< RHS > &rhs)
Definition: Assign.h:182
void assign(const BareField< T, Dim > &a, RHS b, OP op, ExprTag< true >)
void maxeq(const PETE_Expr< LHS > &lhs, const PETE_Expr< RHS > &rhs)
Definition: Assign.h:183
#define ASSIGNMENT_OPERATORS(FUNC, OP)
Definition: Assign.h:115
bool TryCompressLHS(LField< T, Dim > &, A &, Op, const NDIndex< Dim > &)
Definition: Assign.hpp:48
std::complex< double > a
MMatrix< m_complex > complex(MMatrix< double > real)
Definition: MMatrix.cpp:396
Definition: LField.h:58
Definition: Assign.h:48
Definition: Index.h:237