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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1312 - (show annotations)
Mon Sep 24 06:18:44 2007 UTC (12 years ago) by ksteube
File size: 4373 byte(s)
The MPI branch is hereby closed. All future work should be in trunk.

Previously in revision 1295 I merged the latest changes to trunk into trunk-mpi-branch.
In this revision I copied all files from trunk-mpi-branch over the corresponding
trunk files. I did not use 'svn merge', it was a copy.

1
2 /* $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 #include "DataVector.h"
17
18 #include "Taipan.h"
19 #include "DataException.h"
20
21 #include <cassert>
22
23 using namespace std;
24 using namespace escript;
25
26 namespace escript {
27
28 Taipan arrayManager;
29
30 void releaseUnusedMemory()
31 {
32 arrayManager.release_unused_arrays();
33 }
34
35
36 DataVector::DataVector() :
37 m_array_data(0),
38 m_size(0),
39 m_dim(0),
40 m_N(0)
41 {
42 }
43
44 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 int i;
52 #pragma omp parallel for private(i) schedule(static)
53 for (i=0; i<m_size; i++) {
54 m_array_data[i] = other.m_array_data[i];
55 }
56 }
57
58 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 }
67
68 DataVector::~DataVector()
69 {
70 // dispose of data array
71 if (m_array_data!=0) {
72 arrayManager.delete_array(m_array_data);
73 }
74
75 // clear data members
76 m_size = -1;
77 m_dim = -1;
78 m_N = -1;
79 m_array_data = 0;
80 }
81
82 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 if ( newBlockSize == 0) {
90 throw DataException("DataVector: invalid blockSize specified (newBlockSize)");
91 }
92
93 if ( (newSize % newBlockSize) != 0) {
94 throw DataException("DataVector: invalid blockSize specified");
95 }
96
97 if (m_array_data!=0) {
98 arrayManager.delete_array(m_array_data);
99 }
100
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 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 }
111 }
112
113 DataVector&
114 DataVector::operator=(const DataVector& other)
115 {
116 assert(m_size >= 0);
117
118 if (m_array_data!=0) {
119 arrayManager.delete_array(m_array_data);
120 }
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 int i;
128 #pragma omp parallel for private(i) schedule(static)
129 for (i=0; i<m_size; i++) {
130 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 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 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26