/[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 1884 by jfenwick, Tue Oct 14 04:54:59 2008 UTC revision 1885 by jfenwick, Tue Oct 14 05:51:59 2008 UTC
# Line 19  Line 19 
19  #ifdef PASO_MPI  #ifdef PASO_MPI
20  #include <mpi.h>  #include <mpi.h>
21  #endif  #endif
22    #ifdef _OPENMP
23    #include <omp.h>
24    #endif
25  #include "FunctionSpace.h"  #include "FunctionSpace.h"
26  #include "DataTypes.h"  #include "DataTypes.h"
27  #include "Data.h"  #include "Data.h"
# Line 209  DataLazy::getBuffsRequired() const Line 212  DataLazy::getBuffsRequired() const
212    
213  // the vector and the offset are a place where the method could write its data if it wishes  // the vector and the offset are a place where the method could write its data if it wishes
214  // it is not obligated to do so. For example, if it has its own storage already, it can use that.  // it is not obligated to do so. For example, if it has its own storage already, it can use that.
215  // hence the return value to indicate where the data is actually stored.  // Hence the return value to indicate where the data is actually stored.
216  // regardless, the storage should be assumed to be used, even if it isn't.  // Regardless, the storage should be assumed to be used, even if it isn't.
217  const double*  const double*
218  DataLazy::resolveSample(ValueType& v,int sampleNo,  size_t offset ) const  DataLazy::resolveSample(ValueType& v,int sampleNo,  size_t offset ) const
219  {  {
220    if (m_op==IDENTITY)   // copy the contents into the vector    if (m_op==IDENTITY)  
221    {    {
 cout << "Begin ID" << endl;  
 cout << "dpps=" << getNumDPPSample() << " novals=" << getNoValues() << endl;  
222      const ValueType& vec=m_id->getVector();      const ValueType& vec=m_id->getVector();
 //     size_t srcOffset=m_id->getPointOffset(sampleNo, 0);  
 // cout << "v.size()=" << v.size() << " vec=" << vec.size() << endl;  
 //     for (size_t i=0;i<m_samplesize;++i,++srcOffset,++offset)  
 //     {  
 // cout << "Trying offset=" << offset << " srcOffset=" << srcOffset << endl;  
 //  v[offset]=vec[srcOffset];    
 //     }  
 cout << "End ID - returning offset " << m_id->getPointOffset(sampleNo, 0) << " of vector@" << &vec<<endl;  
223      return &(vec[m_id->getPointOffset(sampleNo, 0)]);      return &(vec[m_id->getPointOffset(sampleNo, 0)]);
 //     return;  
224    }    }
 cout << "Begin op";  
225    size_t rightoffset=offset+m_samplesize;    size_t rightoffset=offset+m_samplesize;
226    const double* left=m_left->resolveSample(v,sampleNo,offset);    const double* left=m_left->resolveSample(v,sampleNo,offset);
227    const double* right=m_right->resolveSample(v,sampleNo,rightoffset);    const double* right=m_right->resolveSample(v,sampleNo,rightoffset);
228    double* result=&(v[offset]);    double* result=&(v[offset]);
 cout << "left=" << left << " right=" << right << " result=" << result << endl;  
 //  for (int i=0;i<getNumDPPSample();++i)  
229    {    {
230      switch(m_op)      switch(m_op)
231      {      {
# Line 268  DataLazy::resolve() Line 257  DataLazy::resolve()
257  cout << "Sample size=" << m_samplesize << endl;  cout << "Sample size=" << m_samplesize << endl;
258  cout << "Buffers=" << m_buffsRequired << endl;  cout << "Buffers=" << m_buffsRequired << endl;
259    
260    ValueType v(m_samplesize*(max(1,m_buffsRequired)+1)); // the +1 comes from the fact that I want to have a safe    size_t threadbuffersize=m_samplesize*(max(1,m_buffsRequired)+1);
261      int numthreads=1;
262    #ifdef _OPENMP
263      numthreads=omp_get_max_threads();
264      int threadnum=0;
265    #endif
266      ValueType v(numthreads*threadbuffersize); // the +1 comes from the fact that I want to have a safe
267                              // space for the RHS of ops to write to even if they don't                              // space for the RHS of ops to write to even if they don't
268                              // need it.                              // need it.
269  cout << "Buffer created with size=" << v.size() << endl;  cout << "Buffer created with size=" << v.size() << endl;
# Line 277  cout << "Buffer created with size=" << v Line 272  cout << "Buffer created with size=" << v
272    ValueType& resvec=result->getVector();    ValueType& resvec=result->getVector();
273    DataReady_ptr resptr=DataReady_ptr(result);    DataReady_ptr resptr=DataReady_ptr(result);
274    int sample;    int sample;
275    #pragma omp parallel for private(sample) schedule(static)    int resoffset;
276    for (sample=0;sample<getNumSamples();++sample)    int totalsamples=getNumSamples();
277      #pragma omp parallel for private(sample,resoffset,threadnum) schedule(static)
278      for (sample=0;sample<totalsamples;++sample)
279    {    {
280  cout << "Processing sample#" << sample << endl;  #ifdef _OPENMP
281      resolveSample(v,sample,0);      const double* res=resolveSample(v,sample,threadbuffersize*omp_get_thread_num());
282  cout << "Copying#" << sample << endl;  #else
283      for (int i=0;i<m_samplesize;++i)    // copy values into the output vector      const double* res=resolveSample(v,sample,0);   // this would normally be v, but not if its a single IDENTITY op.
284    #endif
285        resoffset=result->getPointOffset(sample,0);
286        for (int i=0;i<m_samplesize;++i,++resoffset)    // copy values into the output vector
287      {      {
288      resvec[i]=v[i];      resvec[resoffset]=res[i];
289      }      }
290    }    }
291    return resptr;    return resptr;

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

  ViewVC Help
Powered by ViewVC 1.1.26