Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
Tpetra_FECrsMatrix_decl.hpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Tpetra: Templated Linear Algebra Services Package
5// Copyright (2008) Sandia Corporation
6//
7// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8// the U.S. Government retains certain rights in this software.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38//
39// ************************************************************************
40// @HEADER
41#ifndef TPETRA_FECRSMATRIX_DECL_HPP
42#define TPETRA_FECRSMATRIX_DECL_HPP
43
44
47
49#include "Tpetra_FECrsGraph.hpp"
50
51namespace Tpetra {
52
53
54
55// \class FECrsMatrix
56// \brief Sparse matrix that presents a row-oriented interface that lets
57// users read or modify entries.
58template<class Scalar = ::Tpetra::Details::DefaultTypes::scalar_type,
60 class GlobalOrdinal = ::Tpetra::Details::DefaultTypes::global_ordinal_type,
61 class Node = ::Tpetra::Details::DefaultTypes::node_type>
62class FECrsMatrix :
63 public CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>
64{
65 friend class CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>;
66public:
68
69
72 typedef typename CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::scalar_type scalar_type;
73
83 typedef typename CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::impl_scalar_type impl_scalar_type;
84
86 typedef typename CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::local_ordinal_type local_ordinal_type;
87
89 typedef typename CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::global_ordinal_type global_ordinal_type;
90
92 typedef typename CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::node_type node_type;
93
95 typedef typename CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::device_type device_type;
96
98 typedef typename CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::execution_space execution_space;
99
105 typedef typename CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::mag_type mag_type;
106
108 typedef typename CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::map_type map_type;
109
111 typedef typename CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::import_type import_type;
112
114 typedef typename CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::export_type export_type;
115
117 typedef typename CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::crs_graph_type crs_graph_type;
118
120 typedef typename CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::local_graph_device_type local_graph_device_type;
121
124 typedef typename CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::local_matrix_device_type local_matrix_device_type;
125
128 typedef typename CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::local_matrix_host_type local_matrix_host_type;
129
131 typedef CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> crs_matrix_type;
132
134 typedef FECrsGraph<LocalOrdinal, GlobalOrdinal, Node> fe_crs_graph_type;
135
137
139
140
171 explicit FECrsMatrix (const Teuchos::RCP<const fe_crs_graph_type>& graph,
172 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
173
175 FECrsMatrix (const FECrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>&) = delete;
176
178 FECrsMatrix (FECrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>&&) = delete;
179
181 FECrsMatrix&
182 operator= (const FECrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>&) = delete;
184 FECrsMatrix&
185 operator= (FECrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>&&) = delete;
186
196 virtual ~FECrsMatrix () = default;
197
199
200
229 void globalAssemble () {endFill();}
230
232 void endAssembly();
233
235 void beginAssembly();
236
238 void endModify();
239
241 void beginModify();
242
243 private:
244
246 void endFill();
247 void beginFill();
248
253 static const bool useAtomicUpdatesByDefault =
254#ifdef KOKKOS_ENABLE_SERIAL
255 ! std::is_same<execution_space, Kokkos::Serial>::value;
256#else
257 true;
258#endif // KOKKOS_ENABLE_SERIAL
259
260 protected:
261
263 LocalOrdinal
264 replaceGlobalValuesImpl (impl_scalar_type rowVals[],
265 const crs_graph_type& graph,
266 const RowInfo& rowInfo,
267 const GlobalOrdinal inds[],
268 const impl_scalar_type newVals[],
269 const LocalOrdinal numElts);
270
271 LocalOrdinal
272 replaceLocalValuesImpl (impl_scalar_type rowVals[],
273 const crs_graph_type& graph,
274 const RowInfo& rowInfo,
275 const LocalOrdinal inds[],
276 const impl_scalar_type newVals[],
277 const LocalOrdinal numElts);
278
279 LocalOrdinal
280 sumIntoGlobalValuesImpl (impl_scalar_type rowVals[],
281 const crs_graph_type& graph,
282 const RowInfo& rowInfo,
283 const GlobalOrdinal inds[],
284 const impl_scalar_type newVals[],
285 const LocalOrdinal numElts,
286 const bool atomic = useAtomicUpdatesByDefault);
287
288 LocalOrdinal
289 sumIntoLocalValuesImpl (impl_scalar_type rowVals[],
290 const crs_graph_type& graph,
291 const RowInfo& rowInfo,
292 const LocalOrdinal inds[],
293 const impl_scalar_type newVals[],
294 const LocalOrdinal numElts,
295 const bool atomic = useAtomicUpdatesByDefault);
296
297 void
298 insertGlobalValuesImpl (crs_graph_type& graph,
299 RowInfo& rowInfo,
300 const GlobalOrdinal gblColInds[],
301 const impl_scalar_type vals[],
302 const size_t numInputEnt);
303
304 protected:
308 void doOwnedPlusSharedToOwned(const CombineMode CM=Tpetra::ADD);
309
312 void doOwnedToOwnedPlusShared(const CombineMode CM=Tpetra::ADD);
313
315 void switchActiveCrsMatrix();
317
318 private:
319 // Enum for activity
320 enum FEWhichActive
321 {
322 FE_ACTIVE_OWNED,
323 FE_ACTIVE_OWNED_PLUS_SHARED
324 };
325
326 // The FECrsGraph from construction time
327 Teuchos::RCP<const FECrsGraph<LocalOrdinal, GlobalOrdinal, Node> > feGraph_;
328
329 // This is whichever multivector isn't currently active
330 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > inactiveCrsMatrix_;
331 // This is in RCP to make shallow copies of the FECrsMatrix work correctly
332 Teuchos::RCP<FEWhichActive> activeCrsMatrix_;
333
334 enum class FillState
335 {
336 open, // matrix is "open". Values can freely summed in to and replaced
337 modify, // matrix is open for modification. *local* values can be replaced
338 closed
339 };
340 Teuchos::RCP<FillState> fillState_;
341
342}; // end class FECrsMatrix
343
344
345
346} // end namespace Tpetra
347
348
349
350#endif // TPETRA_FECRSMATRIX_DECL_HPP
Declaration of the Tpetra::CrsMatrix class.
Sparse matrix that presents a row-oriented interface that lets users read or modify entries.
int local_ordinal_type
Default value of Scalar template parameter.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
CombineMode
Rule for combining data in an Import or Export.
@ ADD
Sum new values.