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

Contents of /trunk/escript/src/DataAbstract.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2742 - (show annotations)
Thu Nov 12 06:03:37 2009 UTC (9 years, 10 months ago) by jfenwick
File size: 7935 byte(s)
Merging changes from the lapack branch.

The inverse() operation has been moved into c++. [No lazy support for this operation yet.]
Optional Lapack support has been added for matrices larger than 3x3. 
service0 is set to use mkl_lapack.



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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26