/[escript]/trunk/escript/src/BinaryOp.h
ViewVC logotype

Contents of /trunk/escript/src/BinaryOp.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 757 - (show annotations)
Mon Jun 26 13:12:56 2006 UTC (13 years, 2 months ago) by woo409
File MIME type: text/plain
File size: 6371 byte(s)
+ Merge of intelc_win32 branch (revision 741:755) with trunk. Tested on iVEC altix (run_tests and py_tests all pass)

1 /*
2 ************************************************************
3 * Copyright 2006 by ACcESS MNRF *
4 * *
5 * http://www.access.edu.au *
6 * Primary Business: Queensland, Australia *
7 * Licensed under the Open Software License version 3.0 *
8 * http://www.opensource.org/licenses/osl-3.0.php *
9 * *
10 ************************************************************
11
12 */
13
14 #if !defined escript_BinaryOp_20040315_H
15 #define escript_BinaryOp_20040315_H
16 #include "system_dep.h"
17
18 #include "DataArrayView.h"
19 #include "DataConstant.h"
20 #include "DataTagged.h"
21 #include "DataExpanded.h"
22
23 namespace escript {
24 /**
25 \brief
26 Perform the given binary operation.
27 \param left Input/Output - The left hand side.
28 \param right Input - The right hand side.
29 \param operation Input - The operation to perform.
30 */
31 template <class BinaryFunction>
32 inline void binaryOp(DataTagged& left, const DataConstant& right,
33 BinaryFunction operation)
34 {
35 binaryOp(left,right.getPointDataView(),operation);
36 }
37
38 template <class BinaryFunction>
39 inline void binaryOp(DataTagged& left, const DataArrayView& right,
40 BinaryFunction operation)
41 {
42 //
43 // perform the operation on each tagged value
44 const DataTagged::DataMapType& lookup=left.getTagLookup();
45 DataTagged::DataMapType::const_iterator i;
46 DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();
47 DataArrayView& leftView=left.getPointDataView();
48 if (right.getRank()==0) {
49 for (i=lookup.begin();i!=lookupEnd;i++) {
50 leftView.binaryOp(i->second,right(),operation);
51 }
52 } else {
53 for (i=lookup.begin();i!=lookupEnd;i++) {
54 leftView.binaryOp(i->second,right,right.getOffset(),operation);
55 }
56 }
57 //
58 // finally perform the operation on the default value
59 if (right.getRank()==0) {
60 left.getDefaultValue().binaryOp(0,right(),operation);
61 } else {
62 left.getDefaultValue().binaryOp(right,operation);
63 }
64 }
65
66 template <class BinaryFunction>
67 inline void binaryOp(DataTagged& left, const DataTagged& right,
68 BinaryFunction operation)
69 {
70 int right_rank=right.getPointDataView().getRank();
71 //
72 // Add the right hand tag keys which can't currently be found on the left
73 const DataTagged::DataMapType& rightLookup=right.getTagLookup();
74 DataTagged::DataMapType::const_iterator i;
75 DataTagged::DataMapType::const_iterator rightLookupEnd=rightLookup.end();
76 for (i=rightLookup.begin();i!=rightLookupEnd;i++) {
77 //
78 // If the left does not already have a value assigned to this tag,
79 // add the right hand tag to the left hand tag list and assign
80 // the left's default value.
81 if (!left.isCurrentTag(i->first)) {
82 left.addTaggedValue(i->first,left.getDefaultValue());
83 }
84 }
85 //
86 // Perform the operation.
87 const DataTagged::DataMapType& leftLookup=left.getTagLookup();
88 DataTagged::DataMapType::const_iterator leftLookupEnd=leftLookup.end();
89 for (i=leftLookup.begin();i!=leftLookupEnd;i++) {
90 if (right_rank==0) {
91 left.getDataPointByTag(i->first).binaryOp(i->second,right.getDataPointByTag(i->first)(),operation);
92 } else {
93 left.getDataPointByTag(i->first).binaryOp(right.getDataPointByTag(i->first),operation);
94 }
95 }
96 //
97 // finally perform the operation on the default value
98 if (right_rank==0) {
99 left.getDefaultValue().binaryOp(0,right.getDefaultValue()(),operation);
100 } else {
101 left.getDefaultValue().binaryOp(right.getDefaultValue(),operation);
102 }
103 }
104
105 template <class BinaryFunction>
106 inline void binaryOp(DataConstant& left, const DataConstant& right,
107 BinaryFunction operation)
108 {
109 //
110 // As DataConstant there is only one point data
111 binaryOp(left,right.getPointDataView(),operation);
112 }
113
114 template <class BinaryFunction>
115 inline void binaryOp(DataConstant& left, const DataArrayView& right,
116 BinaryFunction operation)
117 {
118 //
119 // perform an operand check, this will throw on error
120 if (right.getRank()==0) {
121 //
122 // special case of applying a single value to the entire array
123 left.getPointDataView().binaryOp(right(),operation);
124 } else {
125 left.getPointDataView().binaryOp(right,operation);
126 }
127 }
128
129 template <class BinaryFunction>
130 inline void binaryOp(DataExpanded& left, const DataAbstract& right,
131 BinaryFunction operation)
132 {
133 int i,j;
134 DataArrayView::ValueType::size_type numDPPSample=left.getNumDPPSample();
135 DataArrayView::ValueType::size_type numSamples=left.getNumSamples();
136 if (right.getPointDataView().getRank()==0) {
137 //
138 // This will call the double version of binaryOp
139 #pragma omp parallel for private(i,j) schedule(static)
140 for (i=0;i<numSamples;i++) {
141 for (j=0;j<numDPPSample;j++) {
142 left.getPointDataView().binaryOp(left.getPointOffset(i,j),
143 right.getPointDataView().getData(right.getPointOffset(i,j)),
144 operation);
145 }
146 }
147 } else {
148 #pragma omp parallel for private(i,j) schedule(static)
149 for (i=0;i<numSamples;i++) {
150 for (j=0;j<numDPPSample;j++) {
151 left.getPointDataView().binaryOp(left.getPointOffset(i,j),
152 right.getPointDataView(),
153 right.getPointOffset(i,j),
154 operation);
155 }
156 }
157 }
158 }
159
160 template <class BinaryFunction>
161 inline void binaryOp(DataExpanded& left, const DataArrayView& right,
162 BinaryFunction operation)
163 {
164 int i,j;
165 DataArrayView::ValueType::size_type numDPPSample=left.getNumDPPSample();
166 DataArrayView::ValueType::size_type numSamples=left.getNumSamples();
167 if (right.getRank()==0) {
168 //
169 // This will call the double version of binaryOp
170 #pragma omp parallel for private(i,j) schedule(static)
171 for (i=0;i<numSamples;i++) {
172 for (j=0;j<numDPPSample;j++) {
173 left.getPointDataView().binaryOp(left.getPointOffset(i,j),
174 right(),
175 operation);
176 }
177 }
178 } else {
179 #pragma omp parallel for private(i,j) schedule(static)
180 for (i=0;i<numSamples;i++) {
181 for (j=0;j<numDPPSample;j++) {
182 left.getPointDataView().binaryOp(left.getPointOffset(i,j),
183 right,
184 0,
185 operation);
186 }
187 }
188 }
189 }
190
191 } // end of namespace
192
193 #endif

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26