/[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 6083 by jfenwick, Tue Mar 22 03:30:18 2016 UTC revision 6174 by caltinay, Fri Apr 15 03:41:03 2016 UTC
# Line 5  Line 5 
5  * http://www.uq.edu.au  * http://www.uq.edu.au
6  *  *
7  * Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
8  * Licensed under the Open Software License version 3.0  * Licensed under the Apache License, version 2.0
9  * http://www.opensource.org/licenses/osl-3.0.php  * http://www.apache.org/licenses/LICENSE-2.0
10  *  *
11  * Development until 2012 by Earth Systems Science Computational Center (ESSCC)  * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12  * Development 2012-2013 by School of Earth Sciences  * Development 2012-2013 by School of Earth Sciences
# Line 20  Line 20 
20  #include "EscriptParams.h"  #include "EscriptParams.h"
21  #include "FunctionSpace.h"  #include "FunctionSpace.h"
22  #include "Utils.h"  #include "Utils.h"
23  #include "DataMaths.h"  #include "DataVectorOps.h"
   
 #ifdef USE_NETCDF  
 #include <netcdfcpp.h>  
 #endif  
24    
25  #include <iomanip> // for some fancy formatting in debug  #include <iomanip> // for some fancy formatting in debug
26    
# 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 478  DataLazy::DataLazy(DataAbstract_ptr p) Line 418  DataLazy::DataLazy(DataAbstract_ptr p)
418     }     }
419     else     else
420     {     {
         p->makeLazyShared();  
421          DataReady_ptr dr=dynamic_pointer_cast<DataReady>(p);          DataReady_ptr dr=dynamic_pointer_cast<DataReady>(p);
422          makeIdentity(dr);          makeIdentity(dr);
423  LAZYDEBUG(cout << "Wrapping " << dr.get() << " id=" << m_id.get() << endl;)  LAZYDEBUG(cout << "Wrapping " << dr.get() << " id=" << m_id.get() << endl;)
# Line 943  DataLazy::collapseToReady() const Line 882  DataLazy::collapseToReady() const
882          result=left.symmetric();          result=left.symmetric();
883          break;          break;
884      case NSYM:      case NSYM:
885          result=left.nonsymmetric();          result=left.antisymmetric();
886          break;          break;
887      case PROD:      case PROD:
888          result=C_GeneralTensorProduct(left,right,m_axis_offset, m_transpose);          result=C_GeneralTensorProduct(left,right,m_axis_offset, m_transpose);
# Line 963  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 1060  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 1248  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 1533  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 1549  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 1567  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 1584  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 1601  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 1879  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;

Legend:
Removed from v.6083  
changed lines
  Added in v.6174

  ViewVC Help
Powered by ViewVC 1.1.26