queso-0.51.1
DistArray.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008,2009,2010,2011,2012,2013 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include <queso/asserts.h>
26 #include <queso/DistArray.h>
27 #include <queso/GslVector.h>
28 #include <queso/GslMatrix.h>
29 #include <queso/ScalarSequence.h>
30 #include <queso/SampledScalarCdf.h>
31 #include <queso/OneDGrid.h>
32 
33 namespace QUESO {
34 
35 template<typename T>
37  : m_Map()
38 {
41  "DistArray<T>::constructor()",
42  "should not be called");
43 }
44 
45 // Constructor for a given inputMap and inputRowSize.
46 template<typename T>
47 DistArray<T>::DistArray(const Map& inputMap, const int inputRowSize)
48  : m_Map(inputMap),
49 #ifdef QUESO_HAS_TRILINOS
50  m_epetraDistArray(new EpetraExt::DistArray<T>(inputMap.epetraMap(),inputRowSize))
51 #else
52  m_rowSize(inputRowSize)
53 #endif
54 {
55 #ifdef QUESO_HAS_TRILINOS
56 #else
58  for (int i = 0; i < m_Map.NumGlobalElements(); ++i) {
59  m_elements[i].resize(m_rowSize);
60  }
61 #endif
62 }
63 
64 // Copy constructor
65 template<typename T>
67  : m_Map(src.m_Map)
68 #ifdef QUESO_HAS_TRILINOS
69  ,
70  m_epetraDistArray(NULL)
71 #endif
72 {
73 #ifdef QUESO_HAS_TRILINOS
74 #else
75  m_elements.clear();
76 #endif
77  this->copy(src);
78 }
79 
80 // Destructor
81 template<typename T>
83 {
84 #ifdef QUESO_HAS_TRILINOS
85  delete m_epetraDistArray;
86  m_epetraDistArray = NULL;
87 #else
88  for (int i = 0; i < m_Map.NumGlobalElements(); ++i) {
89  m_elements[i].clear();
90  }
91  m_elements.clear();
92 #endif
93 }
94 
95 // Set methods
96 template<typename T>
99 {
100 #ifdef QUESO_HAS_TRILINOS
101 #else
102  for (int i = 0; i < m_Map.NumGlobalElements(); ++i) {
103  m_elements[i].clear();
104  }
105  m_elements.clear();
106 #endif
107  this->copy(rhs);
108  return *this;
109 }
110 
111 // Query methods
112 template<typename T>
113 T&
114 DistArray<T>::operator()(int localElementId, int colId)
115 {
116 #ifdef QUESO_HAS_TRILINOS
117  return (*m_epetraDistArray)(localElementId,colId);
118 #else
119  return m_elements[localElementId][colId];
120 #endif
121 }
122 
123 template<typename T>
124 const T&
125 DistArray<T>::operator()(int localElementId, int colId) const
126 {
127 #ifdef QUESO_HAS_TRILINOS
128  return (*m_epetraDistArray)(localElementId,colId);
129 #else
130  return m_elements[localElementId][colId];
131 #endif
132 }
133 
134 template<typename T>
135 int
137 {
138 #ifdef QUESO_HAS_TRILINOS
139  return m_epetraDistArray->GlobalLength();
140 #else
141  return m_Map.NumGlobalElements();
142 #endif
143 }
144 
145 template<typename T>
146 int
148 {
149 #ifdef QUESO_HAS_TRILINOS
150  return m_epetraDistArray->MyLength();
151 #else
152  return m_Map.NumMyElements();
153 #endif
154 }
155 
156 template<typename T>
157 int
159 {
160 #ifdef QUESO_HAS_TRILINOS
161  return m_epetraDistArray->RowSize();
162 #else
163  return m_rowSize;
164 #endif
165 }
166 
167 // For some reason, we need to implement copy() otherwise the link stage during
168 // `make distcheck` fails. Building manually from the tarball works fine even
169 // without copy() implemented. Weirdness++. -- Damon
170 template<typename T> void DistArray<T>::copy(const DistArray<T>& src)
171 {
173 }
174 
175 // I/O methods
176 template<typename T>
177 void
178 DistArray<T>::print(std::ostream& os) const
179 {
180 #ifdef QUESO_HAS_TRILINOS
181  os << *m_epetraDistArray;
182 #else
183  os << "m_rowSize = " << m_rowSize
184  << ", m_elements.size() = " << m_elements.size()
185  << std::endl;
186 #endif
187 
188  return;
189 }
190 
191 } // End namespace QUESO
192 
193 // Class prototypes with all the types that QUESO needs
199 template class QUESO::DistArray<std::string>;
200 template class QUESO::DistArray<std::vector<double>*>;
A class for partitioning vectors and matrices.
Definition: Map.h:49
~DistArray()
Destructor.
Definition: DistArray.C:82
void print(std::ostream &os) const
Definition: DistArray.C:178
int RowSize() const
Returns the row size, that is, the amount of data associated with each element.
Definition: DistArray.C:158
int MyLength() const
Returns the length of the locally owned array.
Definition: DistArray.C:147
const int UQ_UNAVAILABLE_RANK
Definition: Defines.h:74
void copy(const DistArray< T > &src)
Copies the array.
Definition: DistArray.C:170
T & operator()(int localElementId, int colId)
Returns a reference to the colId column component of the localElementId local element.
Definition: DistArray.C:114
unsigned int m_rowSize
Definition: DistArray.h:123
#define queso_not_implemented()
Definition: asserts.h:88
A class for partitioning vectors and matrices.
Definition: DistArray.h:56
int NumGlobalElements() const
Returns the total number of elements across all processors.
Definition: Map.C:96
DistArray< T > & operator=(const DistArray< T > &rhs)
Assignment operator.
Definition: DistArray.C:98
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
std::vector< std::vector< T > > m_elements
Definition: DistArray.h:124
DistArray()
Default constructor. Do not call this directly.
Definition: DistArray.C:36
int GlobalLength() const
Returns the global length of the array.
Definition: DistArray.C:136

Generated on Thu Apr 23 2015 19:26:15 for queso-0.51.1 by  doxygen 1.8.5