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

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

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

revision 2798 by jfenwick, Wed Dec 2 02:39:23 2009 UTC revision 2799 by jfenwick, Thu Dec 3 01:35:08 2009 UTC
# Line 1594  DataLazy::resolve() Line 1594  DataLazy::resolve()
1594      return m_id;      return m_id;
1595  }  }
1596    
1597    
1598    /* This is really a static method but I think that caused problems in windows */
1599    void
1600    DataLazy::resolveGroupWorker(std::vector<DataLazy*>& dats)
1601    {
1602      if (dats.empty())
1603      {
1604        return;
1605      }
1606      vector<DataLazy*> work;
1607      FunctionSpace fs=dats[0]->getFunctionSpace();
1608      bool match=true;
1609      for (int i=dats.size()-1;i>0;--i)
1610      {
1611        if (dats[i]->m_readytype!='E')
1612        {
1613            dats[i]->collapse();
1614        }
1615        if (dats[i]->m_op!=IDENTITY)
1616        {
1617            work.push_back(dats[i]);
1618            if (fs!=dats[i]->getFunctionSpace())
1619            {
1620                match=false;
1621            }
1622        }
1623      }
1624      if (work.empty())
1625      {
1626        return;     // no work to do
1627      }
1628      if (match)    // all functionspaces match.  Yes I realise this is overly strict
1629      {     // it is possible that dats[0] is one of the objects which we discarded and
1630            // all the other functionspaces match.
1631        vector<DataExpanded*> dep;
1632        vector<ValueType*> vecs;
1633        for (int i=0;i<work.size();++i)
1634        {
1635            dep.push_back(new DataExpanded(fs,work[i]->getShape(), ValueType(work[i]->getNoValues())));
1636            vecs.push_back(&(dep[i]->getVectorRW()));
1637        }
1638        int totalsamples=work[0]->getNumSamples();
1639        const ValueType* res=0; // Storage for answer
1640        int sample;
1641        #pragma omp parallel private(sample, res)
1642        {
1643            size_t roffset=0;
1644            #pragma omp for schedule(static)
1645            for (sample=0;sample<totalsamples;++sample)
1646            {
1647            roffset=0;
1648            int j;
1649            for (j=work.size()-1;j>0;--j)
1650            {
1651    #ifdef _OPENMP
1652                    res=work[j]->resolveNodeSample(omp_get_thread_num(),sample,roffset);
1653    #else
1654                    res=work[j]->resolveNodeSample(0,sample,roffset);
1655    #endif
1656                    DataVector::size_type outoffset=dep[j]->getPointOffset(sample,0);
1657                    memcpy(&((*vecs[j])[outoffset]),&((*res)[roffset]),work[j]->m_samplesize*sizeof(DataVector::ElementType));
1658            }
1659            }
1660        }
1661        // Now we need to load the new results as identity ops into the lazy nodes
1662        for (int i=work.size()-1;i>0;--i)
1663        {
1664            work[i]->makeIdentity(boost::dynamic_pointer_cast<DataReady>(dep[i]->getPtr()));
1665        }
1666      }
1667      else  // functionspaces do not match
1668      {
1669        for (int i=0;i<work.size();++i)
1670        {
1671            work[i]->resolveToIdentity();
1672        }
1673      }
1674    }
1675    
1676    
1677    
1678  // This version of resolve uses storage in each node to hold results  // This version of resolve uses storage in each node to hold results
1679  DataReady_ptr  DataReady_ptr
1680  DataLazy::resolveNodeWorker()  DataLazy::resolveNodeWorker()

Legend:
Removed from v.2798  
changed lines
  Added in v.2799

  ViewVC Help
Powered by ViewVC 1.1.26