/[escript]/branches/arrexp_2137_win/escript/src/DataReady.h
ViewVC logotype

Contents of /branches/arrexp_2137_win/escript/src/DataReady.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2212 - (show annotations)
Wed Jan 14 00:15:00 2009 UTC (11 years, 5 months ago) by jfenwick
File MIME type: text/plain
File size: 2722 byte(s)
Executive summary:

This commit adds copy on write checks to operations involving shared data. 

Changes:

new #defines:
~~~~~~~~~~~~~
Data.cpp has ASSIGNMENT_MEANS_DEEPCOPY (defaults to undefined).
Defining this will put the data = operator back to making deep copies instead
of sharing data (now the default.)

Data:
~~~~~
. Added exclusiveWrite method to copy the underlying data if it is shared.
. Some operators which took python objects now call the c++ versions intead of duplicating code.

DataAbstract and offspring:
~~~~~~~~~~~~~~~~~~~~~~~~~~~
. Added method to determine whether the data is currently shared.
. Added getVectorRO to children of DataReady.
. Added getTagRO.

. Operations which modify values in place (or return modifiable pointers) now use
a macro to check for sharing. In the case where a modification attempt is detected, it throws an exception. In the future, I will enable this only for debugging.

. This shold not really have been required but the compiler was not choosing the use the const version as I would have liked. Besides, this makes things explict.

. Moved (and de-inlined) getVector in DataConstant (It was virtual in a parent class).

Unit tests:
~~~~~~~~~~~
Added both python and c++ unit tests to check known cases of sharing and "inplace"
modification operations.

General:
~~~~~~~~
Removed some commented out code.

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2008 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 #if !defined escript_DataReady_20081008_H
16 #define escript_DataReady_20081008_H
17 #include "system_dep.h"
18
19 #include "DataAbstract.h"
20
21 namespace escript {
22
23 // Anything which requires getVector should be moved down here
24
25
26
27 /**
28 \class DataReady ...Purpose...
29 */
30 class DataReady : public DataAbstract
31 {
32 typedef DataAbstract parent;
33 public:
34 DataReady(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty=false);
35 ~DataReady(){};
36
37
38
39 /**
40 \brief
41 Return the sample data for the given sample number.
42 */
43 ESCRIPT_DLL_API
44 double*
45 getSampleData(ValueType::size_type sampleNo);
46
47 /**
48 This function is required primarily for LazyData. For ReadyData it returns 1. (Behaviour subject to change).
49 */
50 ESCRIPT_DLL_API
51 size_t
52 getSampleBufferSize() const
53 {
54 return 1;
55 }
56
57 /**
58 \brief Provide access to underlying storage. Internal use only!
59 */
60 ESCRIPT_DLL_API
61 virtual DataTypes::ValueType&
62 getVector()=0;
63
64 ESCRIPT_DLL_API
65 virtual const DataTypes::ValueType&
66 getVector() const=0;
67
68 ESCRIPT_DLL_API
69 virtual const DataTypes::ValueType&
70 getVectorRO() const=0;
71
72
73 /**
74 \brief
75 Copy the specified region from the given object.
76
77 \param value - Input - Data to copy from
78 \param region - Input - Region to copy.
79 */
80 ESCRIPT_DLL_API
81 virtual
82 void
83 setSlice(const DataAbstract* value,
84 const DataTypes::RegionType& region) = 0;
85
86
87 /**
88 \brief get a reference to the beginning of a data point
89 */
90 ESCRIPT_DLL_API
91 DataTypes::ValueType::const_reference
92 getDataAtOffset(DataTypes::ValueType::size_type i) const;
93
94
95 ESCRIPT_DLL_API
96 DataTypes::ValueType::reference
97 getDataAtOffset(DataTypes::ValueType::size_type i);
98
99 ESCRIPT_DLL_API
100 DataReady_ptr
101 resolve();
102
103 };
104
105
106 inline
107 DataAbstract::ValueType::value_type*
108 DataReady::getSampleData(ValueType::size_type sampleNo)
109 {
110 return &(getVector()[getPointOffset(sampleNo,0)]); // exclusive write checks will be done in getVector()
111 }
112
113
114 inline
115 DataTypes::ValueType::const_reference
116 DataReady::getDataAtOffset(DataTypes::ValueType::size_type i) const
117 {
118 return getVector()[i];
119 }
120
121 inline
122 DataTypes::ValueType::reference
123 DataReady::getDataAtOffset(DataTypes::ValueType::size_type i) // exclusive write checks will be done in getVector()
124 {
125 return getVector()[i];
126 }
127
128
129
130 }
131
132 #endif

  ViewVC Help
Powered by ViewVC 1.1.26