/[escript]/branches/arrayview_from_1695_trunk/escript/src/DataAlgorithm.h
ViewVC logotype

Diff of /branches/arrayview_from_1695_trunk/escript/src/DataAlgorithm.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1723 by jfenwick, Mon Aug 11 03:33:40 2008 UTC revision 1724 by jfenwick, Mon Aug 25 05:38:57 2008 UTC
# Line 22  Line 22 
22  #include "DataTagged.h"  #include "DataTagged.h"
23  #include "DataConstant.h"  #include "DataConstant.h"
24    
25    #include "DataMaths.h"
26    
27  #include <iostream>  #include <iostream>
28  #include <algorithm>  #include <algorithm>
29    
# Line 167  algorithm(DataExpanded& data, Line 169  algorithm(DataExpanded& data,
169    int numSamples=data.getNumSamples();    int numSamples=data.getNumSamples();
170    double global_current_value=initial_value;    double global_current_value=initial_value;
171    double local_current_value;    double local_current_value;
172    DataArrayView dataView=data.getPointDataView();  //  DataArrayView dataView=data.getPointDataView();
173      DataTypes::ValueType& vec=data.getVector();
174      const DataTypes::ShapeType& shape=data.getShape();
175    // calculate the reduction operation value for each data point    // calculate the reduction operation value for each data point
176    // reducing the result for each data-point into the current_value variables    // reducing the result for each data-point into the current_value variables
177    #pragma omp parallel private(local_current_value)    #pragma omp parallel private(local_current_value)
# Line 176  algorithm(DataExpanded& data, Line 180  algorithm(DataExpanded& data,
180        #pragma omp for private(i,j) schedule(static)        #pragma omp for private(i,j) schedule(static)
181        for (i=0;i<numSamples;i++) {        for (i=0;i<numSamples;i++) {
182          for (j=0;j<numDPPSample;j++) {          for (j=0;j<numDPPSample;j++) {
183            local_current_value=operation(local_current_value,dataView.reductionOp(data.getPointOffset(i,j),operation,initial_value));  /*          local_current_value=operation(local_current_value,dataView.reductionOp(data.getPointOffset(i,j),operation,initial_value));*/
184              local_current_value=operation(local_current_value,DataMaths::reductionOp(vec,shape,data.getPointOffset(i,j),operation,initial_value));
185    
186          }          }
187        }        }
188        #pragma omp critical        #pragma omp critical
# Line 193  algorithm(DataTagged& data, Line 199  algorithm(DataTagged& data,
199        double initial_value)        double initial_value)
200  {  {
201    double current_value=initial_value;    double current_value=initial_value;
202    
203    // double current_value2=initial_value;
204    
205    // perform the operation on each tagged value    // perform the operation on each tagged value
206    DataArrayView& dataView=data.getPointDataView();  //   DataArrayView& dataView=data.getPointDataView();
207      DataTypes::ValueType& vec=data.getVector();
208      const DataTypes::ShapeType& shape=data.getShape();
209    const DataTagged::DataMapType& lookup=data.getTagLookup();    const DataTagged::DataMapType& lookup=data.getTagLookup();
210    for (DataTagged::DataMapType::const_iterator i=lookup.begin(); i!=lookup.end(); i++) {    for (DataTagged::DataMapType::const_iterator i=lookup.begin(); i!=lookup.end(); i++) {
211      current_value=operation(current_value,dataView.reductionOp(i->second,operation,initial_value));  
212    // current_value2=operation(current_value2,dataView.reductionOp(i->second,operation,initial_value));
213    
214        current_value=operation(current_value,DataMaths::reductionOp(vec,shape,i->second,operation,initial_value));
215    
216    //std::cout << "binalg: value2=" << current_value2 << " value=" << current_value << " diff=" << current_value2-current_value << std::endl;
217    
218    }    }
219    
220    
221    // perform the operation on the default value    // perform the operation on the default value
222    current_value=operation(current_value,data.getDefaultValue().reductionOp(operation,initial_value));  // current_value2=operation(current_value2,data.getDefaultValue().reductionOp(operation,initial_value));
223      // the 0 comes from the default value being the first one in the structure
224      current_value=operation(current_value,DataMaths::reductionOp(vec,shape,data.getDefaultOffset(),operation,initial_value));
225    
226    return current_value;    return current_value;
227  }  }
228    
# Line 211  algorithm(DataConstant& data, Line 233  algorithm(DataConstant& data,
233            BinaryFunction operation,            BinaryFunction operation,
234        double initial_value)        double initial_value)
235  {  {
236    return data.getPointDataView().reductionOp(operation,initial_value);    return DataMaths::reductionOp(data.getVector(),data.getShape(),0,operation,initial_value);
237    //  return data.getPointDataView().reductionOp(operation,initial_value);
238  }  }
239    
240  /**  /**
# Line 228  algorithm(DataConstant& data, Line 251  algorithm(DataConstant& data,
251  template <class BinaryFunction>  template <class BinaryFunction>
252  inline  inline
253  void  void
254  dp_algorithm(DataExpanded& data,  dp_algorithm(const DataExpanded& data,
255               DataExpanded& result,               DataExpanded& result,
256               BinaryFunction operation,               BinaryFunction operation,
257           double initial_value)           double initial_value)
# Line 236  dp_algorithm(DataExpanded& data, Line 259  dp_algorithm(DataExpanded& data,
259    int i,j;    int i,j;
260    int numSamples=data.getNumSamples();    int numSamples=data.getNumSamples();
261    int numDPPSample=data.getNumDPPSample();    int numDPPSample=data.getNumDPPSample();
262    DataArrayView dataView=data.getPointDataView();  //  DataArrayView dataView=data.getPointDataView();
263    DataArrayView resultView=result.getPointDataView();  //  DataArrayView resultView=result.getPointDataView();
264      const DataTypes::ValueType& dataVec=data.getVector();
265      const DataTypes::ShapeType& shape=data.getShape();
266      DataTypes::ValueType& resultVec=result.getVector();
267    // perform the operation on each data-point and assign    // perform the operation on each data-point and assign
268    // this to the corresponding element in result    // this to the corresponding element in result
269    #pragma omp parallel for private(i,j) schedule(static)    #pragma omp parallel for private(i,j) schedule(static)
270    for (i=0;i<numSamples;i++) {    for (i=0;i<numSamples;i++) {
271      for (j=0;j<numDPPSample;j++) {      for (j=0;j<numDPPSample;j++) {
272        resultView.getData(result.getPointOffset(i,j)) =  /*      resultView.getData(result.getPointOffset(i,j)) =
273          dataView.reductionOp(data.getPointOffset(i,j),operation,initial_value);          dataView.reductionOp(data.getPointOffset(i,j),operation,initial_value);*/
274          resultVec[result.getPointOffset(i,j)] =
275            DataMaths::reductionOp(dataVec, shape, data.getPointOffset(i,j),operation,initial_value);
276    
277      }      }
278    }    }
279  }  }
# Line 252  dp_algorithm(DataExpanded& data, Line 281  dp_algorithm(DataExpanded& data,
281  template <class BinaryFunction>  template <class BinaryFunction>
282  inline  inline
283  void  void
284  dp_algorithm(DataTagged& data,  dp_algorithm(const DataTagged& data,
285               DataTagged& result,               DataTagged& result,
286               BinaryFunction operation,               BinaryFunction operation,
287           double initial_value)           double initial_value)
288  {  {
289    // perform the operation on each tagged value in data    // perform the operation on each tagged value in data
290    // and assign this to the corresponding element in result    // and assign this to the corresponding element in result
291      const DataTypes::ShapeType& shape=data.getShape();
292      const DataTypes::ValueType& vec=data.getVector();
293    const DataTagged::DataMapType& lookup=data.getTagLookup();    const DataTagged::DataMapType& lookup=data.getTagLookup();
294    for (DataTagged::DataMapType::const_iterator i=lookup.begin(); i!=lookup.end(); i++) {    for (DataTagged::DataMapType::const_iterator i=lookup.begin(); i!=lookup.end(); i++) {
295      result.getDataPointByTag(i->first).getData(0) =  //     result.getDataPointByTag(i->first).getData(0) =
296        data.getDataPointByTag(i->first).reductionOp(operation,initial_value);  //       data.getDataPointByTag(i->first).reductionOp(operation,initial_value);
297        result.getDataByTag(i->first,0) =
298        DataMaths::reductionOp(vec,shape,data.getOffsetForTag(i->first),operation,initial_value);
299    }    }
300    // perform the operation on the default data value    // perform the operation on the default data value
301    // and assign this to the default element in result    // and assign this to the default element in result
302    result.getDefaultValue().getData(0) =  //   result.getDefaultValue().getData(0) =
303      data.getDefaultValue().reductionOp(operation,initial_value);  //     data.getDefaultValue().reductionOp(operation,initial_value);
304      result.getVector()[result.getDefaultOffset()] = DataMaths::reductionOp(data.getVector(),data.getShape(),data.getDefaultOffset(),operation,initial_value);
305  }  }
306    
307  template <class BinaryFunction>  template <class BinaryFunction>
# Line 280  dp_algorithm(DataConstant& data, Line 314  dp_algorithm(DataConstant& data,
314  {  {
315    // perform the operation on the data value    // perform the operation on the data value
316    // and assign this to the element in result    // and assign this to the element in result
317    result.getPointDataView().getData(0) =  //   result.getPointDataView().getData(0) =
318      data.getPointDataView().reductionOp(operation,initial_value);  //     data.getPointDataView().reductionOp(operation,initial_value);
319      result.getVector()[0] =
320        DataMaths::reductionOp(data.getVector(),data.getShape(),0,operation,initial_value);
321  }  }
322    
323  } // end of namespace  } // end of namespace

Legend:
Removed from v.1723  
changed lines
  Added in v.1724

  ViewVC Help
Powered by ViewVC 1.1.26