queso-0.53.0
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-2015 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 // Constructor for a given inputMap and inputRowSize.
36 template<typename T>
37 DistArray<T>::DistArray(const Map& inputMap, const int inputRowSize)
38  : m_Map(inputMap),
39 #ifdef QUESO_HAS_TRILINOS
40  m_epetraDistArray(new EpetraExt::DistArray<T>(inputMap.epetraMap(),inputRowSize))
41 #else
42  m_rowSize(inputRowSize)
43 #endif
44 {
45 #ifdef QUESO_HAS_TRILINOS
46 #else
48  for (int i = 0; i < m_Map.NumGlobalElements(); ++i) {
49  m_elements[i].resize(m_rowSize);
50  }
51 #endif
52 }
53 
54 // Copy constructor
55 template<typename T>
57  : m_Map(src.m_Map)
58 #ifdef QUESO_HAS_TRILINOS
59  ,
60  m_epetraDistArray(NULL)
61 #endif
62 {
63 #ifdef QUESO_HAS_TRILINOS
64 #else
65  m_elements.clear();
66 #endif
67  this->copy(src);
68 }
69 
70 // Destructor
71 template<typename T>
73 {
74 #ifdef QUESO_HAS_TRILINOS
75  delete m_epetraDistArray;
76  m_epetraDistArray = NULL;
77 #else
78  for (int i = 0; i < m_Map.NumGlobalElements(); ++i) {
79  m_elements[i].clear();
80  }
81  m_elements.clear();
82 #endif
83 }
84 
85 // Set methods
86 template<typename T>
89 {
90 #ifdef QUESO_HAS_TRILINOS
91 #else
92  for (int i = 0; i < m_Map.NumGlobalElements(); ++i) {
93  m_elements[i].clear();
94  }
95  m_elements.clear();
96 #endif
97  this->copy(rhs);
98  return *this;
99 }
100 
101 // Query methods
102 template<typename T>
103 T&
104 DistArray<T>::operator()(int localElementId, int colId)
105 {
106 #ifdef QUESO_HAS_TRILINOS
107  return (*m_epetraDistArray)(localElementId,colId);
108 #else
109  return m_elements[localElementId][colId];
110 #endif
111 }
112 
113 template<typename T>
114 const T&
115 DistArray<T>::operator()(int localElementId, int colId) const
116 {
117 #ifdef QUESO_HAS_TRILINOS
118  return (*m_epetraDistArray)(localElementId,colId);
119 #else
120  return m_elements[localElementId][colId];
121 #endif
122 }
123 
124 template<typename T>
125 int
127 {
128 #ifdef QUESO_HAS_TRILINOS
129  return m_epetraDistArray->GlobalLength();
130 #else
131  return m_Map.NumGlobalElements();
132 #endif
133 }
134 
135 template<typename T>
136 int
138 {
139 #ifdef QUESO_HAS_TRILINOS
140  return m_epetraDistArray->MyLength();
141 #else
142  return m_Map.NumMyElements();
143 #endif
144 }
145 
146 template<typename T>
147 int
149 {
150 #ifdef QUESO_HAS_TRILINOS
151  return m_epetraDistArray->RowSize();
152 #else
153  return m_rowSize;
154 #endif
155 }
156 
157 // For some reason, we need to implement copy() otherwise the link stage during
158 // `make distcheck` fails. Building manually from the tarball works fine even
159 // without copy() implemented. Weirdness++. -- Damon
160 template<typename T> void DistArray<T>::copy(const DistArray<T>& src)
161 {
163 }
164 
165 // I/O methods
166 template<typename T>
167 void
168 DistArray<T>::print(std::ostream& os) const
169 {
170 #ifdef QUESO_HAS_TRILINOS
171  os << *m_epetraDistArray;
172 #else
173  os << "m_rowSize = " << m_rowSize
174  << ", m_elements.size() = " << m_elements.size()
175  << std::endl;
176 #endif
177 
178  return;
179 }
180 
181 } // End namespace QUESO
182 
183 // Class prototypes with all the types that QUESO needs
189 template class QUESO::DistArray<std::string>;
190 template class QUESO::DistArray<std::vector<double>*>;
int GlobalLength() const
Returns the global length of the array.
Definition: DistArray.C:126
DistArray< T > & operator=(const DistArray< T > &rhs)
Assignment operator.
Definition: DistArray.C:88
~DistArray()
Destructor.
Definition: DistArray.C:72
DistArray()
Default constructor. Do not call this directly.
unsigned int m_rowSize
Definition: DistArray.h:121
std::vector< std::vector< T > > m_elements
Definition: DistArray.h:122
void copy(const DistArray< T > &src)
Copies the array.
Definition: DistArray.C:160
int MyLength() const
Returns the length of the locally owned array.
Definition: DistArray.C:137
int RowSize() const
Returns the row size, that is, the amount of data associated with each element.
Definition: DistArray.C:148
#define queso_not_implemented()
Definition: asserts.h:56
A class for partitioning vectors and matrices.
Definition: DistArray.h:56
T & operator()(int localElementId, int colId)
Returns a reference to the colId column component of the localElementId local element.
Definition: DistArray.C:104
A class for partitioning vectors and matrices.
Definition: Map.h:49
void print(std::ostream &os) const
Definition: DistArray.C:168
int NumGlobalElements() const
Returns the total number of elements across all processors.
Definition: Map.C:85
and that you are informed that you can do these things To protect your we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it For if you distribute copies of the whether gratis or for a you must give the recipients all the rights that we gave you You must make sure that receive or can get the source code If you link other code with the you must provide complete object files to the so that they can relink them with the library after making changes to the library and recompiling it And you must show them these terms so they know their rights We protect your rights with a two step which gives you legal permission to copy
Definition: License.txt:60

Generated on Thu Jun 11 2015 13:52:31 for queso-0.53.0 by  doxygen 1.8.5