/[escript]/trunk-mpi-branch/escript/src/BinaryOp.h
ViewVC logotype

Annotation of /trunk-mpi-branch/escript/src/BinaryOp.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 544 - (hide annotations)
Tue Feb 21 01:23:23 2006 UTC (13 years, 7 months ago) by jgs
Original Path: trunk/escript/src/BinaryOp.h
File MIME type: text/plain
File size: 6315 byte(s)
minor comment fixes

1 jgs 82 /*
2     ******************************************************************************
3     * *
4     * COPYRIGHT ACcESS 2004 - All Rights Reserved *
5     * *
6     * This software is the property of ACcESS. No part of this code *
7     * may be copied in any form or by any means without the expressed written *
8     * consent of ACcESS. Copying, use or modification of this software *
9     * by any unauthorised person is illegal unless that person has a software *
10     * license agreement with ACcESS. *
11     * *
12     ******************************************************************************
13     */
14    
15     #if !defined escript_BinaryOp_20040315_H
16     #define escript_BinaryOp_20040315_H
17    
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     //
36     // perform the operation on each tagged value including the default
37     binaryOp(left,right.getPointDataView(),operation);
38     }
39    
40     template <class BinaryFunction>
41     inline void binaryOp(DataTagged& left, const DataArrayView& right,
42     BinaryFunction operation)
43     {
44     //
45 jgs 154 // perform the operation on each tagged value
46 jgs 82 const DataTagged::DataMapType& lookup=left.getTagLookup();
47     DataTagged::DataMapType::const_iterator i;
48     DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();
49     DataArrayView& leftView=left.getPointDataView();
50     if (right.getRank()==0) {
51 jgs 122 for (i=lookup.begin();i!=lookupEnd;i++) {
52 jgs 82 leftView.binaryOp(i->second,right(),operation);
53     }
54     } else {
55 jgs 122 for (i=lookup.begin();i!=lookupEnd;i++) {
56 jgs 82 leftView.binaryOp(i->second,right,right.getOffset(),operation);
57     }
58     }
59     //
60     // finally perform the operation on the default value
61     left.getDefaultValue().binaryOp(right,operation);
62     }
63    
64     template <class BinaryFunction>
65     inline void binaryOp(DataTagged& left, const DataTagged& right,
66     BinaryFunction operation)
67     {
68     //
69     // Add the right hand tag keys which can't currently be found on the left
70     const DataTagged::DataMapType& rightLookup=right.getTagLookup();
71     DataTagged::DataMapType::const_iterator i;
72     DataTagged::DataMapType::const_iterator rightLookupEnd=rightLookup.end();
73 jgs 122 for (i=rightLookup.begin();i!=rightLookupEnd;i++) {
74 jgs 82 //
75 jgs 154 // If the left does not already have a value assigned to this tag,
76     // add the right hand tag to the left hand tag list and assign
77 jgs 543 // the left's default value.
78 jgs 154 if (!left.isCurrentTag(i->first)) {
79 jgs 543 left.addTaggedValue(i->first,left.getDefaultValue());
80 jgs 154 }
81 jgs 82 }
82     //
83 jgs 544 // Perform the operation.
84 jgs 82 const DataTagged::DataMapType& leftLookup=left.getTagLookup();
85     DataTagged::DataMapType::const_iterator leftLookupEnd=leftLookup.end();
86 jgs 122 for (i=leftLookup.begin();i!=leftLookupEnd;i++) {
87     left.getDataPointByTag(i->first).binaryOp(right.getDataPointByTag(i->first),operation);
88 jgs 82 }
89     //
90     // finally perform the operation on the default value
91     left.getDefaultValue().binaryOp(right.getDefaultValue(),operation);
92     }
93    
94     template <class BinaryFunction>
95     inline void binaryOp(DataConstant& left, const DataConstant& right,
96     BinaryFunction operation)
97     {
98     //
99     // As DataConstant there is only one point data
100     binaryOp(left,right.getPointDataView(),operation);
101     }
102    
103     template <class BinaryFunction>
104     inline void binaryOp(DataConstant& left, const DataArrayView& right,
105     BinaryFunction operation)
106     {
107     //
108     // perform an operand check, this will throw on error
109     if (right.getRank()==0) {
110     //
111     // special case of applying a single value to the entire array
112 jgs 122 left.getPointDataView().binaryOp(right(),operation);
113 jgs 82 } else {
114 jgs 122 left.getPointDataView().binaryOp(right,operation);
115 jgs 82 }
116     }
117    
118     template <class BinaryFunction>
119     inline void binaryOp(DataExpanded& left, const DataAbstract& right,
120     BinaryFunction operation)
121     {
122     int i,j;
123     DataArrayView::ValueType::size_type numDPPSample=left.getNumDPPSample();
124     DataArrayView::ValueType::size_type numSamples=left.getNumSamples();
125     if (right.getPointDataView().getRank()==0) {
126     //
127     // This will call the double version of binaryOp
128 jgs 122 #pragma omp parallel for private(i,j) schedule(static)
129     for (i=0;i<numSamples;i++) {
130     for (j=0;j<numDPPSample;j++) {
131 jgs 82 left.getPointDataView().binaryOp(left.getPointOffset(i,j),
132 jgs 122 right.getPointDataView().getData(right.getPointOffset(i,j)),
133     operation);
134 jgs 82 }
135     }
136     } else {
137 jgs 122 #pragma omp parallel for private(i,j) schedule(static)
138     for (i=0;i<numSamples;i++) {
139     for (j=0;j<numDPPSample;j++) {
140 jgs 82 left.getPointDataView().binaryOp(left.getPointOffset(i,j),
141     right.getPointDataView(),
142     right.getPointOffset(i,j),
143     operation);
144     }
145     }
146     }
147     }
148    
149     template <class BinaryFunction>
150     inline void binaryOp(DataExpanded& left, const DataArrayView& right,
151     BinaryFunction operation)
152     {
153     int i,j;
154     DataArrayView::ValueType::size_type numDPPSample=left.getNumDPPSample();
155     DataArrayView::ValueType::size_type numSamples=left.getNumSamples();
156     if (right.getRank()==0) {
157     //
158     // This will call the double version of binaryOp
159 jgs 122 #pragma omp parallel for private(i,j) schedule(static)
160     for (i=0;i<numSamples;i++) {
161     for (j=0;j<numDPPSample;j++) {
162 jgs 82 left.getPointDataView().binaryOp(left.getPointOffset(i,j),
163 jgs 122 right(),
164     operation);
165 jgs 82 }
166     }
167     } else {
168 jgs 122 #pragma omp parallel for private(i,j) schedule(static)
169     for (i=0;i<numSamples;i++) {
170     for (j=0;j<numDPPSample;j++) {
171 jgs 82 left.getPointDataView().binaryOp(left.getPointOffset(i,j),
172 jgs 122 right,
173     0,
174 jgs 82 operation);
175     }
176     }
177     }
178     }
179    
180     } // end of namespace
181 jgs 122
182 jgs 82 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26