Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
Tpetra_CrsSingletonFilter_LinearProblem_decl.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Tpetra: Templated Linear Algebra Services Package
4//
5// Copyright 2008 NTESS and the Tpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef TPETRA_CRSSINGLETONFILTER_LINEARPROBLEM_DECL_HPP
11#define TPETRA_CRSSINGLETONFILTER_LINEARPROBLEM_DECL_HPP
12
15
16#include "Tpetra_LinearProblem.hpp"
17#include "Tpetra_Transform.hpp"
18
19#include "Teuchos_DataAccess.hpp"
20
21#include "Kokkos_Core.hpp"
22#include "Kokkos_Sort.hpp"
23
24#include "Tpetra_Vector.hpp"
25#include "Tpetra_MultiVector.hpp"
26#include "Tpetra_CrsMatrix.hpp"
27#include "Tpetra_RowMatrix.hpp"
28
29namespace Tpetra {
30
115
116template <class Scalar,
117 class LocalOrdinal,
118 class GlobalOrdinal,
119 class Node>
120class CrsSingletonFilter_LinearProblem : public SameTypeTransform<Tpetra::LinearProblem<Scalar, LocalOrdinal, GlobalOrdinal, Node> > {
121 public:
123
124
125 using scalar_type = Scalar;
126 using local_ordinal_type = LocalOrdinal;
128
139
140 using OriginalType = typename Transform<linear_problem_type, linear_problem_type>::OriginalType;
141 using OriginalConstType = typename Transform<linear_problem_type, linear_problem_type>::OriginalConstType;
142 using NewType = typename Transform<linear_problem_type, linear_problem_type>::NewType;
143 using NewConstType = typename Transform<linear_problem_type, linear_problem_type>::NewConstType;
144
145 using nonconst_local_inds_host_view_type = typename row_matrix_type::nonconst_local_inds_host_view_type;
146 using nonconst_global_inds_host_view_type = typename row_matrix_type::nonconst_global_inds_host_view_type;
147 using nonconst_values_host_view_type = typename row_matrix_type::nonconst_values_host_view_type;
148
149 using local_map_type = typename map_type::local_map_type;
150
151 using local_matrix_type = typename crs_matrix_type::local_matrix_device_type;
152 using local_ptr_view_type = typename crs_matrix_type::row_ptrs_device_view_type;
153 using local_ind_view_type = typename crs_matrix_type::local_inds_device_view_type;
154 using local_val_view_type = typename crs_matrix_type::local_matrix_device_type::values_type;
155 using const_local_val_view_type = typename local_val_view_type::const_type;
156
157 using impl_scalar_type = typename multivector_type::impl_scalar_type;
158 using local_multivector_type = typename multivector_type::dual_view_type::t_dev;
159 using const_local_multivector_type = typename local_multivector_type::const_type;
160
161 using local_vector_int_type = typename vector_type_int::dual_view_type::t_dev;
162
163 using device_type = typename Node::device_type;
164 using vector_view_type_int = Kokkos::View<local_ordinal_type*, device_type>;
165 using vector_view_type_scalar = Kokkos::View<impl_scalar_type*, device_type>;
166
167 using execution_space = typename vector_type_int::execution_space;
168 using range_policy = Kokkos::RangePolicy<execution_space>;
169
171
173
174 CrsSingletonFilter_LinearProblem(bool run_on_host = false, bool verbose = false);
175
179
180 NewType operator()(const OriginalType& originalLinearProblem);
181
182 void analyze(const OriginalType& originalLinearProblem);
183
184 NewType construct();
185
186 void fwd();
187
188 void rvs();
189
191
204 void Analyze(const Teuchos::RCP<row_matrix_type>& FullMatrix);
205
208 bool SingletonsDetected() const {
209 if (!AnalysisDone_)
210 return (false);
211 else
212 return (NumSingletons() > 0);
213 }
214
216
218
224 void ConstructReducedProblem(const Teuchos::RCP<linear_problem_type>& Problem);
225
232 void UpdateReducedProblem(const Teuchos::RCP<linear_problem_type>& Problem);
233
235
237
246 void ComputeFullSolution();
247
249
251
254 int NumSingletonRows() const { return (globalNumSingletonRows_); }
255
259 int NumSingletonCols() const { return (globalNumSingletonCols_); }
260
269 int NumSingletons() const { return (NumSingletonCols() + NumSingletonRows()); }
270
273 double RatioOfDimensions() const { return (RatioOfDimensions_); }
274
277 double RatioOfNonzeros() const { return (RatioOfNonzeros_); }
278
280
282
284 Teuchos::RCP<linear_problem_type> FullProblem() const { return (FullProblem_); }
285
287 Teuchos::RCP<linear_problem_type> ReducedProblem() const { return (ReducedProblem_); }
288
290 Teuchos::RCP<row_matrix_type> FullMatrix() const { return (FullMatrix_); }
291
293 Teuchos::RCP<crs_matrix_type> ReducedMatrix() const { return ReducedMatrix_; }
294
296 Teuchos::RCP<const map_type> ReducedMatrixRowMap() const { return ReducedMatrixRowMap_; }
297
299 Teuchos::RCP<const map_type> ReducedMatrixColMap() const { return ReducedMatrixColMap_; }
300
302 Teuchos::RCP<const map_type> ReducedMatrixDomainMap() const { return ReducedMatrixDomainMap_; }
303
305 Teuchos::RCP<const map_type> ReducedMatrixRangeMap() const { return ReducedMatrixRangeMap_; }
307
308 protected:
309 // This RCP will be null if full matrix is not a CrsMatrix.
310 Teuchos::RCP<crs_matrix_type> FullCrsMatrix() const { return (FullCrsMatrix_); }
311
312 Teuchos::RCP<const map_type> FullMatrixRowMap() const { return (FullMatrix()->getRowMap()); }
313 Teuchos::RCP<const map_type> FullMatrixColMap() const { return (FullMatrix()->getColMap()); }
314 Teuchos::RCP<const map_type> FullMatrixDomainMap() const { return (FullMatrix()->getDomainMap()); }
315 Teuchos::RCP<const map_type> FullMatrixRangeMap() const { return (FullMatrix()->getRangeMap()); }
316
317 // int ComputeEliminateMaps();
318 int Setup(const Teuchos::RCP<linear_problem_type>& Problem);
319 void InitFullMatrixAccess();
320 // void GetRow(int localRow, int & NumIndices, int * & Indices);
321 void GetRow(local_ordinal_type localRow, size_t& NumIndices,
322 Teuchos::Array<local_ordinal_type>& localIndices);
323 void GetRow(LocalOrdinal Row, size_t& NumIndices, Teuchos::ArrayView<const Scalar>& Values,
324 Teuchos::ArrayView<const LocalOrdinal>& Indices);
325
326 void GetRowGCIDs(LocalOrdinal Row, size_t& NumIndices, Teuchos::ArrayView<const Scalar>& Values,
327 Teuchos::Array<GlobalOrdinal>& GlobalIndices);
328
329 void CreatePostSolveArrays(vector_type_LO localRowIDofSingletonCol,
330 vector_type_LO ColProfiles,
331 vector_type_LO NewColProfiles,
332 vector_type_LO ColHasRowWithSingleton);
333
334 void ConstructRedistributeExporter(Teuchos::RCP<const map_type> SourceMap, Teuchos::RCP<const map_type> TargetMap,
335 Teuchos::RCP<export_type>& RedistributeExporter,
336 Teuchos::RCP<const map_type>& RedistributeMap);
337
338 Teuchos::RCP<const map_type> GenerateReducedMap(const Teuchos::RCP<const map_type>& originalMap,
339 const Teuchos::RCP<vector_type_int>& mapColors,
340 int color = 0, bool locally_sort_gids = true);
341
342 Teuchos::RCP<linear_problem_type> FullProblem_;
343 Teuchos::RCP<linear_problem_type> ReducedProblem_;
344 Teuchos::RCP<row_matrix_type> FullMatrix_;
345 Teuchos::RCP<crs_matrix_type> FullCrsMatrix_;
346 Teuchos::RCP<crs_matrix_type> ReducedMatrix_;
347 Teuchos::RCP<multivector_type> ReducedRHS_;
348 Teuchos::RCP<multivector_type> ReducedLHS_;
349
350 Teuchos::RCP<const map_type> ReducedMatrixRowMap_;
351 Teuchos::RCP<const map_type> ReducedMatrixColMap_;
352 Teuchos::RCP<const map_type> ReducedMatrixDomainMap_;
353 Teuchos::RCP<const map_type> ReducedMatrixRangeMap_;
354 Teuchos::RCP<const map_type> OrigReducedMatrixDomainMap_;
355 Teuchos::RCP<import_type> Full2ReducedRHSImporter_;
356 Teuchos::RCP<import_type> Full2ReducedLHSImporter_;
357 Teuchos::RCP<export_type> RedistributeDomainExporter_;
358
359 vector_view_type_int ColSingletonRowLIDs_;
360 vector_view_type_int ColSingletonColLIDs_;
361 vector_view_type_int ColSingletonPivotLIDs_;
362 vector_view_type_scalar ColSingletonPivots_;
363
364 local_ordinal_type localNumSingletonRows_;
365 local_ordinal_type localNumSingletonCols_;
366 local_ordinal_type globalNumSingletonRows_;
367 local_ordinal_type globalNumSingletonCols_;
368 double RatioOfDimensions_;
369 double RatioOfNonzeros_;
370
371 bool HaveReducedProblem_;
372 // bool UserDefinedEliminateMaps_;
373 bool AnalysisDone_;
374 bool SymmetricElimination_;
375
376 Teuchos::RCP<multivector_type> tempExportX_;
377 Teuchos::RCP<multivector_type> tempX_;
378 Teuchos::RCP<multivector_type> tempB_;
379 // Teuchos::RCP<multivector_type> RedistributeReducedLHS_;
380
381 // Maximum number of entries in any row of the matrix, on this process.
382 local_ordinal_type localMaxNumRowEntries_;
383
384 Teuchos::RCP<vector_type_int> RowMapColors_;
385 Teuchos::RCP<vector_type_int> ColMapColors_;
386 bool FullMatrixIsCrsMatrix_;
387
388 bool run_on_host_;
389 bool verbose_;
390
391 private:
393 CrsSingletonFilter_LinearProblem(const Teuchos::RCP<CrsSingletonFilter_LinearProblem>& /* Problem */) {}
394};
395
396} // namespace Tpetra
397
398#endif // TPETRA_CRSSINGLETONFILTER_LINEARPROBLEM_DECL_HPP
Struct that holds views of the contents of a CrsMatrix.
Sparse matrix that presents a row-oriented interface that lets users read or modify entries.
KokkosSparse::CrsMatrix< impl_scalar_type, local_ordinal_type, device_type, void, typename local_graph_device_type::size_type > local_matrix_device_type
The specialization of Kokkos::CrsMatrix that represents the part of the sparse matrix on each MPI pro...
A class for explicitly eliminating matrix rows and columns from a LinearProblem.
int NumSingletons() const
Return total number of singletons detected.
virtual ~CrsSingletonFilter_LinearProblem()=default
Destructor.
int NumSingletonRows() const
Return number of rows that contain a single entry, returns -1 if Analysis has not been performed yet.
bool SingletonsDetected() const
Returns true if singletons were detected in this matrix (must be called after Analyze() to be effecti...
Teuchos::RCP< row_matrix_type > FullMatrix() const
! Returns RCP to Tpetra::RowMatrix from full problem.
double RatioOfNonzeros() const
Returns ratio of reduced system to full system nonzero count, returns -1.0 if reduced problem not con...
Teuchos::RCP< const map_type > ReducedMatrixDomainMap() const
Returns RCP to Tpetra::Map describing the domain map for the reduced system.
void ConstructReducedProblem(const Teuchos::RCP< linear_problem_type > &Problem)
Return a reduced linear problem based on results of Analyze().
Teuchos::RCP< linear_problem_type > FullProblem() const
Returns RCP to the original full (unreduced) Tpetra::LinearProblem.
Teuchos::RCP< crs_matrix_type > ReducedMatrix() const
Returns RCP to Tpetra::CrsMatrix from reduced problem.
void Analyze(const Teuchos::RCP< row_matrix_type > &FullMatrix)
Analyze the input matrix, removing row/column pairs that have singletons.
NewType construct()
Construction of new object as a result of the transform.
void UpdateReducedProblem(const Teuchos::RCP< linear_problem_type > &Problem)
Update a reduced linear problem using new values.
Teuchos::RCP< const map_type > ReducedMatrixRowMap() const
Returns RCP to Tpetra::Map describing the reduced system row distribution.
Teuchos::RCP< const map_type > ReducedMatrixColMap() const
Returns RCP to Tpetra::Map describing the reduced system column distribution.
local_ordinal_type localNumSingletonCols_
Number of singleton columns not eliminated by singleton rows.
void ComputeFullSolution()
Compute a solution for the full problem using the solution of the reduced problem,...
NewType operator()(const OriginalType &originalLinearProblem)
Analysis of transform operation on original object and construction of new object.
void analyze(const OriginalType &originalLinearProblem)
Initial analysis phase of transform.
Teuchos::RCP< linear_problem_type > ReducedProblem() const
Returns RCP to the derived reduced Tpetra::LinearProblem.
Teuchos::RCP< const map_type > ReducedMatrixRangeMap() const
Returns RCP to Tpetra::Map describing the range map for the reduced system.
int NumSingletonCols() const
Return number of columns that contain a single entry that are not associated with singleton row,...
double RatioOfDimensions() const
Returns ratio of reduced system to full system dimensions, returns -1.0 if reduced problem not constr...
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
Class that encapulates linear problem (Ax = b).
A parallel distribution of indices over processes.
::Tpetra::Details::LocalMap< local_ordinal_type, global_ordinal_type, device_type > local_map_type
Type of the "local" Map.
typename device_type::execution_space execution_space
Type of the (new) Kokkos execution space.
A read-only, row-oriented interface to a sparse matrix.
A distributed dense vector.
Namespace Tpetra contains the class and methods constituting the Tpetra library.