/[escript]/branches/schroedinger/escript/src/DataLazy.cpp
ViewVC logotype

Diff of /branches/schroedinger/escript/src/DataLazy.cpp

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

revision 1883 by jfenwick, Tue Oct 14 03:54:42 2008 UTC revision 1884 by jfenwick, Tue Oct 14 04:54:59 2008 UTC
# Line 206  DataLazy::getBuffsRequired() const Line 206  DataLazy::getBuffsRequired() const
206      return m_buffsRequired;      return m_buffsRequired;
207  }  }
208    
209  void  
210    // the vector and the offset are a place where the method could write its data if it wishes
211    // it is not obligated to do so. For example, if it has its own storage already, it can use that.
212    // hence the return value to indicate where the data is actually stored.
213    // regardless, the storage should be assumed to be used, even if it isn't.
214    const double*
215  DataLazy::resolveSample(ValueType& v,int sampleNo,  size_t offset ) const  DataLazy::resolveSample(ValueType& v,int sampleNo,  size_t offset ) const
216  {  {
217    if (m_op==IDENTITY)   // copy the contents into the vector    if (m_op==IDENTITY)   // copy the contents into the vector
# Line 214  DataLazy::resolveSample(ValueType& v,int Line 219  DataLazy::resolveSample(ValueType& v,int
219  cout << "Begin ID" << endl;  cout << "Begin ID" << endl;
220  cout << "dpps=" << getNumDPPSample() << " novals=" << getNoValues() << endl;  cout << "dpps=" << getNumDPPSample() << " novals=" << getNoValues() << endl;
221      const ValueType& vec=m_id->getVector();      const ValueType& vec=m_id->getVector();
222      size_t srcOffset=m_id->getPointOffset(sampleNo, 0);  //     size_t srcOffset=m_id->getPointOffset(sampleNo, 0);
223  cout << "v.size()=" << v.size() << " vec=" << vec.size() << endl;  // cout << "v.size()=" << v.size() << " vec=" << vec.size() << endl;
224      for (size_t i=0;i<m_samplesize;++i,++srcOffset,++offset)  //     for (size_t i=0;i<m_samplesize;++i,++srcOffset,++offset)
225      {  //     {
226  cout << "Trying offset=" << offset << " srcOffset=" << srcOffset << endl;  // cout << "Trying offset=" << offset << " srcOffset=" << srcOffset << endl;
227      v[offset]=vec[srcOffset];    //  v[offset]=vec[srcOffset];  
228      }  //     }
229  cout << "End ID" << endl;  cout << "End ID - returning offset " << m_id->getPointOffset(sampleNo, 0) << " of vector@" << &vec<<endl;
230      return;      return &(vec[m_id->getPointOffset(sampleNo, 0)]);
231    //     return;
232    }    }
233    cout << "Begin op";
234    size_t rightoffset=offset+m_samplesize;    size_t rightoffset=offset+m_samplesize;
235    m_left->resolveSample(v,sampleNo,offset);    const double* left=m_left->resolveSample(v,sampleNo,offset);
236    m_right->resolveSample(v,sampleNo,rightoffset);    const double* right=m_right->resolveSample(v,sampleNo,rightoffset);
237      double* result=&(v[offset]);
238    cout << "left=" << left << " right=" << right << " result=" << result << endl;
239  //  for (int i=0;i<getNumDPPSample();++i)  //  for (int i=0;i<getNumDPPSample();++i)
240    {    {
241      switch(m_op)      switch(m_op)
242      {      {
243      case ADD:       // since these are pointwise ops, pretend each sample is one point      case ADD:       // since these are pointwise ops, pretend each sample is one point
244      tensor_binary_operation(m_samplesize,&(v[offset]),&(v[rightoffset]),&(v[offset]),plus<double>());      tensor_binary_operation(m_samplesize, left, right, result, plus<double>());
245      break;      break;
246      case SUB:            case SUB:      
247      tensor_binary_operation(m_samplesize,&(v[offset]),&(v[rightoffset]),&(v[offset]),minus<double>());      tensor_binary_operation(m_samplesize, left, right, result, minus<double>());
248      break;      break;
249      case MUL:            case MUL:      
250      tensor_binary_operation(m_samplesize,&(v[offset]),&(v[rightoffset]),&(v[offset]),multiplies<double>());      tensor_binary_operation(m_samplesize, left, right, result, multiplies<double>());
251      break;      break;
252      case DIV:            case DIV:      
253      tensor_binary_operation(m_samplesize,&(v[offset]),&(v[rightoffset]),&(v[offset]),divides<double>());      tensor_binary_operation(m_samplesize, left, right, result, divides<double>());
254      break;      break;
255      default:      default:
256      throw DataException("Programmer error - do not know how to resolve operator "+opToString(m_op)+".");      throw DataException("Programmer error - do not know how to resolve operator "+opToString(m_op)+".");
257      }      }
258    }    }
259      return result;
260  }  }
261    
262  DataReady_ptr  DataReady_ptr
# Line 258  DataLazy::resolve() Line 268  DataLazy::resolve()
268  cout << "Sample size=" << m_samplesize << endl;  cout << "Sample size=" << m_samplesize << endl;
269  cout << "Buffers=" << m_buffsRequired << endl;  cout << "Buffers=" << m_buffsRequired << endl;
270    
271    ValueType v(m_samplesize*max(1,m_buffsRequired));    ValueType v(m_samplesize*(max(1,m_buffsRequired)+1)); // the +1 comes from the fact that I want to have a safe
272                                // space for the RHS of ops to write to even if they don't
273                                // need it.
274  cout << "Buffer created with size=" << v.size() << endl;  cout << "Buffer created with size=" << v.size() << endl;
275    ValueType dummy(getNoValues());    ValueType dummy(getNoValues());
276    DataExpanded* result=new DataExpanded(getFunctionSpace(),getShape(),dummy);    DataExpanded* result=new DataExpanded(getFunctionSpace(),getShape(),dummy);
# Line 268  cout << "Buffer created with size=" << v Line 280  cout << "Buffer created with size=" << v
280    #pragma omp parallel for private(sample) schedule(static)    #pragma omp parallel for private(sample) schedule(static)
281    for (sample=0;sample<getNumSamples();++sample)    for (sample=0;sample<getNumSamples();++sample)
282    {    {
283    cout << "Processing sample#" << sample << endl;
284      resolveSample(v,sample,0);      resolveSample(v,sample,0);
285    cout << "Copying#" << sample << endl;
286      for (int i=0;i<m_samplesize;++i)    // copy values into the output vector      for (int i=0;i<m_samplesize;++i)    // copy values into the output vector
287      {      {
288      resvec[i]=v[i];      resvec[i]=v[i];
# Line 316  DataLazy::getPointOffset(int sampleNo, Line 330  DataLazy::getPointOffset(int sampleNo,
330    throw DataException("getPointOffset - not implemented for Lazy objects - yet.");    throw DataException("getPointOffset - not implemented for Lazy objects - yet.");
331  }  }
332    
 // // The startOffset is where to write results in the output vector v  
 // void  
 // DataLazy::processSample(ValueType& v, int sampleNo, size_t startOffset)  
 // {  
 //     m_left.processSample(v,sampleNo,startOffset);  
 //     m_right.processSample(v,sampleNo,startOffset+getSampleSize());  
 //     int i;  
 //     #pragma omp parallel for private(i) schedule(static)  
 //     for (i=0;i<getSampleSize();++i)  
 //     {  
 //      performOp(v,startOffset+i*m_pointsize,ES_optype,m_samplesize);  
 //     }  
 // }  
   
   
333  }   // end namespace  }   // end namespace

Legend:
Removed from v.1883  
changed lines
  Added in v.1884

  ViewVC Help
Powered by ViewVC 1.1.26