/[escript]/branches/arrexp_2137_win_merge/escript/src/DataAbstract.cpp
ViewVC logotype

Contents of /branches/arrexp_2137_win_merge/escript/src/DataAbstract.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2221 - (show annotations)
Mon Jan 19 06:11:25 2009 UTC (10 years, 7 months ago) by jfenwick
File size: 7003 byte(s)
A second attempt at a thread-safe COW

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 #include "DataAbstract.h"
16 #include "DataException.h"
17 #include "DataLazy.h"
18
19 #include "Data.h" // So we can update the shared status when things change
20
21 using namespace std;
22
23 namespace escript {
24
25 DataAbstract_ptr DataAbstract::getPtr()
26 {
27 if (_internal_weak_this.expired())
28 {
29 return DataAbstract_ptr(this);
30 }
31 else
32 {
33 return shared_from_this();
34 }
35 }
36
37 const_DataAbstract_ptr DataAbstract::getPtr() const
38 {
39 if (_internal_weak_this.expired())
40 {
41 return const_DataAbstract_ptr(this);
42 }
43 else
44 {
45 return shared_from_this();
46 }
47 }
48
49
50 // Warning - this method uses .use_count() which the boost doco labels inefficient.
51 // If this method needs to be called in debug contexts, we may need to do some
52 // timing experiments to determine how inefficient and possibly switch over to
53 // invasive pointers which can answer these questions faster
54 bool DataAbstract::checkNoSharing() const
55 {
56
57 return m_owners.size()<2;
58
59 /* if (_internal_weak_this.expired()) // there is no shared_ptr for this object yet
60 {
61 return true;
62 }
63 if (shared_from_this().use_count()==2) // shared_from_this will increase the ref count
64 { // which is the reason .unique is no use.
65 return true;
66 }
67 std::cerr << "-<"<<shared_from_this().use_count() << ">-" << endl;
68 return false;*/
69 }
70
71 bool
72 DataAbstract::isLazy() const
73 {
74 return (dynamic_cast<const DataLazy*>(this)!=0);
75 }
76
77
78
79 DataAbstract::DataAbstract(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty):
80 m_noSamples(what.getNumSamples()),
81 m_noDataPointsPerSample(what.getNumDPPSample()),
82 m_functionSpace(what),
83 m_shape(shape),
84 m_novalues(DataTypes::noValues(shape)),
85 m_rank(DataTypes::getRank(shape)),
86 m_lazyshared(false)
87
88 {
89 m_isempty=isDataEmpty;
90 if (m_rank>ESCRIPT_MAX_DATA_RANK)
91 {
92 ostringstream os;
93 os << "Error - Attempt to create a rank " << m_rank
94 << " object. The maximum rank is " << ESCRIPT_MAX_DATA_RANK << ".";
95 throw DataException(os.str());
96 }
97 }
98
99 DataAbstract::~DataAbstract()
100 {
101 }
102
103
104 void
105 DataAbstract::operandCheck(const DataAbstract& right) const
106 {
107 if ((right.getNumDPPSample()!=getNumDPPSample()) ||
108 (right.getNumSamples()!=getNumSamples()) ||
109 (right.getFunctionSpace()!=getFunctionSpace())) {
110 stringstream temp;
111 temp << "Error - Right hand argument sample shape or function space "
112 << "incompatible with left." << endl
113 << "LHS: (" << getNumSamples() << ","
114 << getNumDPPSample() << ") " << getFunctionSpace().toString()
115 << endl
116 << "RHS: (" << right.getNumSamples() << ","
117 << right.getNumDPPSample() << ") "
118 << right.getFunctionSpace().toString();
119 throw DataException(temp.str());
120 }
121
122 //
123 // Check the shape of the point data, a rank of 0(scalar) is okay
124 if (!((right.getRank()==0) || (getRank()==0) ||
125 (right.getShape()==getShape())))
126 {
127 stringstream temp;
128 temp << "Error - Right hand argument point data shape: "
129 << DataTypes::shapeToString(right.getShape())
130 << " doesn't match left: "
131 << DataTypes::shapeToString(getShape());
132 throw DataException(temp.str());
133 }
134 }
135
136 void
137 DataAbstract::dump(const std::string fileName) const
138 {
139 throw DataException("Error - DataAbstract::dump: not implemented.");
140 }
141
142
143
144 DataAbstract::ValueType::value_type*
145 DataAbstract::getSampleDataByTag(int tag)
146 {
147 throw DataException("Error - DataAbstract::getSampleDataByTag: Data type does not have tag values.");
148 }
149
150
151 void
152 DataAbstract::setTaggedValue(int tagKey,
153 const DataTypes::ShapeType& pointshape,
154 const DataTypes::ValueType& value,
155 int dataOffset)
156 {
157 throw DataException("Error - DataAbstract::setTaggedValue: Data type does not have tag values.");
158 }
159
160
161 int
162 DataAbstract::getTagNumber(int dpno)
163 {
164 throw DataException("Error - DataAbstract::getTagNumber: Data type cannot be accessed by tag values.");
165 return (0);
166 }
167
168 void
169 DataAbstract::copyToDataPoint(const int sampleNo, const int dataPointNo, const double value)
170 {
171 throw DataException("Error - DataAbstract::copying data from double value to a single data point is not supported.");
172 }
173
174
175 void
176 DataAbstract::copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value)
177 {
178 throw DataException("Error - DataAbstract::copying data from WrappedArray objects to a single data point is not supported.");
179 }
180
181
182 void
183 DataAbstract::symmetric(DataAbstract* ev)
184 {
185 throw DataException("Error - DataAbstract::symmetric is not supported.");
186 }
187
188 void
189 DataAbstract::nonsymmetric(DataAbstract* ev)
190 {
191 throw DataException("Error - DataAbstract::nonsymmetric is not supported.");
192 }
193
194 void
195 DataAbstract::trace(DataAbstract* ev, int axis_offset)
196 {
197 throw DataException("Error - DataAbstract::trace is not supported.");
198 }
199
200 void
201 DataAbstract::swapaxes(DataAbstract* ev, int axis0, int axis1)
202 {
203 throw DataException("Error - DataAbstract::component swapaxes is not supported.");
204 }
205 void
206 DataAbstract::transpose(DataAbstract* ev, int axis_offset)
207 {
208 throw DataException("Error - DataAbstract::transpose is not supported.");
209 }
210
211 void
212 DataAbstract::eigenvalues(DataAbstract* ev)
213 {
214 throw DataException("Error - DataAbstract::eigenvalues is not supported.");
215 }
216 void
217 DataAbstract::eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol)
218 {
219 throw DataException("Error - DataAbstract::eigenvalues_and_eigenvectors is not supported.");
220
221 }
222 void
223 DataAbstract::setToZero()
224 {
225 throw DataException("Error - DataAbstract:: cannot set values to zero.");
226 }
227
228 void
229 DataAbstract::reorderByReferenceIDs(int *reference_ids)
230 {
231 throw DataException("Error - DataAbstract:: cannot reorder by reference ids.");
232 }
233
234
235 void DataAbstract::addOwner(Data* d)
236 {
237 for (size_t i=0;i<m_owners.size();++i)
238 {
239 if (m_owners[i]==d)
240 {
241 return;
242 }
243 }
244 m_owners.push_back(d);
245 // cerr << "Adding " << d << " as an owner of " << this << " now O=" << m_owners.size() << endl;
246 if (m_owners.size()==2) // Means it used to be 1 so we need to tell people
247 {
248 for (size_t i=0;i<m_owners.size();++i)
249 {
250 m_owners[i]->updateShareStatus(true);
251 }
252 }
253 /*
254 for (size_t i=0;i<m_owners.size();++i)
255 {
256 m_owners[i]->updateShareStatus(true);
257 cerr << m_owners[i] << " ";
258 }
259 cerr << endl;*/
260
261
262 }
263
264 void DataAbstract::removeOwner(Data* d)
265 {
266 for (size_t i=0;i<m_owners.size();++i)
267 {
268 if (m_owners[i]==d)
269 {
270 m_owners.erase(m_owners.begin()+i,m_owners.begin()+(i+1)); // remove the element
271 break;
272 }
273 }
274 if (m_owners.size()==1) // Means it used to be 2 so we need to tell people
275 {
276 m_owners[0]->updateShareStatus(false);
277 }
278 }
279
280
281 } // end of namespace

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26