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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 757 - (hide annotations)
Mon Jun 26 13:12:56 2006 UTC (13 years, 4 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 jgs 82 /*
2 elspeth 615 ************************************************************
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 jgs 82 */
13    
14     #if !defined escript_BinaryOp_20040315_H
15     #define escript_BinaryOp_20040315_H
16 woo409 757 #include "system_dep.h"
17 jgs 82
18 jgs 474 #include "DataArrayView.h"
19     #include "DataConstant.h"
20 jgs 478 #include "DataTagged.h"
21 jgs 474 #include "DataExpanded.h"
22 jgs 82
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 jgs 121 \param operation Input - The operation to perform.
30 jgs 82 */
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 jgs 154 // perform the operation on each tagged value
44 jgs 82 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 jgs 122 for (i=lookup.begin();i!=lookupEnd;i++) {
50 jgs 82 leftView.binaryOp(i->second,right(),operation);
51     }
52     } else {
53 jgs 122 for (i=lookup.begin();i!=lookupEnd;i++) {
54 jgs 82 leftView.binaryOp(i->second,right,right.getOffset(),operation);
55     }
56     }
57     //
58     // finally perform the operation on the default value
59 jgs 555 if (right.getRank()==0) {
60     left.getDefaultValue().binaryOp(0,right(),operation);
61     } else {
62     left.getDefaultValue().binaryOp(right,operation);
63     }
64 jgs 82 }
65    
66     template <class BinaryFunction>
67     inline void binaryOp(DataTagged& left, const DataTagged& right,
68     BinaryFunction operation)
69     {
70 gross 697 int right_rank=right.getPointDataView().getRank();
71 jgs 82 //
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 jgs 122 for (i=rightLookup.begin();i!=rightLookupEnd;i++) {
77 jgs 82 //
78 jgs 154 // 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 jgs 543 // the left's default value.
81 jgs 154 if (!left.isCurrentTag(i->first)) {
82 jgs 543 left.addTaggedValue(i->first,left.getDefaultValue());
83 jgs 154 }
84 jgs 82 }
85     //
86 jgs 544 // Perform the operation.
87 jgs 82 const DataTagged::DataMapType& leftLookup=left.getTagLookup();
88     DataTagged::DataMapType::const_iterator leftLookupEnd=leftLookup.end();
89 jgs 122 for (i=leftLookup.begin();i!=leftLookupEnd;i++) {
90 gross 697 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 jgs 82 }
96     //
97     // finally perform the operation on the default value
98 gross 697 if (right_rank==0) {
99     left.getDefaultValue().binaryOp(0,right.getDefaultValue()(),operation);
100     } else {
101     left.getDefaultValue().binaryOp(right.getDefaultValue(),operation);
102     }
103 jgs 82 }
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 jgs 122 left.getPointDataView().binaryOp(right(),operation);
124 jgs 82 } else {
125 jgs 122 left.getPointDataView().binaryOp(right,operation);
126 jgs 82 }
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 jgs 122 #pragma omp parallel for private(i,j) schedule(static)
140     for (i=0;i<numSamples;i++) {
141     for (j=0;j<numDPPSample;j++) {
142 jgs 82 left.getPointDataView().binaryOp(left.getPointOffset(i,j),
143 jgs 122 right.getPointDataView().getData(right.getPointOffset(i,j)),
144     operation);
145 jgs 82 }
146     }
147     } else {
148 jgs 122 #pragma omp parallel for private(i,j) schedule(static)
149     for (i=0;i<numSamples;i++) {
150     for (j=0;j<numDPPSample;j++) {
151 jgs 82 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 jgs 122 #pragma omp parallel for private(i,j) schedule(static)
171     for (i=0;i<numSamples;i++) {
172     for (j=0;j<numDPPSample;j++) {
173 jgs 82 left.getPointDataView().binaryOp(left.getPointOffset(i,j),
174 jgs 122 right(),
175     operation);
176 jgs 82 }
177     }
178     } else {
179 jgs 122 #pragma omp parallel for private(i,j) schedule(static)
180     for (i=0;i<numSamples;i++) {
181     for (j=0;j<numDPPSample;j++) {
182 jgs 82 left.getPointDataView().binaryOp(left.getPointOffset(i,j),
183 jgs 122 right,
184     0,
185 jgs 82 operation);
186     }
187     }
188     }
189     }
190    
191     } // end of namespace
192 jgs 122
193 jgs 82 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26