/[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 2776 by jfenwick, Wed Nov 25 01:24:51 2009 UTC revision 2777 by jfenwick, Thu Nov 26 01:06:00 2009 UTC
# Line 109  namespace escript Line 109  namespace escript
109  namespace  namespace
110  {  {
111    
112    
113    // enabling this will print out when ever the maximum stacksize used by resolve increases
114    // it assumes _OPENMP is also in use
115    //#define LAZY_STACK_PROF
116    
117    
118    
119    #ifndef _OPENMP
120      #ifdef LAZY_STACK_PROF
121      #undef LAZY_STACK_PROF
122      #endif
123    #endif
124    
125    
126    #ifdef LAZY_STACK_PROF
127    std::vector<void*> stackstart(getNumberOfThreads());
128    std::vector<void*> stackend(getNumberOfThreads());
129    size_t maxstackuse=0;
130    #endif
131    
132  enum ES_opgroup  enum ES_opgroup
133  {  {
134     G_UNKNOWN,     G_UNKNOWN,
# Line 930  LAZYDEBUG(cout << "Resolve sample " << t Line 950  LAZYDEBUG(cout << "Resolve sample " << t
950    {    {
951      const ValueType& vec=m_id->getVectorRO();      const ValueType& vec=m_id->getVectorRO();
952      roffset=m_id->getPointOffset(sampleNo, 0);      roffset=m_id->getPointOffset(sampleNo, 0);
953    #ifdef LAZY_STACK_PROF
954    int x;
955    if (&x<stackend[omp_get_thread_num()])
956    {
957           stackend[omp_get_thread_num()]=&x;
958    }
959    #endif
960      return &(vec);      return &(vec);
961    }    }
962    if (m_readytype!='E')    if (m_readytype!='E')
# Line 1505  DataLazy::resolveSample(int sampleNo, si Line 1532  DataLazy::resolveSample(int sampleNo, si
1532  #else  #else
1533      int tid=0;      int tid=0;
1534  #endif  #endif
1535    
1536    #ifdef LAZY_STACK_PROF
1537        stackstart[tid]=&tid;
1538        stackend[tid]=&tid;
1539        const DataTypes::ValueType* r=resolveNodeSample(tid, sampleNo, roffset);
1540        size_t d=(size_t)stackstart[tid]-(size_t)stackend[tid];
1541        #pragma omp critical
1542        if (d>maxstackuse)
1543        {
1544    cout << "Max resolve Stack use " << d << endl;
1545            maxstackuse=d;
1546        }
1547        return r;
1548    #else
1549      return resolveNodeSample(tid, sampleNo, roffset);      return resolveNodeSample(tid, sampleNo, roffset);
1550    #endif
1551  }  }
1552    
1553    
# Line 1565  DataLazy::resolveNodeWorker() Line 1607  DataLazy::resolveNodeWorker()
1607    int totalsamples=getNumSamples();    int totalsamples=getNumSamples();
1608    const ValueType* res=0;   // Storage for answer    const ValueType* res=0;   // Storage for answer
1609  LAZYDEBUG(cout << "Total number of samples=" <<totalsamples << endl;)  LAZYDEBUG(cout << "Total number of samples=" <<totalsamples << endl;)
1610    #pragma omp parallel for private(sample,res) schedule(static)    #pragma omp parallel private(sample,res)
   for (sample=0;sample<totalsamples;++sample)  
1611    {    {
1612      size_t roffset=0;      size_t roffset=0;
1613    #ifdef LAZY_STACK_PROF
1614        stackstart[omp_get_thread_num()]=&roffset;
1615        stackend[omp_get_thread_num()]=&roffset;
1616    #endif
1617        #pragma omp for schedule(static)
1618        for (sample=0;sample<totalsamples;++sample)
1619        {
1620            roffset=0;
1621  #ifdef _OPENMP  #ifdef _OPENMP
1622      res=resolveNodeSample(omp_get_thread_num(),sample,roffset);              res=resolveNodeSample(omp_get_thread_num(),sample,roffset);
1623  #else  #else
1624      res=resolveNodeSample(0,sample,roffset);              res=resolveNodeSample(0,sample,roffset);
1625  #endif  #endif
1626  LAZYDEBUG(cout << "Sample #" << sample << endl;)  LAZYDEBUG(cout << "Sample #" << sample << endl;)
1627  LAZYDEBUG(cout << "Final res[" << roffset<< "]=" << (*res)[roffset] << (*res)[roffset]<< endl; )  LAZYDEBUG(cout << "Final res[" << roffset<< "]=" << (*res)[roffset] << (*res)[roffset]<< endl; )
1628      DataVector::size_type outoffset=result->getPointOffset(sample,0);              DataVector::size_type outoffset=result->getPointOffset(sample,0);
1629      memcpy(&(resvec[outoffset]),&((*res)[roffset]),m_samplesize*sizeof(DataVector::ElementType));              memcpy(&(resvec[outoffset]),&((*res)[roffset]),m_samplesize*sizeof(DataVector::ElementType));
1630        }
1631      }
1632    #ifdef LAZY_STACK_PROF
1633      for (int i=0;i<getNumberOfThreads();++i)
1634      {
1635        size_t r=((size_t)stackstart[i] - (size_t)stackend[i]);
1636    //  cout << i << " " << stackstart[i] << " .. " << stackend[i] << " = " <<  r << endl;
1637        if (r>maxstackuse)
1638        {
1639            maxstackuse=r;
1640        }
1641    }    }
1642      cout << "Max resolve Stack use=" << maxstackuse << endl;
1643    #endif
1644    return resptr;    return resptr;
1645  }  }
1646    

Legend:
Removed from v.2776  
changed lines
  Added in v.2777

  ViewVC Help
Powered by ViewVC 1.1.26