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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1387 - (hide annotations)
Fri Jan 11 07:45:26 2008 UTC (11 years, 9 months ago) by trankine
Original Path: temp/escript/src/DataVector.cpp
File size: 4373 byte(s)
Restore the trunk that existed before the windows changes were committed to the (now moved to branches) old trunk.
1 jgs 117
2 ksteube 1312 /* $Id$ */
3    
4     /*******************************************************
5     *
6     * Copyright 2003-2007 by ACceSS MNRF
7     * Copyright 2007 by University of Queensland
8     *
9     * http://esscc.uq.edu.au
10     * Primary Business: Queensland, Australia
11     * Licensed under the Open Software License version 3.0
12     * http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16 jgs 474 #include "DataVector.h"
17 jgs 117
18 jgs 477 #include "Taipan.h"
19     #include "DataException.h"
20    
21     #include <cassert>
22    
23 jgs 117 using namespace std;
24 jgs 121 using namespace escript;
25 jgs 117
26     namespace escript {
27    
28 jgs 121 Taipan arrayManager;
29    
30 gross 797 void releaseUnusedMemory()
31     {
32     arrayManager.release_unused_arrays();
33     }
34    
35    
36 jgs 121 DataVector::DataVector() :
37     m_array_data(0),
38     m_size(0),
39     m_dim(0),
40     m_N(0)
41     {
42 jgs 117 }
43    
44 jgs 121 DataVector::DataVector(const DataVector& other) :
45     m_array_data(0),
46     m_size(other.m_size),
47     m_dim(other.m_dim),
48     m_N(other.m_N)
49     {
50     m_array_data = arrayManager.new_array(m_dim,m_N);
51 jgs 122 int i;
52     #pragma omp parallel for private(i) schedule(static)
53     for (i=0; i<m_size; i++) {
54 jgs 121 m_array_data[i] = other.m_array_data[i];
55     }
56 jgs 117 }
57    
58 jgs 121 DataVector::DataVector(const DataVector::size_type size,
59     const DataVector::value_type val,
60     const DataVector::size_type blockSize) :
61     m_array_data(0),
62     m_size(size),
63     m_dim(blockSize)
64     {
65     resize(size, val, blockSize);
66 jgs 117 }
67    
68 jgs 121 DataVector::~DataVector()
69     {
70     // dispose of data array
71 jgs 151 if (m_array_data!=0) {
72     arrayManager.delete_array(m_array_data);
73     }
74 jgs 121
75     // clear data members
76     m_size = -1;
77     m_dim = -1;
78     m_N = -1;
79     m_array_data = 0;
80 jgs 117 }
81    
82 jgs 121 void
83     DataVector::resize(const DataVector::size_type newSize,
84     const DataVector::value_type newValue,
85     const DataVector::size_type newBlockSize)
86     {
87     assert(m_size >= 0);
88    
89 jgs 151 if ( newBlockSize == 0) {
90 ksteube 1250 throw DataException("DataVector: invalid blockSize specified (newBlockSize)");
91 jgs 151 }
92    
93 jgs 121 if ( (newSize % newBlockSize) != 0) {
94     throw DataException("DataVector: invalid blockSize specified");
95     }
96    
97 jgs 151 if (m_array_data!=0) {
98     arrayManager.delete_array(m_array_data);
99     }
100 jgs 121
101     m_size = newSize;
102     m_dim = newBlockSize;
103     m_N = newSize / newBlockSize;
104     m_array_data = arrayManager.new_array(m_dim,m_N);
105    
106 jgs 122 int i;
107     #pragma omp parallel for private(i) schedule(static)
108     for (i=0; i<m_size; i++) {
109     m_array_data[i] = newValue;
110 jgs 121 }
111     }
112    
113     DataVector&
114     DataVector::operator=(const DataVector& other)
115     {
116     assert(m_size >= 0);
117    
118 jgs 151 if (m_array_data!=0) {
119     arrayManager.delete_array(m_array_data);
120     }
121 jgs 121
122     m_size = other.m_size;
123     m_dim = other.m_dim;
124     m_N = other.m_N;
125    
126     m_array_data = arrayManager.new_array(m_dim,m_N);
127 jgs 122 int i;
128     #pragma omp parallel for private(i) schedule(static)
129     for (i=0; i<m_size; i++) {
130 jgs 121 m_array_data[i] = other.m_array_data[i];
131     }
132    
133     return *this;
134     }
135    
136     bool
137     DataVector::operator==(const DataVector& other) const
138     {
139     assert(m_size >= 0);
140    
141     if (m_size!=other.m_size) {
142     return false;
143     }
144     if (m_dim!=other.m_dim) {
145     return false;
146     }
147     if (m_N!=other.m_N) {
148     return false;
149     }
150     for (int i=0; i<m_size; i++) {
151     if (m_array_data[i] != other.m_array_data[i]) {
152     return false;
153     }
154     }
155     return true;
156     }
157    
158     bool
159     DataVector::operator!=(const DataVector& other) const
160     {
161     return !(*this==other);
162     }
163    
164 jgs 123 int
165     DataVector::archiveData(ofstream& archiveFile,
166     const size_type noValues) const
167     {
168     //
169     // Check number of values expected to be written matches number in this object
170     if (noValues != size()) {
171     return 2;
172     }
173    
174     //
175     // Write all values in this object out to archiveFile
176     for (int i=0; i<size(); i++) {
177     archiveFile.write(reinterpret_cast<char *>(&m_array_data[i]),sizeof(double));
178     }
179    
180     //
181     // Check no errors were encountered before returning
182     if (!archiveFile.good()) {
183     return 1;
184     }
185    
186     return 0;
187     }
188    
189     int
190     DataVector::extractData(ifstream& archiveFile,
191     const size_type noValues)
192     {
193     //
194     // Check number of values expected to be read matches number in this object
195     if (noValues != size()) {
196     return 2;
197     }
198    
199     //
200     // Read all values in archiveFile back to this object
201     for (int i=0; i<size(); i++) {
202     archiveFile.read(reinterpret_cast<char *>(&m_array_data[i]),sizeof(double));
203     }
204    
205     //
206     // Check no errors were encountered before returning
207     if (!archiveFile.good()) {
208     return 1;
209     }
210    
211     return 0;
212     }
213    
214 jgs 117 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26