# Diff of /trunk/escript/src/DataAlgorithm.h

revision 113 by jgs, Mon Feb 28 07:06:33 2005 UTC revision 122 by jgs, Thu Jun 9 05:38:05 2005 UTC
# Line 110  struct AbsMax : public std::binary_funct Line 110  struct AbsMax : public std::binary_funct
110
111  /**  /**
112     \brief     \brief
113       Return the absolute minimum value of the two given values.
114    */
115    struct AbsMin : public std::binary_function<double,double,double>
116    {
117      inline double operator()(double x, double y) const
118      {
119        return std::min(fabs(x),fabs(y));
120      }
121    };
122
123    /**
124       \brief
125     Return the length between the two given values.     Return the length between the two given values.
126  */  */
127  struct Length : public std::binary_function<double,double,double>  struct Length : public std::binary_function<double,double,double>
# Line 154  algorithm(DataExpanded& data, Line 166  algorithm(DataExpanded& data,
166    // calculate the reduction operation value for each data point    // calculate the reduction operation value for each data point
167    // storing the result for each data-point in successive entries    // storing the result for each data-point in successive entries
168    // in resultVector    // in resultVector
169    {    //
170  #pragma omp for private(i,j) schedule(static)    // this loop cannot be prallelised as "operation" is an instance of DataAlgorithmAdapter
171      for (i=0;i<numSamples;i++) {    // which maintains state between calls which would be corrupted by parallel execution
172        for (j=0;j<numDPPSample;j++) {    for (i=0;i<numSamples;i++) {
173  #pragma omp critical (reductionOp)      for (j=0;j<numDPPSample;j++) {
174      resultVector[j*numSamples+i]=dataView.reductionOp(data.getPointOffset(i,j),operation);        resultVector[j*numSamples+i]=dataView.reductionOp(data.getPointOffset(i,j),operation);
}
175      }      }
176    }    }
177    // now calculate the reduction operation value across the results    // now calculate the reduction operation value across the results
178    // for each data-point    // for each data-point
179      //
180      // this loop cannot be prallelised as "operation" is an instance of DataAlgorithmAdapter
181      // which maintains state between calls which would be corrupted by parallel execution
182    operation.resetResult();    operation.resetResult();
183    for (int l=0;l<resultVectorLength;l++) {    for (int l=0;l<resultVectorLength;l++) {
184      operation(resultVector[l]);      operation(resultVector[l]);
# Line 192  algorithm(DataTagged& data, Line 206  algorithm(DataTagged& data,
206    resultVector.push_back(data.getDefaultValue().reductionOp(operation));    resultVector.push_back(data.getDefaultValue().reductionOp(operation));
207    // now calculate the reduction operation value across the results    // now calculate the reduction operation value across the results
208    // for each tagged value    // for each tagged value
209      //
210      // this loop cannot be prallelised as "operation" is an instance of DataAlgorithmAdapter
211      // which maintains state between calls which would be corrupted by parallel execution
212    resultVectorLength=resultVector.size();    resultVectorLength=resultVector.size();
213    operation.resetResult();    operation.resetResult();
214    for (int l=0;l<resultVectorLength;l++) {    for (int l=0;l<resultVectorLength;l++) {
# Line 228  dp_algorithm(DataExpanded& data, Line 245  dp_algorithm(DataExpanded& data,
245               UnaryFunction operation)               UnaryFunction operation)
246  {  {
247    int i,j;    int i,j;
int numDPPSample=data.getNumDPPSample();
248    int numSamples=data.getNumSamples();    int numSamples=data.getNumSamples();
249      int numDPPSample=data.getNumDPPSample();
250    DataArrayView dataView=data.getPointDataView();    DataArrayView dataView=data.getPointDataView();
251    DataArrayView resultView=result.getPointDataView();    DataArrayView resultView=result.getPointDataView();
252    // perform the operation on each data-point and assign    // perform the operation on each data-point and assign
253    // this to the corresponding element in result    // this to the corresponding element in result
254    {    //
255  #pragma omp for private(i,j) schedule(static)    // this loop cannot be prallelised as "operation" is an instance of DataAlgorithmAdapter
256      for (i=0;i<numSamples;i++) {    // which maintains state between calls which would be corrupted by parallel execution
257        for (j=0;j<numDPPSample;j++) {    for (i=0;i<numSamples;i++) {
258  #pragma omp critical (reductionOp)      for (j=0;j<numDPPSample;j++) {
259          resultView.getData(data.getPointOffset(i,j)) =        resultView.getData(result.getPointOffset(i,j)) =
260            dataView.reductionOp(data.getPointOffset(i,j),operation);          dataView.reductionOp(data.getPointOffset(i,j),operation);
}
261      }      }
262    }    }
263  }  }
# Line 260  dp_algorithm(DataTagged& data, Line 276  dp_algorithm(DataTagged& data,
276    DataArrayView resultView=result.getPointDataView();    DataArrayView resultView=result.getPointDataView();
277    // perform the operation on each tagged data value    // perform the operation on each tagged data value
278    // and assign this to the corresponding element in result    // and assign this to the corresponding element in result
279      //
280      // this loop cannot be prallelised as "operation" is an instance of DataAlgorithmAdapter
281      // which maintains state between calls which would be corrupted by parallel execution
282    for (i=lookup.begin();i!=lookupEnd;i++) {    for (i=lookup.begin();i!=lookupEnd;i++) {
283      resultView.getData(i->second) =      resultView.getData(i->second) =
284        dataView.reductionOp(i->second,operation);        dataView.reductionOp(i->second,operation);
# Line 284  dp_algorithm(DataConstant& data, Line 303  dp_algorithm(DataConstant& data,
303  }  }
304
305  } // end of namespace  } // end of namespace
306
307  #endif  #endif

Legend:
 Removed from v.113 changed lines Added in v.122