OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
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 "AppTypes/dcomplex.h"
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 #ifdef IPPL_PURIFY
50 public:
51  ExprTag() {}
52  ExprTag(const ExprTag<IsExpr> &) {}
53  ExprTag<IsExpr>& operator=(const ExprTag<IsExpr> &) { return *this; }
54 #endif
55 };
56 
58 
59 // BareField = Expression
60 template<class T, unsigned Dim, class RHS, class OP>
61 void
62 assign(const BareField<T,Dim>& a, RHS b, OP op, ExprTag<true>);
63 
64 // IndexedBareField = Expression
65 template<class T1, unsigned Dim, class RHS, class OP>
66 void
67 assign(const IndexedBareField<T1,Dim,Dim> &a, RHS b, OP op, ExprTag<true>,
68  bool fillGC); // tjw added fillGC 12/16/1997 new BC hack
69 
70 // IndexedBareField = Expression
71 template<class T1, unsigned Dim, class RHS, class OP>
72 inline void
73 assign(const IndexedBareField<T1,Dim,Dim> &a, RHS b, OP op, ExprTag<true> et) {
74  assign(a, b, op, et, true);
75 }
76 
77 #ifdef __MWERKS__
78 // Work around CodeWarrior 4.0 bug
79 // Component = Expression
80 template<class A, class RHS, class OP, class Tag, class TP>
81 void
82 assign(PETE_TUTree<OpParens<TP>,A> lhs, RHS rhs, OP op, Tag tag) {
83  assign(lhs, rhs, op, tag, true);
84 }
85 
86 // Component = Expression
87 template<class A, class RHS, class OP, class Tag, class TP>
88 void
89 assign(PETE_TUTree<OpParens<TP>,A> lhs, RHS rhs, OP op, Tag,
90  bool fillGC); // tjw added fillGC 12/16/1997 new BC hack
91 
92 #else
93 // Component = Expression
94 template<class A, class RHS, class OP, class Tag, class TP>
95 void
96 assign(PETE_TUTree<OpParens<TP>,A> lhs, RHS rhs, OP op, Tag,
97  bool fillGC=true); // tjw added fillGC 12/16/1997 new BC hack
98 #endif // __MWERKS__
99 
100 // BareField = BareField, with communication.
101 template<class T1, unsigned D1, class RHS, class Op>
102 void
103 assign(const BareField<T1,D1>& lhs, RHS rhs, Op op, ExprTag<false>);
104 
105 // IndexedBareField = IndexedBareField, different dimensions.
106 template<class T1, unsigned D1, class RHS, class Op>
107 void
109 
111 
112 // Expression = constant;
113 template<class T, unsigned D, class OP>
114 inline void
115 assign(BareField<T,D>& a,const T& b, OP op, ExprTag<true>)
116 {
117  assign(a, PETE_Scalar<T>(b), op, ExprTag<true>());
118 }
119 
120 template<class T, unsigned D, class OP>
121 inline void
123 {
124  assign(a, PETE_Scalar<T>(b), op, ExprTag<true>());
125 }
126 
128 
129 template<class T> struct IsExprTrait { enum { IsExpr = T::IsExpr } ; };
130 template<> struct IsExprTrait<double> { enum { IsExpr = 1 }; };
131 template<> struct IsExprTrait<dcomplex> { enum { IsExpr = 1 }; };
132 template<> struct IsExprTrait<float> { enum { IsExpr = 1 }; };
133 template<> struct IsExprTrait<short> { enum { IsExpr = 1 }; };
134 template<> struct IsExprTrait<int> { enum { IsExpr = 1 }; };
135 template<> struct IsExprTrait<long> { enum { IsExpr = 1 }; };
136 template<> struct IsExprTrait<Index> { enum { IsExpr = 1 }; };
137 
138 #define ASSIGNMENT_OPERATORS(FUNC,OP) \
139  \
140 template<class LHS, class RHS> \
141 inline void \
142 FUNC(const PETE_Expr<LHS>& lhs, const PETE_Expr<RHS>& rhs) \
143 { \
144  assign(lhs.PETE_unwrap(), rhs.PETE_unwrap().MakeExpression(), \
145  OP(),ExprTag< IsExprTrait<RHS>::IsExpr >()); \
146 } \
147  \
148 template<class T, unsigned D> \
149 inline void \
150 FUNC(const IndexedBareField<T,D,D>& lhs, const T& rhs) \
151 { \
152  assign(lhs,PETE_Scalar<T>(rhs), OP(),ExprTag<true>(),true); \
153 } \
154  \
155 template<class T, unsigned D> \
156 inline void \
157 FUNC(const BareField<T,D>& lhs, const T& rhs) \
158 { \
159  assign(lhs,PETE_Scalar<T>(rhs),OP(),ExprTag<true>()); \
160 } \
161  \
162 template<class A, class TP> \
163 inline void \
164 FUNC(const PETE_TUTree<OpParens<TP>,A>& lhs, const bool& rhs) \
165 { \
166  assign(lhs,PETE_Scalar<bool>(rhs),OP(),ExprTag<true>()); \
167 } \
168 template<class A, class TP> \
169 inline void \
170 FUNC(const PETE_TUTree<OpParens<TP>,A>& lhs, const char& rhs) \
171 { \
172  assign(lhs,PETE_Scalar<char>(rhs),OP(),ExprTag<true>()); \
173 } \
174 template<class A, class TP> \
175 inline void \
176 FUNC(const PETE_TUTree<OpParens<TP>,A>& lhs, const int& rhs) \
177 { \
178  assign(lhs,PETE_Scalar<int>(rhs),OP(),ExprTag<true>()); \
179 } \
180 template<class A,class TP> \
181 inline void \
182 FUNC(const PETE_TUTree<OpParens<TP>,A>& lhs, const float& rhs) \
183 { \
184  assign(lhs,PETE_Scalar<float>(rhs),OP(),ExprTag<true>()); \
185 } \
186 template<class A, class TP> \
187 inline void \
188 FUNC(const PETE_TUTree<OpParens<TP>,A>& lhs, const double& rhs) \
189 { \
190  assign(lhs,PETE_Scalar<double>(rhs),OP(),ExprTag<true>()); \
191 } \
192 template<class A, class TP> \
193 inline void \
194 FUNC(const PETE_TUTree<OpParens<TP>,A>& lhs, const dcomplex& rhs)\
195 { \
196  assign(lhs,PETE_Scalar<dcomplex>(rhs),OP(),ExprTag<true>()); \
197 }
198 
199 #ifdef UNDEFINED
200 
201 template<class LHS> \
202 inline void \
203 FUNC(const PETE_Expr<LHS>& lhs, double rhs) \
204 { \
205  assign(lhs.PETE_unwrap(),PETE_Scalar<double>(rhs),OP(),ExprTag<true>()); \
206 } \
207  \
208 template<class LHS> \
209 inline void \
210 FUNC(const PETE_Expr<LHS>& lhs, float rhs) \
211 { \
212  assign(lhs.PETE_unwrap(),PETE_Scalar<float>(rhs),OP(),ExprTag<true>()); \
213 } \
214  \
215 template<class LHS> \
216 inline void \
217 FUNC(const PETE_Expr<LHS>& lhs, int rhs) \
218 { \
219  assign(lhs.PETE_unwrap(),PETE_Scalar<int>(rhs),OP(),ExprTag<true>()); \
220 }
221 
222 #endif
223 
232 
233 
234 // Determine whether to compress or uncompress the
235 // left hand side given information about the expression.
236 // This prototype is defined here because the SubField assignment
237 // files need this functionality as well.
238 template<class T, unsigned Dim, class A, class Op>
239 bool TryCompressLHS(LField<T,Dim>&, A&, Op, const NDIndex<Dim>&);
240 
241 
242 // Include the .cpp function definitions.
243 #include "Field/Assign.hpp"
244 #include "Field/AssignGeneralBF.hpp"
246 
247 #endif // ASSIGN_H
248 
249 /***************************************************************************
250  * $RCSfile: Assign.h,v $ $Author: adelmann $
251  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:26 $
252  * IPPL_VERSION_ID: $Id: Assign.h,v 1.1.1.1 2003/01/23 07:40:26 adelmann Exp $
253  ***************************************************************************/
Definition: PETE.h:80
void mineq(const PETE_Expr< LHS > &lhs, const PETE_Expr< RHS > &rhs)
Definition: Assign.h:230
Definition: Assign.h:47
void maxeq(const PETE_Expr< LHS > &lhs, const PETE_Expr< RHS > &rhs)
Definition: Assign.h:231
Definition: rbendmap.h:8
Definition: FFT.h:31
std::complex< double > dcomplex
Definition: dcomplex.h:30
void assign(const BareField< T, Dim > &a, RHS b, OP op, ExprTag< true >)
#define FUNC(x)
Definition: integrate.cpp:35
Definition: Index.h:236
#define ASSIGNMENT_OPERATORS(FUNC, OP)
Definition: Assign.h:138
Definition: FFT.h:30
bool TryCompressLHS(LField< T, Dim > &, A &, Op, const NDIndex< Dim > &)
Definition: Assign.hpp:67
const unsigned Dim