/[escript]/branches/clazy/escriptcore/src/DataLazy.cpp
ViewVC logotype

Diff of /branches/clazy/escriptcore/src/DataLazy.cpp

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

revision 5997 by caltinay, Mon Feb 29 07:24:47 2016 UTC revision 6057 by jfenwick, Thu Mar 10 06:00:58 2016 UTC
# Line 14  Line 14 
14  *  *
15  *****************************************************************************/  *****************************************************************************/
16    
 #define ESNEEDPYTHON  
 #include "esysUtils/first.h"  
   
17  #include "DataLazy.h"  #include "DataLazy.h"
18  #include "Data.h"  #include "Data.h"
19  #include "DataTypes.h"  #include "DataTypes.h"
# Line 24  Line 21 
21  #include "FunctionSpace.h"  #include "FunctionSpace.h"
22  #include "UnaryFuncs.h"    // for escript::fsign  #include "UnaryFuncs.h"    // for escript::fsign
23  #include "Utils.h"  #include "Utils.h"
24    #include "DataMaths.h"
25    
26  #ifdef USE_NETCDF  #ifdef USE_NETCDF
27  #include <netcdfcpp.h>  #include <netcdfcpp.h>
# Line 993  DataLazy::collapse() const Line 991  DataLazy::collapse() const
991    m_op=IDENTITY;    m_op=IDENTITY;
992  }  }
993    
   
   
   
   
   
 #define PROC_OP(TYPE,X)                               \  
         for (int j=0;j<onumsteps;++j)\  
         {\  
           for (int i=0;i<numsteps;++i,resultp+=resultStep) \  
           { \  
 LAZYDEBUG(cout << "[left,right]=[" << lroffset << "," << rroffset << "]" << endl;)\  
 LAZYDEBUG(cout << "{left,right}={" << (*left)[lroffset] << "," << (*right)[rroffset] << "}\n";)\  
              tensor_binary_operation< TYPE >(chunksize, &((*left)[lroffset]), &((*right)[rroffset]), resultp, X); \  
 LAZYDEBUG(cout << " result=      " << resultp[0] << endl;) \  
              lroffset+=leftstep; \  
              rroffset+=rightstep; \  
           }\  
           lroffset+=oleftstep;\  
           rroffset+=orightstep;\  
         }  
   
   
994  // The result will be stored in m_samples  // The result will be stored in m_samples
995  // The return value is a pointer to the DataVector, offset is the offset within the return value  // The return value is a pointer to the DataVector, offset is the offset within the return value
996  const DataTypes::RealVectorType*  const DataTypes::RealVectorType*
# Line 1028  LAZYDEBUG(cout << "Resolve sample " << t Line 1004  LAZYDEBUG(cout << "Resolve sample " << t
1004    }    }
1005    if (m_op==IDENTITY)      if (m_op==IDENTITY)  
1006    {    {
1007      const ValueType& vec=m_id->getVectorRO();      const RealVectorType& vec=m_id->getVectorRO();
1008      roffset=m_id->getPointOffset(sampleNo, 0);      roffset=m_id->getPointOffset(sampleNo, 0);
1009  #ifdef LAZY_STACK_PROF  #ifdef LAZY_STACK_PROF
1010  int x;  int x;
# Line 1265  DataLazy::resolveNodeNP1OUT(int tid, int Line 1241  DataLazy::resolveNodeNP1OUT(int tid, int
1241      throw DataException("Programmer error - resolveNodeNP1OUT should not be called on identity nodes.");      throw DataException("Programmer error - resolveNodeNP1OUT should not be called on identity nodes.");
1242    }    }
1243    size_t subroffset;    size_t subroffset;
1244    const ValueType* leftres=m_left->resolveNodeSample(tid, sampleNo, subroffset);    const RealVectorType* leftres=m_left->resolveNodeSample(tid, sampleNo, subroffset);
1245    roffset=m_samplesize*tid;    roffset=m_samplesize*tid;
1246    size_t loop=0;    size_t loop=0;
1247    size_t numsteps=(m_readytype=='E')?getNumDPPSample():1;    size_t numsteps=(m_readytype=='E')?getNumDPPSample():1;
# Line 1311  DataLazy::resolveNodeNP1OUT_P(int tid, i Line 1287  DataLazy::resolveNodeNP1OUT_P(int tid, i
1287    }    }
1288    size_t subroffset;    size_t subroffset;
1289    size_t offset;    size_t offset;
1290    const ValueType* leftres=m_left->resolveNodeSample(tid, sampleNo, subroffset);    const RealVectorType* leftres=m_left->resolveNodeSample(tid, sampleNo, subroffset);
1291    roffset=m_samplesize*tid;    roffset=m_samplesize*tid;
1292    offset=roffset;    offset=roffset;
1293    size_t loop=0;    size_t loop=0;
# Line 1356  DataLazy::resolveNodeNP1OUT_2P(int tid, Line 1332  DataLazy::resolveNodeNP1OUT_2P(int tid,
1332    }    }
1333    size_t subroffset;    size_t subroffset;
1334    size_t offset;    size_t offset;
1335    const ValueType* leftres=m_left->resolveNodeSample(tid, sampleNo, subroffset);    const RealVectorType* leftres=m_left->resolveNodeSample(tid, sampleNo, subroffset);
1336    roffset=m_samplesize*tid;    roffset=m_samplesize*tid;
1337    offset=roffset;    offset=roffset;
1338    size_t loop=0;    size_t loop=0;
# Line 1392  DataLazy::resolveNodeCondEval(int tid, i Line 1368  DataLazy::resolveNodeCondEval(int tid, i
1368    }    }
1369    size_t subroffset;    size_t subroffset;
1370    
1371    const ValueType* maskres=m_mask->resolveNodeSample(tid, sampleNo, subroffset);    const RealVectorType* maskres=m_mask->resolveNodeSample(tid, sampleNo, subroffset);
1372    const ValueType* srcres=0;    const RealVectorType* srcres=0;
1373    if ((*maskres)[subroffset]>0)    if ((*maskres)[subroffset]>0)
1374    {    {
1375          srcres=m_left->resolveNodeSample(tid, sampleNo, subroffset);          srcres=m_left->resolveNodeSample(tid, sampleNo, subroffset);
# Line 1536  LAZYDEBUG(cout << "Resolve binary: " << Line 1512  LAZYDEBUG(cout << "Resolve binary: " <<
1512    
1513    int resultStep=max(leftstep,rightstep);       // only one (at most) should be !=0    int resultStep=max(leftstep,rightstep);       // only one (at most) should be !=0
1514          // Get the values of sub-expressions          // Get the values of sub-expressions
1515    const ValueType* left=m_left->resolveNodeSample(tid,sampleNo,lroffset);          const RealVectorType* left=m_left->resolveNodeSample(tid,sampleNo,lroffset);      
1516    const ValueType* right=m_right->resolveNodeSample(tid,sampleNo,rroffset);    const RealVectorType* right=m_right->resolveNodeSample(tid,sampleNo,rroffset);
1517  LAZYDEBUG(cout << "Post sub calls in " << toString() << endl;)  LAZYDEBUG(cout << "Post sub calls in " << toString() << endl;)
1518  LAZYDEBUG(cout << "shapes=" << DataTypes::shapeToString(m_left->getShape()) << "," << DataTypes::shapeToString(m_right->getShape()) << endl;)  LAZYDEBUG(cout << "shapes=" << DataTypes::shapeToString(m_left->getShape()) << "," << DataTypes::shapeToString(m_right->getShape()) << endl;)
1519  LAZYDEBUG(cout << "chunksize=" << chunksize << endl << "leftstep=" << leftstep << " rightstep=" << rightstep;)  LAZYDEBUG(cout << "chunksize=" << chunksize << endl << "leftstep=" << leftstep << " rightstep=" << rightstep;)
# Line 1555  LAZYDEBUG(cout << "Right res["<< rroffse Line 1531  LAZYDEBUG(cout << "Right res["<< rroffse
1531    switch(m_op)    switch(m_op)
1532    {    {
1533      case ADD:      case ADD:
1534          PROC_OP(NO_ARG,plus<double>());          //PROC_OP(NO_ARG,plus<double>());
1535          DataMaths::binaryOpVectorLazyHelper<real_t, real_t, real_t>(resultp,
1536                 &(*left)[0],
1537                 &(*right)[0],
1538                 chunksize,
1539                 onumsteps,
1540                 numsteps,
1541                 resultStep,
1542                 leftstep,
1543                 rightstep,
1544                 oleftstep,
1545                 orightstep,
1546                 lroffset,
1547                 rroffset,
1548                 escript::ESFunction::PLUSF);  
1549          break;          break;
1550      case SUB:      case SUB:
1551          PROC_OP(NO_ARG,minus<double>());        DataMaths::binaryOpVectorLazyHelper<real_t, real_t, real_t>(resultp,
1552                 &(*left)[0],
1553                 &(*right)[0],
1554                 chunksize,
1555                 onumsteps,
1556                 numsteps,
1557                 resultStep,
1558                 leftstep,
1559                 rightstep,
1560                 oleftstep,
1561                 orightstep,
1562                 lroffset,
1563                 rroffset,
1564                 escript::ESFunction::MINUSF);        
1565            //PROC_OP(NO_ARG,minus<double>());
1566          break;          break;
1567      case MUL:      case MUL:
1568          PROC_OP(NO_ARG,multiplies<double>());          //PROC_OP(NO_ARG,multiplies<double>());
1569          DataMaths::binaryOpVectorLazyHelper<real_t, real_t, real_t>(resultp,
1570                 &(*left)[0],
1571                 &(*right)[0],
1572                 chunksize,
1573                 onumsteps,
1574                 numsteps,
1575                 resultStep,
1576                 leftstep,
1577                 rightstep,
1578                 oleftstep,
1579                 orightstep,
1580                 lroffset,
1581                 rroffset,
1582                 escript::ESFunction::MULTIPLIESF);      
1583          break;          break;
1584      case DIV:      case DIV:
1585          PROC_OP(NO_ARG,divides<double>());          //PROC_OP(NO_ARG,divides<double>());
1586          DataMaths::binaryOpVectorLazyHelper<real_t, real_t, real_t>(resultp,
1587                 &(*left)[0],
1588                 &(*right)[0],
1589                 chunksize,
1590                 onumsteps,
1591                 numsteps,
1592                 resultStep,
1593                 leftstep,
1594                 rightstep,
1595                 oleftstep,
1596                 orightstep,
1597                 lroffset,
1598                 rroffset,
1599                 escript::ESFunction::DIVIDESF);          
1600          break;          break;
1601      case POW:      case POW:
1602         PROC_OP(double (double,double),::pow);         //PROC_OP(double (double,double),::pow);
1603          DataMaths::binaryOpVectorLazyHelper<real_t, real_t, real_t>(resultp,
1604                 &(*left)[0],
1605                 &(*right)[0],
1606                 chunksize,
1607                 onumsteps,
1608                 numsteps,
1609                 resultStep,
1610                 leftstep,
1611                 rightstep,
1612                 oleftstep,
1613                 orightstep,
1614                 lroffset,
1615                 rroffset,
1616                 escript::ESFunction::POWF);          
1617          break;          break;
1618      default:      default:
1619          throw DataException("Programmer error - resolveBinary can not resolve operator "+opToString(m_op)+".");          throw DataException("Programmer error - resolveBinary can not resolve operator "+opToString(m_op)+".");
# Line 1597  LAZYDEBUG(cout << "Resolve TensorProduct Line 1643  LAZYDEBUG(cout << "Resolve TensorProduct
1643    roffset=m_samplesize*tid;    roffset=m_samplesize*tid;
1644    size_t offset=roffset;    size_t offset=roffset;
1645    
1646    const ValueType* left=m_left->resolveNodeSample(tid, sampleNo, lroffset);    const RealVectorType* left=m_left->resolveNodeSample(tid, sampleNo, lroffset);
1647    
1648    const ValueType* right=m_right->resolveNodeSample(tid, sampleNo, rroffset);    const RealVectorType* right=m_right->resolveNodeSample(tid, sampleNo, rroffset);
1649    
1650  LAZYDEBUG(cerr << "[Left shape]=" << DataTypes::shapeToString(m_left->getShape()) << "\n[Right shape]=" << DataTypes::shapeToString(m_right->getShape()) << " result=" <<DataTypes::shapeToString(getShape()) <<  endl;  LAZYDEBUG(cerr << "[Left shape]=" << DataTypes::shapeToString(m_left->getShape()) << "\n[Right shape]=" << DataTypes::shapeToString(m_right->getShape()) << " result=" <<DataTypes::shapeToString(getShape()) <<  endl;
1651  cout << getNoValues() << endl;)  cout << getNoValues() << endl;)
# Line 1736  DataLazy::resolveGroupWorker(std::vector Line 1782  DataLazy::resolveGroupWorker(std::vector
1782    {             // it is possible that dats[0] is one of the objects which we discarded and    {             // it is possible that dats[0] is one of the objects which we discarded and
1783                  // all the other functionspaces match.                  // all the other functionspaces match.
1784          vector<DataExpanded*> dep;          vector<DataExpanded*> dep;
1785          vector<ValueType*> vecs;          vector<RealVectorType*> vecs;
1786          for (int i=0;i<work.size();++i)          for (int i=0;i<work.size();++i)
1787          {          {
1788                  dep.push_back(new DataExpanded(fs,work[i]->getShape(), ValueType(work[i]->getNoValues())));                  dep.push_back(new DataExpanded(fs,work[i]->getShape(), RealVectorType(work[i]->getNoValues())));
1789                  vecs.push_back(&(dep[i]->getVectorRW()));                  vecs.push_back(&(dep[i]->getVectorRW()));
1790          }          }
1791          int totalsamples=work[0]->getNumSamples();          int totalsamples=work[0]->getNumSamples();
1792          const ValueType* res=0; // Storage for answer          const RealVectorType* res=0; // Storage for answer
1793          int sample;          int sample;
1794          #pragma omp parallel private(sample, res)          #pragma omp parallel private(sample, res)
1795          {          {
# Line 1795  DataLazy::resolveNodeWorker() Line 1841  DataLazy::resolveNodeWorker()
1841      return m_id;      return m_id;
1842    }    }
1843          // from this point on we must have m_op!=IDENTITY and m_readytype=='E'          // from this point on we must have m_op!=IDENTITY and m_readytype=='E'
1844    DataExpanded* result=new DataExpanded(getFunctionSpace(),getShape(),  ValueType(getNoValues()));    DataExpanded* result=new DataExpanded(getFunctionSpace(),getShape(),  RealVectorType(getNoValues()));
1845    ValueType& resvec=result->getVectorRW();    RealVectorType& resvec=result->getVectorRW();
1846    DataReady_ptr resptr=DataReady_ptr(result);    DataReady_ptr resptr=DataReady_ptr(result);
1847    
1848    int sample;    int sample;
1849    int totalsamples=getNumSamples();    int totalsamples=getNumSamples();
1850    const ValueType* res=0;       // Storage for answer    const RealVectorType* res=0;       // Storage for answer
1851  LAZYDEBUG(cout << "Total number of samples=" <<totalsamples << endl;)  LAZYDEBUG(cout << "Total number of samples=" <<totalsamples << endl;)
1852    #pragma omp parallel private(sample,res)    #pragma omp parallel private(sample,res)
1853    {    {

Legend:
Removed from v.5997  
changed lines
  Added in v.6057

  ViewVC Help
Powered by ViewVC 1.1.26