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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3911 - (hide annotations)
Thu Jun 14 01:01:03 2012 UTC (7 years, 5 months ago) by jfenwick
File size: 7934 byte(s)
Copyright changes
1 jgs 82
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
4 jfenwick 3911 * Copyright (c) 2003-2012 by University of Queensland
5 ksteube 1811 * 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 ksteube 1312
14 ksteube 1811
15 jgs 474 #include "DataAbstract.h"
16     #include "DataException.h"
17 jfenwick 2005 #include "DataLazy.h"
18 jgs 82
19 jfenwick 2271 #include "Data.h" // So we can update the shared status when things change
20    
21 jgs 82 using namespace std;
22    
23     namespace escript {
24    
25 jfenwick 2436 // 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 jfenwick 1872 DataAbstract_ptr DataAbstract::getPtr()
37     {
38 jfenwick 2436 try
39 jfenwick 1872 {
40 jfenwick 2436 return shared_from_this();
41 jfenwick 1872 }
42 jfenwick 2436 catch (boost::bad_weak_ptr p)
43 jfenwick 1872 {
44 jfenwick 2436 return DataAbstract_ptr(this);
45 jfenwick 1872 }
46     }
47    
48     const_DataAbstract_ptr DataAbstract::getPtr() const
49     {
50 jfenwick 2436 try
51 jfenwick 1872 {
52 jfenwick 2436 return shared_from_this();
53 jfenwick 1872 }
54 jfenwick 2436 catch (boost::bad_weak_ptr p)
55 jfenwick 1872 {
56 jfenwick 2436 return const_DataAbstract_ptr(this);
57 jfenwick 1872 }
58     }
59    
60 jfenwick 2271
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 jfenwick 2005 bool
83     DataAbstract::isLazy() const
84     {
85     return (dynamic_cast<const DataLazy*>(this)!=0);
86     }
87 jfenwick 1872
88    
89 jfenwick 2005
90 jfenwick 1803 DataAbstract::DataAbstract(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty):
91 jfenwick 1946 m_noSamples(what.getNumSamples()),
92 jgs 82 m_noDataPointsPerSample(what.getNumDPPSample()),
93 jfenwick 1796 m_functionSpace(what),
94     m_shape(shape),
95 jfenwick 1946 m_novalues(DataTypes::noValues(shape)),
96 jfenwick 2271 m_rank(DataTypes::getRank(shape)),
97     m_lazyshared(false)
98 jfenwick 1946
99 jgs 82 {
100 jfenwick 1803 m_isempty=isDataEmpty;
101 jfenwick 2086 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 jgs 82 }
109    
110     DataAbstract::~DataAbstract()
111     {
112     }
113    
114    
115 jgs 119 void
116 jgs 82 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 jfenwick 2084 if (!((right.getRank()==0) || (getRank()==0) ||
136 jfenwick 1796 (right.getShape()==getShape())))
137 jgs 82 {
138     stringstream temp;
139     temp << "Error - Right hand argument point data shape: "
140 jfenwick 1796 << DataTypes::shapeToString(right.getShape())
141 jgs 82 << " doesn't match left: "
142 jfenwick 1796 << DataTypes::shapeToString(getShape());
143 jgs 82 throw DataException(temp.str());
144     }
145     }
146    
147 gross 950 void
148     DataAbstract::dump(const std::string fileName) const
149     {
150 jfenwick 1803 throw DataException("Error - DataAbstract::dump: not implemented.");
151 gross 950 }
152    
153    
154    
155 jgs 82 DataAbstract::ValueType::value_type*
156     DataAbstract::getSampleDataByTag(int tag)
157     {
158 jgs 110 throw DataException("Error - DataAbstract::getSampleDataByTag: Data type does not have tag values.");
159 jgs 82 }
160    
161 jfenwick 1796
162     void
163 jgs 82 DataAbstract::setTaggedValue(int tagKey,
164 jfenwick 1796 const DataTypes::ShapeType& pointshape,
165     const DataTypes::ValueType& value,
166     int dataOffset)
167 jgs 82 {
168 jgs 110 throw DataException("Error - DataAbstract::setTaggedValue: Data type does not have tag values.");
169 jgs 82 }
170    
171 jfenwick 1796
172 jgs 149 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 jgs 126 void
180 gross 922 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 jfenwick 2271
185    
186 gross 922 void
187 jfenwick 2271 DataAbstract::copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value)
188 gross 921 {
189 jfenwick 2271 throw DataException("Error - DataAbstract::copying data from WrappedArray objects to a single data point is not supported.");
190 gross 921 }
191 jgs 126
192 jfenwick 2271
193 gross 576 void
194 ksteube 775 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 gross 800 DataAbstract::trace(DataAbstract* ev, int axis_offset)
207 ksteube 775 {
208 gross 800 throw DataException("Error - DataAbstract::trace is not supported.");
209 ksteube 775 }
210    
211     void
212 gross 804 DataAbstract::swapaxes(DataAbstract* ev, int axis0, int axis1)
213 gross 800 {
214 gross 804 throw DataException("Error - DataAbstract::component swapaxes is not supported.");
215 gross 800 }
216     void
217 ksteube 775 DataAbstract::transpose(DataAbstract* ev, int axis_offset)
218     {
219     throw DataException("Error - DataAbstract::transpose is not supported.");
220     }
221    
222     void
223 gross 576 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 jfenwick 2742
234 jfenwick 2792 int
235 jfenwick 2742 DataAbstract::matrixInverse(DataAbstract* out) const
236     {
237     throw DataException("Error - DataAbstract::matrixInverse is not supported.");
238     }
239    
240     void
241 gross 1118 DataAbstract::setToZero()
242     {
243     throw DataException("Error - DataAbstract:: cannot set values to zero.");
244     }
245 gross 576
246 gross 1487 void
247     DataAbstract::reorderByReferenceIDs(int *reference_ids)
248     {
249 jfenwick 1803 throw DataException("Error - DataAbstract:: cannot reorder by reference ids.");
250 gross 1487 }
251 gross 576
252    
253 jfenwick 2271 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 gross 1487
273 jfenwick 2271 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 gross 1487
289 jfenwick 1796
290 jfenwick 2271 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 jfenwick 1796
299 jfenwick 2271
300 jgs 82 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26