/[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

trunk/escriptcore/src/DataLazy.cpp revision 6112 by jfenwick, Thu Mar 31 09:40:10 2016 UTC branches/clazy/escriptcore/src/DataLazy.cpp revision 6511 by jfenwick, Fri Mar 3 01:41:39 2017 UTC
# Line 22  Line 22 
22  #include "Utils.h"  #include "Utils.h"
23  #include "DataVectorOps.h"  #include "DataVectorOps.h"
24    
 #ifdef USE_NETCDF  
 #include <netcdfcpp.h>  
 #endif  
   
25  #include <iomanip> // for some fancy formatting in debug  #include <iomanip> // for some fancy formatting in debug
26    
27  using namespace escript::DataTypes;  using namespace escript::DataTypes;
# Line 42  bool privdebug=false; Line 38  bool privdebug=false;
38  #define DISABLEDEBUG privdebug=false;  #define DISABLEDEBUG privdebug=false;
39  }  }
40    
41  // #define SIZELIMIT if ((m_height>escript::escriptParams.getTOO_MANY_LEVELS()) || (m_children>escript::escriptParams.getTOO_MANY_NODES())) {cerr << "\n!!!!!!! SIZE LIMIT EXCEEDED " << m_children << ";" << m_height << endl << toString() << endl;resolveToIdentity();}  //#define SIZELIMIT if ((m_height>escript::escriptParams.getInt("TOO_MANY_LEVELS")) || (m_children>escript::escriptParams.getInt("TOO_MANY_NODES"))) {cerr << "\n!!!!!!! SIZE LIMIT EXCEEDED " << m_children << ";" << m_height << endl << toString() << endl;resolveToIdentity();}
42    
43  // #define SIZELIMIT if ((m_height>escript::escriptParams.getTOO_MANY_LEVELS()) || (m_children>escript::escriptParams.getTOO_MANY_NODES())) {cerr << "SIZE LIMIT EXCEEDED " << m_height << endl;resolveToIdentity();}  //#define SIZELIMIT if ((m_height>escript::escriptParams.getInt("TOO_MANY_LEVELS")) || (m_children>escript::escriptParams.getInt("TOO_MANY_NODES"))) {cerr << "SIZE LIMIT EXCEEDED " << m_height << endl;resolveToIdentity();}
44    
45    
46  #define SIZELIMIT if (m_height>escript::escriptParams.getTOO_MANY_LEVELS())  {if (escript::escriptParams.getLAZY_VERBOSE()){cerr << "SIZE LIMIT EXCEEDED height=" << m_height << endl;}resolveToIdentity();}  #define SIZELIMIT \
47        if (m_height > escript::escriptParams.getTooManyLevels()) {\
48            if (escript::escriptParams.getLazyVerbose()) {\
49                cerr << "SIZE LIMIT EXCEEDED height=" << m_height << endl;\
50            }\
51            resolveToIdentity();\
52        }
53    
54  /*  /*
55  How does DataLazy work?  How does DataLazy work?
# Line 131  std::vector<void*> stackend(getNumberOfT Line 133  std::vector<void*> stackend(getNumberOfT
133  size_t maxstackuse=0;  size_t maxstackuse=0;
134  #endif  #endif
135    
 enum ES_opgroup  
 {  
    G_UNKNOWN,  
    G_IDENTITY,  
    G_BINARY,            // pointwise operations with two arguments  
    G_UNARY,             // pointwise operations with one argument  
    G_UNARY_P,           // pointwise operations with one argument, requiring a parameter  
    G_NP1OUT,            // non-pointwise op with one output  
    G_NP1OUT_P,          // non-pointwise op with one output requiring a parameter  
    G_TENSORPROD,        // general tensor product  
    G_NP1OUT_2P,         // non-pointwise op with one output requiring two params  
    G_REDUCTION,         // non-pointwise unary op with a scalar output  
    G_CONDEVAL  
 };  
   
   
   
   
 string ES_opstrings[]={"UNKNOWN","IDENTITY","+","-","*","/","^",  
                         "sin","cos","tan",  
                         "asin","acos","atan","sinh","cosh","tanh","erf",  
                         "asinh","acosh","atanh",  
                         "log10","log","sign","abs","neg","pos","exp","sqrt",  
                         "1/","where>0","where<0","where>=0","where<=0", "where<>0","where=0",  
                         "symmetric","nonsymmetric",  
                         "prod",  
                         "transpose", "trace",  
                         "swapaxes",  
                         "minval", "maxval",  
                         "condEval"};  
 int ES_opcount=44;  
 ES_opgroup opgroups[]={G_UNKNOWN,G_IDENTITY,G_BINARY,G_BINARY,G_BINARY,G_BINARY, G_BINARY,  
                         G_UNARY,G_UNARY,G_UNARY, //10  
                         G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,        // 17  
                         G_UNARY,G_UNARY,G_UNARY,                                        // 20  
                         G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY,        // 28  
                         G_UNARY,G_UNARY,G_UNARY,G_UNARY,G_UNARY, G_UNARY_P, G_UNARY_P,          // 35  
                         G_NP1OUT,G_NP1OUT,  
                         G_TENSORPROD,  
                         G_NP1OUT_P, G_NP1OUT_P,  
                         G_NP1OUT_2P,  
                         G_REDUCTION, G_REDUCTION,  
                         G_CONDEVAL};  
 inline  
 ES_opgroup  
 getOpgroup(ES_optype op)  
 {  
   return opgroups[op];  
 }  
136    
137  // return the FunctionSpace of the result of "left op right"  // return the FunctionSpace of the result of "left op right"
138  FunctionSpace  FunctionSpace
# Line 432  GTPShape(DataAbstract_ptr left, DataAbst Line 385  GTPShape(DataAbstract_ptr left, DataAbst
385    
386  }       // end anonymous namespace  }       // end anonymous namespace
387    
   
   
 // Return a string representing the operation  
 const std::string&  
 opToString(ES_optype op)  
 {  
   if (op<0 || op>=ES_opcount)  
   {  
     op=UNKNOWNOP;  
   }  
   return ES_opstrings[op];  
 }  
   
388  void DataLazy::LazyNodeSetup()  void DataLazy::LazyNodeSetup()
389  {  {
390  #ifdef _OPENMP  #ifdef _OPENMP
# Line 962  DataLazy::collapseToReady() const Line 902  DataLazy::collapseToReady() const
902      case MAXVAL:      case MAXVAL:
903          result=left.minval();          result=left.minval();
904          break;          break;
905        case HER:
906        result=left.hermitian();
907        break;
908      default:      default:
909          throw DataException("Programmer error - collapseToReady does not know how to resolve operator "+opToString(m_op)+".");          throw DataException("Programmer error - collapseToReady does not know how to resolve operator "+opToString(m_op)+".");
910    }    }
# Line 1059  DataLazy::resolveNodeUnary(int tid, int Line 1002  DataLazy::resolveNodeUnary(int tid, int
1002    const double* left=&((*leftres)[roffset]);    const double* left=&((*leftres)[roffset]);
1003    roffset=m_samplesize*tid;    roffset=m_samplesize*tid;
1004    double* result=&(m_samples[roffset]);    double* result=&(m_samples[roffset]);
1005    escript::ESFunction operation=SINF;    if (m_op==POS)
   switch (m_op)  
1006    {    {
1007      case SIN:      // this should be prevented earlier
1008      operation=SINF;      // operation is meaningless for lazy
1009      break;          throw DataException("Programmer error - POS not supported for lazy data.");    
     case COS:  
         operation=COSF;  
     break;  
     case TAN:  
         operation=TANF;  
     break;  
     case ASIN:  
         operation=ASINF;  
     break;  
     case ACOS:  
         operation=ACOSF;  
     break;  
     case ATAN:  
         operation=ATANF;  
     break;  
     case SINH:  
         operation=SINHF;  
     break;  
     case COSH:  
         operation=COSHF;  
     break;  
     case TANH:  
         operation=TANHF;  
     break;  
     case ERF:  
         operation=ERFF;  
     break;  
    case ASINH:  
         operation=ASINHF;  
     break;  
    case ACOSH:  
         operation=ACOSHF;  
     break;  
    case ATANH:  
         operation=ATANHF;  
     break;  
     case LOG10:  
         operation=LOG10F;  
     break;  
     case LOG:  
         operation=LOGF;  
     break;  
     case SIGN:  
         operation=SIGNF;  
     break;  
     case ABS:  
         operation=ABSF;  
     break;  
     case NEG:  
         operation=NEGF;  
     break;  
     case POS:  
         // it doesn't mean anything for delayed.  
         // it will just trigger a deep copy of the lazy object  
         throw DataException("Programmer error - POS not supported for lazy data.");  
         break;  
     case EXP:  
         operation=EXPF;  
     break;  
     case SQRT:  
         operation=SQRTF;  
     break;  
     case RECIP:  
         operation=INVF;  
     break;  
     case GZ:  
         operation=GTZEROF;  
     break;  
     case LZ:  
         operation=LTZEROF;  
     break;  
     case GEZ:  
         operation=GEZEROF;  
     break;  
     case LEZ:  
         operation=LEZEROF;  
     break;  
 // There are actually G_UNARY_P but I don't see a compelling reason to treat them differently  
     case NEZ:  
         operation=NEQZEROF;  
     break;  
     case EZ:  
         operation=EQZEROF;  
     break;  
     default:  
         throw DataException("Programmer error - resolveUnary can not resolve operator "+opToString(m_op)+".");  
1010    }    }
1011    tensor_unary_array_operation(m_samplesize,    tensor_unary_array_operation(m_samplesize,
1012                               left,                               left,
1013                               result,                               result,
1014                               operation,                               m_op,
1015                               m_tol);                                 m_tol);  
1016    return &(m_samples);    return &(m_samples);
1017  }  }
# Line 1247  DataLazy::resolveNodeNP1OUT(int tid, int Line 1103  DataLazy::resolveNodeNP1OUT(int tid, int
1103      case NSYM:      case NSYM:
1104          for (loop=0;loop<numsteps;++loop)          for (loop=0;loop<numsteps;++loop)
1105          {          {
1106              escript::nonsymmetric(*leftres,m_left->getShape(),subroffset, m_samples, getShape(), offset);              escript::antisymmetric(*leftres,m_left->getShape(),subroffset, m_samples, getShape(), offset);
1107              subroffset+=step;              subroffset+=step;
1108              offset+=step;              offset+=step;
1109          }          }
# Line 1532  LAZYDEBUG(cout << "Right res["<< rroffse Line 1388  LAZYDEBUG(cout << "Right res["<< rroffse
1388               orightstep,               orightstep,
1389               lroffset,               lroffset,
1390               rroffset,               rroffset,
1391               escript::ESFunction::PLUSF);                 escript::ES_optype::ADD);  
1392          break;          break;
1393      case SUB:      case SUB:
1394        escript::binaryOpVectorLazyHelper<real_t, real_t, real_t>(resultp,        escript::binaryOpVectorLazyHelper<real_t, real_t, real_t>(resultp,
# Line 1548  LAZYDEBUG(cout << "Right res["<< rroffse Line 1404  LAZYDEBUG(cout << "Right res["<< rroffse
1404               orightstep,               orightstep,
1405               lroffset,               lroffset,
1406               rroffset,               rroffset,
1407               escript::ESFunction::MINUSF);                       escript::ES_optype::SUB);        
1408          //PROC_OP(NO_ARG,minus<double>());          //PROC_OP(NO_ARG,minus<double>());
1409          break;          break;
1410      case MUL:      case MUL:
# Line 1566  LAZYDEBUG(cout << "Right res["<< rroffse Line 1422  LAZYDEBUG(cout << "Right res["<< rroffse
1422               orightstep,               orightstep,
1423               lroffset,               lroffset,
1424               rroffset,               rroffset,
1425               escript::ESFunction::MULTIPLIESF);                     escript::ES_optype::MUL);        
1426          break;          break;
1427      case DIV:      case DIV:
1428          //PROC_OP(NO_ARG,divides<double>());          //PROC_OP(NO_ARG,divides<double>());
# Line 1583  LAZYDEBUG(cout << "Right res["<< rroffse Line 1439  LAZYDEBUG(cout << "Right res["<< rroffse
1439               orightstep,               orightstep,
1440               lroffset,               lroffset,
1441               rroffset,               rroffset,
1442               escript::ESFunction::DIVIDESF);                         escript::ES_optype::DIV);        
1443          break;          break;
1444      case POW:      case POW:
1445         //PROC_OP(double (double,double),::pow);         //PROC_OP(double (double,double),::pow);
# Line 1600  LAZYDEBUG(cout << "Right res["<< rroffse Line 1456  LAZYDEBUG(cout << "Right res["<< rroffse
1456               orightstep,               orightstep,
1457               lroffset,               lroffset,
1458               rroffset,               rroffset,
1459               escript::ESFunction::POWF);                         escript::ES_optype::POW);        
1460          break;          break;
1461      default:      default:
1462          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 1878  DataLazy::toString() const Line 1734  DataLazy::toString() const
1734  {  {
1735    ostringstream oss;    ostringstream oss;
1736    oss << "Lazy Data: [depth=" << m_height<< "] ";    oss << "Lazy Data: [depth=" << m_height<< "] ";
1737    switch (escriptParams.getLAZY_STR_FMT())    switch (escriptParams.getLazyStrFmt())
1738    {    {
1739    case 1:       // tree format    case 1:       // tree format
1740          oss << endl;          oss << endl;
# Line 2039  DataLazy::deepCopy() const Line 1895  DataLazy::deepCopy() const
1895    }    }
1896  }  }
1897    
1898    // For this, we don't care what op you were doing because the answer is now zero
1899    DataAbstract*
1900    DataLazy::zeroedCopy() const
1901    {
1902      return new DataLazy(m_id->zeroedCopy()->getPtr());
1903    }
1904    
1905  // There is no single, natural interpretation of getLength on DataLazy.  // There is no single, natural interpretation of getLength on DataLazy.
1906  // Instances of DataReady can look at the size of their vectors.  // Instances of DataReady can look at the size of their vectors.

Legend:
Removed from v.6112  
changed lines
  Added in v.6511

  ViewVC Help
Powered by ViewVC 1.1.26