queso-0.57.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-2017 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 #ifdef QUESO_HAS_TRILINOS
34 #include <Epetra_MpiComm.h>
35 #include <Epetra_SerialComm.h>
36 #endif
37 
38 namespace QUESO {
39 
40 // Constructor for a given inputMap and inputRowSize.
41 template<typename T>
42 DistArray<T>::DistArray(const Map& inputMap, const int inputRowSize)
43  : m_Map(inputMap),
44 #ifdef QUESO_HAS_TRILINOS
45  m_epetraDistArray(new EpetraExt::DistArray<T>(inputMap.epetraMap(),inputRowSize))
46 #else
47  m_rowSize(inputRowSize)
48 #endif
49 {
50 #ifdef QUESO_HAS_TRILINOS
51 #else
52  m_elements.resize(m_Map.NumGlobalElements());
53  for (int i = 0; i < m_Map.NumGlobalElements(); ++i) {
54  m_elements[i].resize(m_rowSize);
55  }
56 #endif
57 }
58 
59 // Destructor
60 template<typename T>
62 {
63 #ifdef QUESO_HAS_TRILINOS
64  delete m_epetraDistArray;
65  m_epetraDistArray = NULL;
66 #else
67  for (int i = 0; i < m_Map.NumGlobalElements(); ++i) {
68  m_elements[i].clear();
69  }
70  m_elements.clear();
71 #endif
72 }
73 
74 // Set methods
75 template<typename T>
78 {
79  return *this;
80 }
81 
82 // Query methods
83 template<typename T>
84 T&
85 DistArray<T>::operator()(int localElementId, int colId)
86 {
87 #ifdef QUESO_HAS_TRILINOS
88  return (*m_epetraDistArray)(localElementId,colId);
89 #else
90  return m_elements[localElementId][colId];
91 #endif
92 }
93 
94 template<typename T>
95 const T&
96 DistArray<T>::operator()(int localElementId, int colId) const
97 {
98 #ifdef QUESO_HAS_TRILINOS
99  return (*m_epetraDistArray)(localElementId,colId);
100 #else
101  return m_elements[localElementId][colId];
102 #endif
103 }
104 
105 template<typename T>
106 int
108 {
109 #ifdef QUESO_HAS_TRILINOS
110  return m_epetraDistArray->GlobalLength();
111 #else
112  return m_Map.NumGlobalElements();
113 #endif
114 }
115 
116 template<typename T>
117 int
119 {
120 #ifdef QUESO_HAS_TRILINOS
121  return m_epetraDistArray->MyLength();
122 #else
123  return m_Map.NumMyElements();
124 #endif
125 }
126 
127 template<typename T>
128 int
130 {
131 #ifdef QUESO_HAS_TRILINOS
132  return m_epetraDistArray->RowSize();
133 #else
134  return m_rowSize;
135 #endif
136 }
137 
138 // I/O methods
139 template<typename T>
140 void
141 DistArray<T>::print(std::ostream& os) const
142 {
143 #ifdef QUESO_HAS_TRILINOS
144  os << *m_epetraDistArray;
145 #else
146  os << "m_rowSize = " << m_rowSize
147  << ", m_elements.size() = " << m_elements.size()
148  << std::endl;
149 #endif
150 
151  return;
152 }
153 
154 } // End namespace QUESO
155 
156 // Class prototypes with all the types that QUESO needs
162 template class QUESO::DistArray<std::string>;
163 template class QUESO::DistArray<std::vector<double>*>;
DistArray()
Default constructor. Do not call this directly.
int MyLength() const
Returns the length of the locally owned array.
Definition: DistArray.C:118
A class for partitioning vectors and matrices.
Definition: DistArray.h:56
int RowSize() const
Returns the row size, that is, the amount of data associated with each element.
Definition: DistArray.C:129
int GlobalLength() const
Returns the global length of the array.
Definition: DistArray.C:107

Generated on Sat Apr 22 2017 14:04:35 for queso-0.57.0 by  doxygen 1.8.5