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

Annotation of /branches/arrexp_2137_win_merge/escript/src/DataVector.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1250 - (hide annotations)
Thu Aug 16 02:54:42 2007 UTC (12 years, 1 month ago) by ksteube
Original Path: trunk/escript/src/DataVector.cpp
File size: 4498 byte(s)
Minor repairs to scons files

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