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

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

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

revision 147 by jgs, Fri Aug 12 01:45:47 2005 UTC revision 148 by jgs, Tue Aug 23 01:24:31 2005 UTC
# Line 167  algorithm(DataExpanded& data, Line 167  algorithm(DataExpanded& data,
167    int i,j;    int i,j;
168    int numDPPSample=data.getNumDPPSample();    int numDPPSample=data.getNumDPPSample();
169    int numSamples=data.getNumSamples();    int numSamples=data.getNumSamples();
170    int resultVectorLength=numDPPSample*numSamples;    double global_current_value=initial_value;
171    std::vector<double> resultVector(resultVectorLength);    double local_current_value;
172    DataArrayView dataView=data.getPointDataView();    DataArrayView dataView=data.getPointDataView();
173    // calculate the reduction operation value for each data point    // calculate the reduction operation value for each data point
174    // storing the result for each data-point in successive entries    // reducing the result for each data-point into the current_value variables
175    // in resultVector    #pragma omp parallel private(local_current_value)
176    #pragma omp parallel for private(i,j) schedule(static)    {
177    for (i=0;i<numSamples;i++) {        local_current_value=initial_value;
178      for (j=0;j<numDPPSample;j++) {        #pragma omp for private(i,j) schedule(static)
179        resultVector[j*numSamples+i]=dataView.reductionOp(data.getPointOffset(i,j),operation,initial_value);        for (i=0;i<numSamples;i++) {
180      }          for (j=0;j<numDPPSample;j++) {
181              local_current_value=operation(local_current_value,dataView.reductionOp(data.getPointOffset(i,j),operation,initial_value));
182            }
183          }
184          #pragma omp critical
185          global_current_value=operation(global_current_value,local_current_value);
186    }    }
187    // now calculate the reduction operation value across the results    return global_current_value;
   // for each data-point  
   double current_value=initial_value;  
   for (int l=0;l<resultVectorLength;l++) {  
     current_value=operation(current_value,resultVector[l]);  
   }  
   return current_value;  
188  }  }
189    
190  template <class BinaryFunction>  template <class BinaryFunction>
# Line 199  algorithm(DataTagged& data, Line 198  algorithm(DataTagged& data,
198    DataTagged::DataMapType::const_iterator i;    DataTagged::DataMapType::const_iterator i;
199    DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();    DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();
200    DataArrayView& dataView=data.getPointDataView();    DataArrayView& dataView=data.getPointDataView();
201    std::vector<double> resultVector;    double current_value=initial_value;
   int resultVectorLength;  
202    // perform the operation on each tagged value    // perform the operation on each tagged value
203    for (i=lookup.begin();i!=lookupEnd;i++) {    for (i=lookup.begin();i!=lookupEnd;i++) {
204      resultVector.push_back(dataView.reductionOp(i->second,operation,initial_value));      current_value=operation(current_value,dataView.reductionOp(i->second,operation,initial_value));
205    }    }
206    // perform the operation on the default value    // perform the operation on the default value
207    resultVector.push_back(data.getDefaultValue().reductionOp(operation,initial_value));    current_value=operation(current_value,data.getDefaultValue().reductionOp(operation,initial_value));
   // now calculate the reduction operation value across the results  
   // for each tagged value  
   resultVectorLength=resultVector.size();  
   double current_value=initial_value;  
   for (int l=0;l<resultVectorLength;l++) {  
     current_value=operation(current_value,resultVector[l]);  
   }  
208    return current_value;    return current_value;
209  }  }
210    

Legend:
Removed from v.147  
changed lines
  Added in v.148

  ViewVC Help
Powered by ViewVC 1.1.26