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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 122 - (show annotations)
Thu Jun 9 05:38:05 2005 UTC (14 years, 4 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/DataVector.cpp
File size: 3513 byte(s)
Merge of development branch back to main trunk on 2005-06-09

1 /*
2 ******************************************************************************
3 * *
4 * COPYRIGHT ACcESS 2004 - All Rights Reserved *
5 * *
6 * This software is the property of ACcESS. No part of this code *
7 * may be copied in any form or by any means without the expressed written *
8 * consent of ACcESS. Copying, use or modification of this software *
9 * by any unauthorised person is illegal unless that person has a software *
10 * license agreement with ACcESS. *
11 * *
12 ******************************************************************************
13 */
14
15 #include <iostream>
16 #include <cassert>
17
18 #include "escript/Data/DataVector.h"
19 #include "escript/Data/Taipan.h"
20 #include "escript/Data/DataException.h"
21
22 using namespace std;
23 using namespace escript;
24
25 namespace escript {
26
27 Taipan arrayManager;
28
29 DataVector::DataVector() :
30 m_array_data(0),
31 m_size(0),
32 m_dim(0),
33 m_N(0)
34 {
35 }
36
37 DataVector::DataVector(const DataVector& other) :
38 m_array_data(0),
39 m_size(other.m_size),
40 m_dim(other.m_dim),
41 m_N(other.m_N)
42 {
43 m_array_data = arrayManager.new_array(m_dim,m_N);
44 int i;
45 #pragma omp parallel for private(i) schedule(static)
46 for (i=0; i<m_size; i++) {
47 m_array_data[i] = other.m_array_data[i];
48 }
49 }
50
51 DataVector::DataVector(const DataVector::size_type size,
52 const DataVector::value_type val,
53 const DataVector::size_type blockSize) :
54 m_array_data(0),
55 m_size(size),
56 m_dim(blockSize)
57 {
58 resize(size, val, blockSize);
59 }
60
61 DataVector::~DataVector()
62 {
63 // dispose of data array
64 arrayManager.delete_array(m_array_data);
65
66 // clear data members
67 m_size = -1;
68 m_dim = -1;
69 m_N = -1;
70 m_array_data = 0;
71 }
72
73 void
74 DataVector::resize(const DataVector::size_type newSize,
75 const DataVector::value_type newValue,
76 const DataVector::size_type newBlockSize)
77 {
78 assert(m_size >= 0);
79
80 if ( (newSize % newBlockSize) != 0) {
81 throw DataException("DataVector: invalid blockSize specified");
82 }
83
84 arrayManager.delete_array(m_array_data);
85
86 m_size = newSize;
87 m_dim = newBlockSize;
88 m_N = newSize / newBlockSize;
89 m_array_data = arrayManager.new_array(m_dim,m_N);
90
91 int i;
92 #pragma omp parallel for private(i) schedule(static)
93 for (i=0; i<m_size; i++) {
94 m_array_data[i] = newValue;
95 }
96 }
97
98 DataVector&
99 DataVector::operator=(const DataVector& other)
100 {
101 assert(m_size >= 0);
102
103 arrayManager.delete_array(m_array_data);
104
105 m_size = other.m_size;
106 m_dim = other.m_dim;
107 m_N = other.m_N;
108
109 m_array_data = arrayManager.new_array(m_dim,m_N);
110 int i;
111 #pragma omp parallel for private(i) schedule(static)
112 for (i=0; i<m_size; i++) {
113 m_array_data[i] = other.m_array_data[i];
114 }
115
116 return *this;
117 }
118
119 bool
120 DataVector::operator==(const DataVector& other) const
121 {
122 assert(m_size >= 0);
123
124 if (m_size!=other.m_size) {
125 return false;
126 }
127 if (m_dim!=other.m_dim) {
128 return false;
129 }
130 if (m_N!=other.m_N) {
131 return false;
132 }
133 for (int i=0; i<m_size; i++) {
134 if (m_array_data[i] != other.m_array_data[i]) {
135 return false;
136 }
137 }
138 return true;
139 }
140
141 bool
142 DataVector::operator!=(const DataVector& other) const
143 {
144 return !(*this==other);
145 }
146
147 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26