/[escript]/trunk/escriptcore/src/DataLazy.cpp
ViewVC logotype

Diff of /trunk/escriptcore/src/DataLazy.cpp

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

revision 2270 by jfenwick, Thu Jan 8 06:10:52 2009 UTC revision 2271 by jfenwick, Mon Feb 16 05:08:29 2009 UTC
# Line 40  bool privdebug=false; Line 40  bool privdebug=false;
40  #define DISABLEDEBUG privdebug=false;  #define DISABLEDEBUG privdebug=false;
41  }  }
42    
43  #define SIZELIMIT  // #define SIZELIMIT
44  // #define SIZELIMIT if ((m_height>7) || (m_children>127)) {cerr << "\n!!!!!!! SIZE LIMIT EXCEEDED " << m_children << ";" << m_height << endl << toString() << endl; resolveToIdentity();}  // #define SIZELIMIT if ((m_height>7) || (m_children>127)) {cerr << "\n!!!!!!! SIZE LIMIT EXCEEDED " << m_children << ";" << m_height << endl << toString() << endl; resolveToIdentity();}
45    #define SIZELIMIT if ((m_height>7) || (m_children>127)) {resolveToIdentity();}
46    
47  /*  /*
48  How does DataLazy work?  How does DataLazy work?
# Line 348  GTPShape(DataAbstract_ptr left, DataAbst Line 348  GTPShape(DataAbstract_ptr left, DataAbst
348  // determine the number of samples requires to evaluate an expression combining left and right  // determine the number of samples requires to evaluate an expression combining left and right
349  // NP1OUT needs an extra buffer because we can't write the answers over the top of the input.  // NP1OUT needs an extra buffer because we can't write the answers over the top of the input.
350  // The same goes for G_TENSORPROD  // The same goes for G_TENSORPROD
351  // It might seem that pointwise binary ops (G_BINARY) could be written over the top of the lefths.  // It might seem that pointwise binary ops (G_BINARY) could be written over the top of the lefts.
352  // This would be true were it not for the possibility that the LHS could be a scalar which needs to be examined  // This would be true were it not for the possibility that the LHS could be a scalar which needs to be examined
353  // multiple times  // multiple times
354  int  int
# Line 397  DataLazy::DataLazy(DataAbstract_ptr p) Line 397  DataLazy::DataLazy(DataAbstract_ptr p)
397     }     }
398     else     else
399     {     {
400        p->makeLazyShared();
401      DataReady_ptr dr=dynamic_pointer_cast<DataReady>(p);      DataReady_ptr dr=dynamic_pointer_cast<DataReady>(p);
402      makeIdentity(dr);      makeIdentity(dr);
403  LAZYDEBUG(cout << "Wrapping " << dr.get() << " id=" << m_id.get() << endl;)  LAZYDEBUG(cout << "Wrapping " << dr.get() << " id=" << m_id.get() << endl;)
# Line 657  DataLazy::getMaxSampleSize() const Line 658  DataLazy::getMaxSampleSize() const
658      return m_maxsamplesize;      return m_maxsamplesize;
659  }  }
660    
661    
662    
663    size_t
664    DataLazy::getSampleBufferSize() const
665    {
666        return m_maxsamplesize*(max(1,m_buffsRequired));
667    }
668    
669  /*  /*
670    \brief Evaluates the expression using methods on Data.    \brief Evaluates the expression using methods on Data.
671    This does the work for the collapse method.    This does the work for the collapse method.
# Line 1425  LAZYDEBUG(cout << "Resolve sample " << t Line 1434  LAZYDEBUG(cout << "Resolve sample " << t
1434    }    }
1435    if (m_op==IDENTITY)      if (m_op==IDENTITY)  
1436    {    {
1437      const ValueType& vec=m_id->getVector();      const ValueType& vec=m_id->getVectorRO();
1438      if (m_readytype=='C')      if (m_readytype=='C')
1439      {      {
1440      roffset=0;      roffset=0;
# Line 1454  LAZYDEBUG(cout << "Finish  sample " << t Line 1463  LAZYDEBUG(cout << "Finish  sample " << t
1463    
1464  }  }
1465    
1466    const DataTypes::ValueType*
1467    DataLazy::resolveSample(BufferGroup& bg, int sampleNo, size_t& roffset)
1468    {
1469    #ifdef _OPENMP
1470        int tid=omp_get_thread_num();
1471    #else
1472        int tid=0;
1473    #endif
1474        return resolveSample(bg.getBuffer(tid),bg.getOffset(tid),sampleNo,roffset);
1475    }
1476    
1477    
1478  // This needs to do the work of the idenity constructor  // This needs to do the work of the idenity constructor
1479  void  void
1480  DataLazy::resolveToIdentity()  DataLazy::resolveToIdentity()
# Line 1491  DataLazy::resolve() Line 1512  DataLazy::resolve()
1512    
1513  LAZYDEBUG(cout << "Sample size=" << m_samplesize << endl;)  LAZYDEBUG(cout << "Sample size=" << m_samplesize << endl;)
1514  LAZYDEBUG(cout << "Buffers=" << m_buffsRequired << endl;)  LAZYDEBUG(cout << "Buffers=" << m_buffsRequired << endl;)
   
1515    if (m_readytype!='E')     // if the whole sub-expression is Constant or Tagged, then evaluate it normally    if (m_readytype!='E')     // if the whole sub-expression is Constant or Tagged, then evaluate it normally
1516    {    {
1517      collapse();      collapse();
# Line 1505  LAZYDEBUG(cout << "Buffers=" << m_buffsR Line 1525  LAZYDEBUG(cout << "Buffers=" << m_buffsR
1525      // storage to evaluate its expression      // storage to evaluate its expression
1526    int numthreads=1;    int numthreads=1;
1527  #ifdef _OPENMP  #ifdef _OPENMP
1528    numthreads=getNumberOfThreads();    numthreads=omp_get_max_threads();
1529  #endif  #endif
1530    ValueType v(numthreads*threadbuffersize);    ValueType v(numthreads*threadbuffersize);
1531  LAZYDEBUG(cout << "Buffer created with size=" << v.size() << endl;)  LAZYDEBUG(cout << "Buffer created with size=" << v.size() << endl;)
1532    DataExpanded* result=new DataExpanded(getFunctionSpace(),getShape(),  ValueType(getNoValues()));    DataExpanded* result=new DataExpanded(getFunctionSpace(),getShape(),  ValueType(getNoValues()));
1533    ValueType& resvec=result->getVector();    ValueType& resvec=result->getVectorRW();
1534    DataReady_ptr resptr=DataReady_ptr(result);    DataReady_ptr resptr=DataReady_ptr(result);
1535    int sample;    int sample;
1536    size_t outoffset;     // offset in the output data    size_t outoffset;     // offset in the output data
# Line 1559  DataLazy::toString() const Line 1579  DataLazy::toString() const
1579  void  void
1580  DataLazy::intoString(ostringstream& oss) const  DataLazy::intoString(ostringstream& oss) const
1581  {  {
1582  //   oss << "[" << m_children <<";"<<m_height <<"]";  //    oss << "[" << m_children <<";"<<m_height <<"]";
1583    switch (getOpgroup(m_op))    switch (getOpgroup(m_op))
1584    {    {
1585    case G_IDENTITY:    case G_IDENTITY:
# Line 1699  DataLazy::getPointOffset(int sampleNo, Line 1719  DataLazy::getPointOffset(int sampleNo,
1719    throw DataException("Programmer error - getPointOffset on lazy data may require collapsing (but this object is marked const).");    throw DataException("Programmer error - getPointOffset on lazy data may require collapsing (but this object is marked const).");
1720  }  }
1721    
1722  // It would seem that DataTagged will need to be treated differently since even after setting all tags  
1723  // to zero, all the tags from all the DataTags would be in the result.  // I have decided to let Data:: handle this issue.
 // However since they all have the same value (0) whether they are there or not should not matter.  
 // So I have decided that for all types this method will create a constant 0.  
 // It can be promoted up as required.  
 // A possible efficiency concern might be expanded->constant->expanded which has an extra memory management  
 // but we can deal with that if it arrises.  
1724  void  void
1725  DataLazy::setToZero()  DataLazy::setToZero()
1726  {  {
1727    DataTypes::ValueType v(getNoValues(),0);  //   DataTypes::ValueType v(getNoValues(),0);
1728    m_id=DataReady_ptr(new DataConstant(getFunctionSpace(),getShape(),v));  //   m_id=DataReady_ptr(new DataConstant(getFunctionSpace(),getShape(),v));
1729    m_op=IDENTITY;  //   m_op=IDENTITY;
1730    m_right.reset();    //   m_right.reset();  
1731    m_left.reset();  //   m_left.reset();
1732    m_readytype='C';  //   m_readytype='C';
1733    m_buffsRequired=1;  //   m_buffsRequired=1;
1734    
1735      throw DataException("Programmer error - setToZero not supported for DataLazy (DataLazy objects should be read only).");
1736    
1737    }
1738    
1739    bool
1740    DataLazy::actsExpanded() const
1741    {
1742        return (m_readytype=='E');
1743  }  }
1744    
1745  }   // end namespace  }   // end namespace

Legend:
Removed from v.2270  
changed lines
  Added in v.2271

  ViewVC Help
Powered by ViewVC 1.1.26