/[escript]/branches/arrexp_2137_win_merge/escript/src/Data.h
ViewVC logotype

Diff of /branches/arrexp_2137_win_merge/escript/src/Data.h

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

revision 2221 by jfenwick, Mon Jan 19 06:11:25 2009 UTC revision 2222 by jfenwick, Tue Jan 20 04:52:39 2009 UTC
# Line 29  Line 29 
29    
30  extern "C" {  extern "C" {
31  #include "DataC.h"  #include "DataC.h"
 /* #include "paso/Paso.h" doesn't belong in this file...causes trouble for BruceFactory.cpp */  
32  }  }
33    
34  #include "esysmpi.h"  #include "esysmpi.h"
# Line 376  class Data { Line 375  class Data {
375    
376    
377    /**    /**
378       \brief Ensures data is ready for write access.
379      This means that the data will be resolved if lazy and will be copied if shared with another Data object.
380      \warning This method should only be called in single threaded sections of code. (It modifies m_data).
381      Do not create any Data objects from this one between calling requireWrite and getSampleDataRW.
382      Doing so might introduce additional sharing.
383      */
384      ESCRIPT_DLL_API
385      void
386      requireWrite();
387    
388      /**
389       \brief       \brief
390       Return true if this Data is expanded.       Return true if this Data is expanded.
391       \note To determine if a sample will contain separate values for each datapoint. Use actsExpanded instead.       \note To determine if a sample will contain separate values for each datapoint. Use actsExpanded instead.
# Line 1456  contains datapoints. Line 1466  contains datapoints.
1466     Allocates a DataVector large enough for DataLazy::resolveSample to operate on for the current Data.     Allocates a DataVector large enough for DataLazy::resolveSample to operate on for the current Data.
1467     Do not use this buffer for other Data instances (unless you are sure they will be the same size).     Do not use this buffer for other Data instances (unless you are sure they will be the same size).
1468        
1469       In multi-threaded sections, this needs to be called on each thread.
1470    
1471     \return A DataVector* if Data is lazy, NULL otherwise.     \return A DataVector* if Data is lazy, NULL otherwise.
1472     \warning This pointer must be deallocated using freeSampleBuffer to avoid cross library memory issues.     \warning This pointer must be deallocated using freeSampleBuffer to avoid cross library memory issues.
1473  */  */
# Line 1635  ESCRIPT_DLL_API void freeSampleBuffer(Da Line 1647  ESCRIPT_DLL_API void freeSampleBuffer(Da
1647    
1648    /**    /**
1649    \brief if another object is sharing out member data make a copy to work with instead.    \brief if another object is sharing out member data make a copy to work with instead.
1650      This code should only be called from single threaded sections of code.
1651    */    */
1652    void exclusiveWrite()    void exclusiveWrite()
1653    {    {
# Line 1646  ESCRIPT_DLL_API void freeSampleBuffer(Da Line 1659  ESCRIPT_DLL_API void freeSampleBuffer(Da
1659  //  }  //  }
1660      if (isShared())      if (isShared())
1661      {      {
1662         #pragma OMP CRITICAL          DataAbstract* t=m_data->deepCopy();
1663         {          set_m_data(DataAbstract_ptr(t));
         if (isShared())  
         {  
             DataAbstract* t=m_data->deepCopy();  
             set_m_data(DataAbstract_ptr(t));  
         }  
        }  
1664      }      }
1665    }    }
1666    
# Line 1738  inline Line 1745  inline
1745  DataAbstract::ValueType::value_type*  DataAbstract::ValueType::value_type*
1746  Data::getSampleDataRW(DataAbstract::ValueType::size_type sampleNo)  Data::getSampleDataRW(DataAbstract::ValueType::size_type sampleNo)
1747  {  {
1748    //    if (isLazy())
1749    //    {
1750    //  resolve();
1751    //    }
1752    //    exclusiveWrite();
1753     if (isLazy())     if (isLazy())
1754     {     {
1755      resolve();      throw DataException("Error, attempt to acquire RW access to lazy data. Please call requireWrite() first.");
1756     }     }
    exclusiveWrite();  
1757     return getReady()->getSampleData(sampleNo);     return getReady()->getSampleData(sampleNo);
1758  }  }
1759    
# Line 1756  Data::getSampleDataRO(DataAbstract::Valu Line 1767  Data::getSampleDataRO(DataAbstract::Valu
1767      size_t offset=0;      size_t offset=0;
1768      if (buffer==NULL)      if (buffer==NULL)
1769      {      {
1770          throw DataException("Error attempt to getSampleDataRO for lazy Data with buffer==NULL");          throw DataException("Error, attempt to getSampleDataRO for lazy Data with buffer==NULL");
1771      }      }
1772      const DataTypes::ValueType* res=l->resolveSample(*buffer,0,sampleNo,offset);      const DataTypes::ValueType* res=l->resolveSample(*buffer,0,sampleNo,offset);
1773      return &((*res)[offset]);      return &((*res)[offset]);

Legend:
Removed from v.2221  
changed lines
  Added in v.2222

  ViewVC Help
Powered by ViewVC 1.1.26