10#ifndef TPETRA_CRSSINGLETONFILTER_LINEARPROBLEM_DEF_HPP
11#define TPETRA_CRSSINGLETONFILTER_LINEARPROBLEM_DEF_HPP
21template <
class LocalLO_type,
class ColIDView_type,
class ColMapColor_type,
class RowMapColor_type,
class Counter_type>
22struct CreatePostSolveArraysFunctor {
23 LocalLO_type LocalRowIDofSingletonColData;
24 ColIDView_type ColSingletonRowLIDs;
25 ColIDView_type ColSingletonColLIDs;
27 LocalLO_type NewColProfilesData;
28 LocalLO_type ColProfilesData;
29 LocalLO_type ColHasRowWithSingletonData;
30 ColMapColor_type ColMapColors_Data;
31 RowMapColor_type RowMapColors_Data;
32 Counter_type numSingletonCols;
34 CreatePostSolveArraysFunctor(LocalLO_type localRowIDofSingletonColData,
35 ColIDView_type colSingletonRowLIDs, ColIDView_type colSingletonColLIDs,
36 LocalLO_type newColProfilesData, LocalLO_type colProfilesData, LocalLO_type colHasRowWithSingletonData,
37 ColMapColor_type colMapColors_Data, RowMapColor_type rowMapColors_Data, Counter_type in_numSingletonCols)
38 : LocalRowIDofSingletonColData(localRowIDofSingletonColData)
39 , ColSingletonRowLIDs(colSingletonRowLIDs)
40 , ColSingletonColLIDs(colSingletonColLIDs)
41 , NewColProfilesData(newColProfilesData)
42 , ColProfilesData(colProfilesData)
43 , ColHasRowWithSingletonData(colHasRowWithSingletonData)
44 , ColMapColors_Data(colMapColors_Data)
45 , RowMapColors_Data(rowMapColors_Data)
46 , numSingletonCols(in_numSingletonCols) {}
48 KOKKOS_INLINE_FUNCTION
49 void operator()(
const size_t j)
const {
50 int i = LocalRowIDofSingletonColData(j, 0);
51 if (ColProfilesData(j, 0) == 1 && RowMapColors_Data(i, 0) != 1) {
53 auto lclNumSingletonCols = Kokkos::atomic_fetch_add(&numSingletonCols(0), 1);
54 ColSingletonRowLIDs(lclNumSingletonCols) = i;
55 ColSingletonColLIDs(lclNumSingletonCols) = j;
59 else if (NewColProfilesData(j, 0) == 0 && ColHasRowWithSingletonData(j, 0) != 1 && RowMapColors_Data(i, 0) == 0) {
60 ColMapColors_Data(j, 0) = 1;
66template <
class LocalOrdinal,
class GlobalOrdinal,
class LocalMap_type,
class LocalMatrix_type,
class row_map_type,
class entries_type,
class values_type>
67struct ConstructReducedProblemFunctor {
68 LocalMap_type lclFullRowMap;
69 LocalMap_type lclFullColMap;
70 LocalMap_type lclReducedRowMap;
71 LocalMap_type lclReducedColMap;
73 LocalMatrix_type lclFullMatrix;
75 row_map_type lclReducedRowPtr;
76 entries_type lclReducedColInd;
77 values_type lclReducedValues;
80 ConstructReducedProblemFunctor(LocalMap_type lclFullRowMap_, LocalMap_type lclFullColMap_, LocalMap_type lclReducedRowMap_, LocalMap_type lclReducedColMap_,
81 LocalMatrix_type lclFullMatrix_, row_map_type lclReducedRowPtr_, entries_type lclReducedColInd_, values_type lclReducedValues_)
82 : lclFullRowMap(lclFullRowMap_)
83 , lclFullColMap(lclFullColMap_)
84 , lclReducedRowMap(lclReducedRowMap_)
85 , lclReducedColMap(lclReducedColMap_)
86 , lclFullMatrix(lclFullMatrix_)
87 , lclReducedRowPtr(lclReducedRowPtr_)
88 , lclReducedColInd(lclReducedColInd_)
89 , lclReducedValues(lclReducedValues_) {}
92 KOKKOS_INLINE_FUNCTION
93 void operator()(
const LocalOrdinal i,
size_t& nnz)
const {
94 const LocalOrdinal INVALID = Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
96 auto lclFullRowPtr = lclFullMatrix.graph.row_map;
97 auto lclFullColInd = lclFullMatrix.graph.entries;
98 auto lclFullValues = lclFullMatrix.values;
100 GlobalOrdinal glbRowID = lclFullRowMap.getGlobalElement(i);
101 LocalOrdinal lclRowID = lclReducedRowMap.getLocalElement(glbRowID);
103 if (lclRowID != INVALID) {
104 for (
size_t j = lclFullRowPtr(i); j < lclFullRowPtr(i + 1); j++) {
105 GlobalOrdinal glbColID = lclFullColMap.getGlobalElement(lclFullColInd[j]);
106 LocalOrdinal lclColID = lclReducedColMap.getLocalElement(glbColID);
107 if (lclColID != INVALID) {
108 lclReducedRowPtr(1 + lclRowID)++;
112 nnz += lclReducedRowPtr(1 + lclRowID);
117 KOKKOS_INLINE_FUNCTION
118 void operator()(
const LocalOrdinal i)
const {
119 const LocalOrdinal INVALID = Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
121 auto lclFullRowPtr = lclFullMatrix.graph.row_map;
122 auto lclFullColInd = lclFullMatrix.graph.entries;
123 auto lclFullValues = lclFullMatrix.values;
125 GlobalOrdinal glbRowID = lclFullRowMap.getGlobalElement(i);
126 LocalOrdinal lclRowID = lclReducedRowMap.getLocalElement(glbRowID);
128 if (lclRowID != INVALID) {
129 size_t k = lclReducedRowPtr(lclRowID);
130 for (
size_t j = lclFullRowPtr(i); j < lclFullRowPtr(i + 1); j++) {
131 GlobalOrdinal glbColID = lclFullColMap.getGlobalElement(lclFullColInd[j]);
132 LocalOrdinal lclColID = lclReducedColMap.getLocalElement(glbColID);
133 if (lclColID != INVALID) {
134 lclReducedColInd[k] = lclColID;
135 lclReducedValues[k] = lclFullValues[j];
143template <
class LocalOrdinal,
class GlobalOrdinal,
class LocalMap_type,
class LocalMatrix_type>
144struct UpdateReducedProblemFunctor {
145 LocalMap_type lclFullRowMap;
146 LocalMap_type lclFullColMap;
147 LocalMap_type lclReducedRowMap;
148 LocalMap_type lclReducedColMap;
150 LocalMatrix_type lclFullMatrix;
151 LocalMatrix_type lclReducedMatrix;
154 UpdateReducedProblemFunctor(LocalMap_type lclFullRowMap_, LocalMap_type lclFullColMap_,
155 LocalMap_type lclReducedRowMap_, LocalMap_type lclReducedColMap_,
156 LocalMatrix_type lclFullMatrix_, LocalMatrix_type lclReducedMatrix_)
157 : lclFullRowMap(lclFullRowMap_)
158 , lclFullColMap(lclFullColMap_)
159 , lclReducedRowMap(lclReducedRowMap_)
160 , lclReducedColMap(lclReducedColMap_)
161 , lclFullMatrix(lclFullMatrix_)
162 , lclReducedMatrix(lclReducedMatrix_) {}
165 KOKKOS_INLINE_FUNCTION
166 void operator()(
const LocalOrdinal i)
const {
167 const LocalOrdinal INVALID = Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
169 auto lclFullRowPtr = lclFullMatrix.graph.row_map;
170 auto lclFullColInd = lclFullMatrix.graph.entries;
171 auto lclFullValues = lclFullMatrix.values;
173 auto lclReducedRowPtr = lclReducedMatrix.graph.row_map;
174 auto lclReducedColInd = lclReducedMatrix.graph.entries;
175 auto lclReducedValues = lclReducedMatrix.values;
177 GlobalOrdinal glbRowID = lclFullRowMap.getGlobalElement(i);
178 LocalOrdinal lclRowID = lclReducedRowMap.getLocalElement(glbRowID);
180 if (lclRowID != INVALID) {
181 for (
size_t j = lclFullRowPtr(i); j < lclFullRowPtr(i + 1); j++) {
182 GlobalOrdinal glbColID = lclFullColMap.getGlobalElement(lclFullColInd(j));
183 LocalOrdinal lclColID = lclReducedColMap.getLocalElement(glbColID);
184 if (lclColID != INVALID) {
185 for (
size_t k = lclReducedRowPtr(lclRowID); k < lclReducedRowPtr(lclRowID + 1); k++) {
186 if (lclReducedColInd[k] == lclColID) {
187 lclReducedValues[k] = lclFullValues[j];
197template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node,
198 class LocalMap_type,
class LocalMatrix_type,
class LocalX_type,
class LocalB_type,
199 class View_type_int,
class View_type_scalar,
class Err_type>
200struct SolveSingletonProblemFunctor {
201 using local_ordinal_type = LocalOrdinal;
204 local_ordinal_type NumVectors;
205 local_ordinal_type localNumSingletonCols;
208 LocalMap_type lclFullRowMap;
209 LocalMap_type lclFullColMap;
210 LocalMap_type lclReducedRowMap;
212 LocalMatrix_type lclFullMatrix;
214 LocalX_type localExportX;
215 LocalB_type localRHS;
217 View_type_int ColSingletonColLIDs;
218 View_type_int ColSingletonRowLIDs;
219 View_type_int ColSingletonPivotLIDs;
220 View_type_scalar ColSingletonPivots;
223 SolveSingletonProblemFunctor(local_ordinal_type NumVectors_, local_ordinal_type localNumSingletonCols_, Err_type error_code_,
224 LocalMap_type lclFullRowMap_, LocalMap_type lclFullColMap_, LocalMap_type lclReducedRowMap_,
225 LocalMatrix_type lclFullMatrix_, LocalX_type localExportX_, LocalB_type localRHS_,
226 View_type_int colSingletonColLIDs_, View_type_int colSingletonRowLIDs_,
227 View_type_int colSingletonPivotLIDs_, View_type_scalar colSingletonPivots_)
228 : NumVectors(NumVectors_)
229 , localNumSingletonCols(localNumSingletonCols_)
230 , error_code(error_code_)
231 , lclFullRowMap(lclFullRowMap_)
232 , lclFullColMap(lclFullColMap_)
233 , lclReducedRowMap(lclReducedRowMap_)
234 , lclFullMatrix(lclFullMatrix_)
235 , localExportX(localExportX_)
236 , localRHS(localRHS_)
237 , ColSingletonColLIDs(colSingletonColLIDs_)
238 , ColSingletonRowLIDs(colSingletonRowLIDs_)
239 , ColSingletonPivotLIDs(colSingletonPivotLIDs_)
240 , ColSingletonPivots(colSingletonPivots_) {}
243 KOKKOS_INLINE_FUNCTION
244 void operator()(
const local_ordinal_type i)
const {
245 const LocalOrdinal INVALID = Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
246 const impl_scalar_type zero(0);
248 auto lclFullRowPtr = lclFullMatrix.graph.row_map;
249 auto lclFullColInd = lclFullMatrix.graph.entries;
250 auto lclFullValues = lclFullMatrix.values;
252 GlobalOrdinal glbID = lclFullRowMap.getGlobalElement(i);
253 LocalOrdinal lclID = lclReducedRowMap.getLocalElement(glbID);
255 if (lclID == INVALID) {
256 if (lclFullRowPtr(i + 1) == lclFullRowPtr(i) + 1) {
258 LocalOrdinal indX = lclFullColInd(lclFullRowPtr(i));
259 impl_scalar_type pivot = lclFullValues(lclFullRowPtr(i));
261 Kokkos::atomic_exchange(&error_code(0), 1);
263 for (LocalOrdinal j = 0; j < NumVectors; j++) {
264 localExportX(indX, j) = localRHS(i, j) / pivot;
271 for (local_ordinal_type j = 0; j < localNumSingletonCols; j++) {
272 if (ColSingletonRowLIDs[j] == i) {
277 Kokkos::atomic_exchange(&error_code(0), 3);
280 LocalOrdinal targetCol = ColSingletonColLIDs[myNum];
281 for (
size_t j = lclFullRowPtr(i); j < lclFullRowPtr(i + 1); j++) {
282 if (lclFullColMap.getGlobalElement(lclFullColInd[j]) == targetCol) {
283 impl_scalar_type pivot = lclFullValues[j];
285 Kokkos::atomic_exchange(&error_code(0), 2);
287 ColSingletonPivotLIDs[myNum] = j;
288 ColSingletonPivots[myNum] = pivot;
299 KOKKOS_INLINE_FUNCTION
300 void operator()(
const local_ordinal_type i, local_ordinal_type& lclNumSingletonCols)
const {
301 const LocalOrdinal INVALID = Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
302 const impl_scalar_type zero(0);
304 auto lclFullRowPtr = lclFullMatrix.graph.row_map;
305 auto lclFullColInd = lclFullMatrix.graph.entries;
306 auto lclFullValues = lclFullMatrix.values;
308 GlobalOrdinal glbID = lclFullRowMap.getGlobalElement(i);
309 LocalOrdinal lclID = lclReducedRowMap.getLocalElement(glbID);
311 if (lclID == INVALID) {
312 if (lclFullRowPtr(i + 1) == lclFullRowPtr(i) + 1) {
314 LocalOrdinal indX = lclFullColInd(lclFullRowPtr(i));
315 impl_scalar_type pivot = lclFullValues(lclFullRowPtr(i));
317 Kokkos::atomic_exchange(&error_code(0), 1);
319 for (LocalOrdinal j = 0; j < NumVectors; j++) {
320 localExportX(indX, j) = localRHS(i, j) / pivot;
327 for (local_ordinal_type j = 0; j < localNumSingletonCols; j++) {
328 if (ColSingletonRowLIDs[j] == i) {
333 Kokkos::atomic_exchange(&error_code(0), 3);
336 LocalOrdinal targetCol = ColSingletonColLIDs[myNum];
337 for (
size_t j = lclFullRowPtr(i); j < lclFullRowPtr(i + 1); j++) {
338 if (lclFullColMap.getGlobalElement(lclFullColInd[j]) == targetCol) {
339 impl_scalar_type pivot = lclFullValues[j];
341 Kokkos::atomic_exchange(&error_code(0), 2);
343 ColSingletonPivots[myNum] = pivot;
348 lclNumSingletonCols++;
356template <
class View_type_
int,
class View_type_scalar,
class SOL_type,
class RHS_type>
357struct ComputeFullSolutionFunctor {
358 using scalar_type =
typename View_type_scalar::non_const_value_type;
360 View_type_int ColSingletonRowLIDs;
361 View_type_int ColSingletonColLIDs;
362 View_type_scalar ColSingletonPivots;
368 ComputeFullSolutionFunctor(View_type_int rowLIDs, View_type_int colLIDs, View_type_scalar pivots,
369 SOL_type X, RHS_type RHS, RHS_type B)
370 : ColSingletonRowLIDs(rowLIDs)
371 , ColSingletonColLIDs(colLIDs)
372 , ColSingletonPivots(pivots)
377 KOKKOS_INLINE_FUNCTION
378 void operator()(
const size_t k)
const {
379 int i = ColSingletonRowLIDs[k];
380 int j = ColSingletonColLIDs[k];
381 scalar_type pivot = ColSingletonPivots[k];
383 size_t NumVectors = localX.extent(1);
384 for (
size_t jj = 0; jj < NumVectors; jj++) {
385 localX(j, jj) = (localRHS(i, jj) - localB(i, jj)) / pivot;
390template <
class Map_color_type,
class LocalMap_type,
class IndexList_type>
391struct GenerateReducedMapFunctor {
393 Map_color_type mapColors;
394 LocalMap_type lclMap;
395 IndexList_type indexList;
398 using device_type =
typename Map_color_type::device_type;
399 Kokkos::View<size_t*, device_type> numView;
402 GenerateReducedMapFunctor(
int color_, Map_color_type mapColors_)
404 , mapColors(mapColors_) {}
407 GenerateReducedMapFunctor(
int color_, Map_color_type mapColors_, LocalMap_type lclMap_, IndexList_type indexList_)
409 , mapColors(mapColors_)
411 , indexList(indexList_) {
412 Kokkos::resize(numView, 1);
413 Kokkos::deep_copy(numView, 0);
417 KOKKOS_INLINE_FUNCTION
418 void operator()(
const size_t i,
size_t& num)
const {
419 if (mapColors(i, 0) == color) {
425 KOKKOS_INLINE_FUNCTION
426 void operator()(
const size_t i)
const {
427 if (mapColors(i, 0) == color) {
428 auto num = Kokkos::atomic_fetch_add(&numView(0), 1);
429 indexList(num) = lclMap.getGlobalElement(i);
436template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
439 : globalNumSingletonRows_(Teuchos::as<local_ordinal_type>(0))
440 , globalNumSingletonCols_(Teuchos::as<local_ordinal_type>(0))
441 , RatioOfDimensions_(0.0)
442 , RatioOfNonzeros_(0.0)
443 , HaveReducedProblem_(false)
444 , AnalysisDone_(false)
445 , SymmetricElimination_(true)
446 , localMaxNumRowEntries_(Teuchos::as<local_ordinal_type>(0))
447 , FullMatrixIsCrsMatrix_(false)
448 , run_on_host_(run_on_host)
449 , verbose_(verbose) {
454template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
455typename CrsSingletonFilter_LinearProblem<Scalar, LocalOrdinal, GlobalOrdinal, Node>::NewType
457operator()(
const CrsSingletonFilter_LinearProblem::OriginalType& originalLinearProblem) {
458 analyze(originalLinearProblem);
464template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
466 analyze(
const CrsSingletonFilter_LinearProblem::OriginalType& originalLinearProblem) {
467 this->origObj_ = originalLinearProblem;
469 FullMatrix_ = originalLinearProblem->getMatrix();
473 if (verbose_ &&
FullMatrix()->getComm()->getRank() == 0) {
474 std::cout <<
"\nAnalyzed Singleton Problem:\n";
475 std::cout <<
"---------------------------\n";
478 if (verbose_ &&
FullMatrix()->getComm()->getRank() == 0) {
479 std::cout <<
"Singletons Detected!" << std::endl;
480 std::cout <<
"Num Singletons: " <<
NumSingletons() << std::endl;
483 if (verbose_ &&
FullMatrix()->getComm()->getRank() == 0)
484 std::cout <<
"No Singletons Detected!" << std::endl;
487 if (verbose_ &&
FullMatrix()->getComm()->getRank() == 0)
488 std::cout <<
"---------------------------\n\n";
495template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
496typename CrsSingletonFilter_LinearProblem<Scalar, LocalOrdinal, GlobalOrdinal, Node>::NewType
499 const char tfecfFuncName[] =
"construct: ";
501 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(this->origObj_ == Teuchos::null, std::runtime_error,
502 "Linear problem (orgiObj_) have not been set. Call analyze() first.");
509 std::cout <<
"\nConstructedSingleton Problem:\n";
510 std::cout <<
"---------------------------\n";
513 std::cout <<
"---------------------------\n\n";
516 return this->newObj_;
521template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
529template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
537template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
539 Analyze(
const Teuchos::RCP<row_matrix_type>& fullMatrix) {
540 const char tfecfFuncName[] =
"Analyze: ";
542 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(AnalysisDone_, std::runtime_error,
543 "Analyze() already done once. Cannot do it again.");
545 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(fullMatrix == Teuchos::null,
546 std::runtime_error,
"Input matrix is Teuchos::null.");
548 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(fullMatrix->getGlobalNumRows() == 0,
549 std::runtime_error,
"Full matrix has zero dimension.");
551 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(fullMatrix->getGlobalNumEntries() == 0,
552 std::runtime_error,
"Full matrix has no nonzero terms.");
554 FullMatrix_ = fullMatrix;
557 vector_type_int ColProfiles(FullMatrixColMap());
559 vector_type_int ColHasRowWithSingleton(FullMatrixColMap());
564 vector_type_LO localRowIDofSingletonCol(FullMatrixColMap());
565 localRowIDofSingletonCol.
putScalar(Teuchos::OrdinalTraits<LocalOrdinal>::invalid());
568 RowMapColors_ = Teuchos::rcp(
new vector_type_int(FullMatrixRowMap()));
569 ColMapColors_ = Teuchos::rcp(
new vector_type_int(FullMatrixColMap()));
571 local_ordinal_type localNumRows =
FullMatrix()->getLocalNumRows();
572 local_ordinal_type localNumCols =
FullMatrix()->getLocalNumCols();
575 InitFullMatrixAccess();
580 size_t NumIndices = 1;
583 Teuchos::Array<local_ordinal_type> localIndices;
584 auto ColProfilesData = ColProfiles.
getLocalViewHost(Tpetra::Access::ReadWrite);
585 auto localRowIDofSingletonColData = localRowIDofSingletonCol.
getLocalViewHost(Tpetra::Access::ReadWrite);
586 auto ColHasRowWithSingletonData = ColHasRowWithSingleton.
getLocalViewHost(Tpetra::Access::ReadWrite);
587 auto RowMapColors_Data = RowMapColors_->getLocalViewHost(Tpetra::Access::ReadWrite);
588 auto ColMapColors_Data = ColMapColors_->getLocalViewHost(Tpetra::Access::ReadWrite);
590 for (
int i = 0; i < localNumRows; i++) {
592 GetRow(i, NumIndices, localIndices);
593 for (
size_t j = 0; j < NumIndices; j++) {
594 local_ordinal_type ColumnIndex = localIndices[j];
597 if (
static_cast<size_t>(ColumnIndex) >= ColProfilesData.extent(0)) {
598 std::cout <<
"Error: ColumnIndex out of bounds: " << ColumnIndex << std::endl;
602 ColProfilesData(ColumnIndex, 0)++;
604 if (
static_cast<size_t>(ColumnIndex) >= localRowIDofSingletonColData.extent(0)) {
605 std::cout <<
"Error: ColumnIndex out of bounds for localRowIDofSingletonColData: "
606 << ColumnIndex << std::endl;
612 localRowIDofSingletonColData(ColumnIndex, 0) = i;
615 if (NumIndices == 1) {
616 int j2 = localIndices[0];
617 ColHasRowWithSingletonData(j2, 0)++;
618 RowMapColors_Data(i, 0) = 1;
619 ColMapColors_Data(j2, 0) = 1;
624 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!FullMatrixIsCrsMatrix_, std::runtime_error,
625 "Error: FullMatrix is not CrsMatrix");
628 auto localRowIDofSingletonColData = localRowIDofSingletonCol.
getLocalViewDevice(Tpetra::Access::ReadWrite);
629 auto ColHasRowWithSingletonData = ColHasRowWithSingleton.
getLocalViewDevice(Tpetra::Access::ReadWrite);
630 auto RowMapColors_Data = RowMapColors_->getLocalViewDevice(Tpetra::Access::ReadWrite);
631 auto ColMapColors_Data = ColMapColors_->getLocalViewDevice(Tpetra::Access::ReadWrite);
633 Kokkos::View<int*, execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged | Kokkos::Atomic>>
634 ColProfilesAtomic(ColProfilesData.data(), ColProfilesData.extent(0));
635 Kokkos::View<int*, execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged | Kokkos::Atomic>>
636 ColHasRowWithSingletonAtomic(ColHasRowWithSingletonData.data(), ColHasRowWithSingletonData.extent(0));
637 Kokkos::View<int*, execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged | Kokkos::Atomic>>
638 ColMapColors_Atomic(ColMapColors_Data.data(), ColMapColors_Data.extent(0));
639 Kokkos::View<int*, execution_space> error_code(
"singleton-bound-check", 2);
640 Kokkos::deep_copy(error_code, 0);
642 auto lclRowPtr = FullCrsMatrix_->getLocalRowPtrsDevice();
643 auto lclColInd = FullCrsMatrix_->getLocalIndicesDevice();
645 Kokkos::parallel_reduce(
646 "CrsSingletonFilter_LinearProblem:Analyze(find-singleton-row)", range_policy(0, localNumRows),
647 KOKKOS_LAMBDA(
const size_t i, local_ordinal_type& lclNumSingletonRows) {
649 for (
size_t k = lclRowPtr(i); k < lclRowPtr(i + 1); k++) {
650 local_ordinal_type ColumnIndex = lclColInd(k);
653 if (
static_cast<size_t>(ColumnIndex) >= ColProfilesData.extent(0)) {
654 Kokkos::atomic_exchange(&error_code(0), ColumnIndex + 1);
656 ColProfilesAtomic(ColumnIndex)++;
660 if (
static_cast<size_t>(ColumnIndex) >= localRowIDofSingletonColData.extent(0)) {
661 Kokkos::atomic_exchange(&error_code(1), ColumnIndex + 1);
667 Kokkos::atomic_max(&localRowIDofSingletonColData(ColumnIndex, 0), i);
671 if (lclRowPtr(i + 1) == lclRowPtr(i) + 1) {
672 local_ordinal_type ColumnIndex = lclColInd(lclRowPtr(i));
673 RowMapColors_Data(i, 0) = 1;
676 ColHasRowWithSingletonAtomic(ColumnIndex)++;
677 ColMapColors_Atomic(ColumnIndex) = 1;
678 lclNumSingletonRows++;
685 auto h_error = Kokkos::create_mirror_view(error_code);
686 Kokkos::deep_copy(h_error, error_code);
687 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(h_error(0) > 0, std::runtime_error,
688 "Error: ColumnIndex out of bounds: " + std::to_string(h_error(0)));
689 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(h_error(1) > 0, std::runtime_error,
690 "Error: ColumnIndex out of bounds for localRowIDofSingletonColData " + std::to_string(h_error(1)));
701 vector_type_int NewColProfiles(ColProfiles.
getMap());
702 NewColProfiles.
update(1.0, ColProfiles, 0.0);
705 auto importer = FullCrsMatrix()->getCrsGraph()->getImporter();
706 if (importer != Teuchos::null) {
707 vector_type_int tmpVec(FullMatrixDomainMap());
713 tmpVec.
doExport(ColHasRowWithSingleton, *importer,
ADD);
726 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(ColHasRowWithSingleton.
normInf() > 1, std::runtime_error,
727 "At least one column is associated with two singleton rows, can't handle it.");
730 vector_type_int RowHasColWithSingleton(
FullMatrix()->getRowMap());
733 size_t NumIndices = 1;
736 Teuchos::Array<local_ordinal_type> localIndices;
738 auto ColProfilesData = ColProfiles.
getLocalViewHost(Tpetra::Access::ReadOnly);
739 auto localRowIDofSingletonColData = localRowIDofSingletonCol.
getLocalViewHost(Tpetra::Access::ReadOnly);
740 auto ColHasRowWithSingletonData = ColHasRowWithSingleton.
getLocalViewHost(Tpetra::Access::ReadOnly);
742 auto RowMapColors_Data = RowMapColors_->getLocalViewHost(Tpetra::Access::ReadWrite);
743 auto ColMapColors_Data = ColMapColors_->getLocalViewHost(Tpetra::Access::ReadWrite);
745 auto NewColProfilesData = NewColProfiles.
getLocalViewHost(Tpetra::Access::ReadWrite);
746 auto RowHasColWithSingletonData = RowHasColWithSingleton.
getLocalViewHost(Tpetra::Access::ReadWrite);
749 for (local_ordinal_type j = 0; j < localNumCols; j++) {
750 local_ordinal_type i2 = localRowIDofSingletonColData(j, 0);
752 if (ColProfilesData(j, 0) == 1) {
754 if (RowMapColors_Data(i2, 0) != 1) {
755 RowHasColWithSingletonData(i2, 0)++;
756 RowMapColors_Data(i2, 0) = 2;
757 ColMapColors_Data(j, 0) = 1;
762 GetRow(i2, NumIndices, localIndices);
763 for (
size_t jj = 0; jj < NumIndices; jj++) {
764 NewColProfilesData(localIndices[jj], 0)--;
769 else if (ColHasRowWithSingletonData(j, 0) == 1 && RowMapColors_Data(i2, 0) != 1) {
770 ColMapColors_Data(j, 0) = 1;
775 auto localRowIDofSingletonColData = localRowIDofSingletonCol.
getLocalViewDevice(Tpetra::Access::ReadOnly);
776 auto ColHasRowWithSingletonData = ColHasRowWithSingleton.
getLocalViewDevice(Tpetra::Access::ReadOnly);
778 auto RowMapColors_Data = RowMapColors_->getLocalViewDevice(Tpetra::Access::ReadWrite);
779 auto ColMapColors_Data = ColMapColors_->getLocalViewDevice(Tpetra::Access::ReadWrite);
781 auto NewColProfilesData = NewColProfiles.
getLocalViewDevice(Tpetra::Access::ReadWrite);
782 auto RowHasColWithSingletonData = RowHasColWithSingleton.
getLocalViewDevice(Tpetra::Access::ReadWrite);
784 auto lclRowPtr = FullCrsMatrix_->getLocalRowPtrsDevice();
785 auto lclColInd = FullCrsMatrix_->getLocalIndicesDevice();
788 Kokkos::parallel_reduce(
789 "CrsSingletonFilter_LinearProblem:Analyze(find-singleton-column)", range_policy(0, localNumCols),
790 KOKKOS_LAMBDA(
const size_t j, local_ordinal_type& lclNumSingletonCols) {
792 if (ColProfilesData(j, 0) == 1) {
795 local_ordinal_type i = localRowIDofSingletonColData(j, 0);
803 if (RowMapColors_Data(i, 0) != 1) {
804 RowMapColors_Data(i, 0) = 2;
805 ColMapColors_Data(j, 0) = 1;
806 lclNumSingletonCols++;
809 RowHasColWithSingletonData(i, 0)++;
815 for (
size_t k = lclRowPtr(i); k < lclRowPtr(i + 1); k++) {
816 NewColProfilesData(lclColInd(k), 0)--;
822 Kokkos::parallel_for(
823 "CrsSingletonFilter_LinearProblem:Analyze(find-non-singleton-column)", range_policy(0, localNumCols),
824 KOKKOS_LAMBDA(
const size_t j) {
826 if (ColProfilesData(j, 0) != 1) {
829 local_ordinal_type i = localRowIDofSingletonColData(j, 0);
837 if (ColHasRowWithSingletonData(j, 0) == 1 && RowMapColors_Data(i, 0) != 1) {
840 ColMapColors_Data(j, 0) = 1;
847 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(RowHasColWithSingleton.
normInf() > 1, std::runtime_error,
848 "At least one row is associated with two singleton columns, can't handle it.");
851 CreatePostSolveArrays(localRowIDofSingletonCol, ColProfiles, NewColProfiles, ColHasRowWithSingleton);
853 auto RowMapColors_Data = RowMapColors_->getLocalViewHost(Tpetra::Access::ReadWrite);
854 for (local_ordinal_type i = 0; i < localNumRows; i++) {
855 if (RowMapColors_Data(i, 0) == 2) RowMapColors_Data(i, 0) = 1;
858 auto RowMapColors_Data = RowMapColors_->getLocalViewDevice(Tpetra::Access::ReadWrite);
859 Kokkos::parallel_for(
860 "CrsSingletonFilter_LinearProblem:Analyze(convert-rowmap-color)", range_policy(0, localNumRows),
861 KOKKOS_LAMBDA(
const size_t i) {
862 if (RowMapColors_Data(i, 0) == 2) RowMapColors_Data(i, 0) = 1;
866 const Teuchos::Ptr<local_ordinal_type> gRowsPtr(&globalNumSingletonRows_);
867 const Teuchos::Ptr<local_ordinal_type> gColsPtr(&globalNumSingletonCols_);
868 auto rowComm =
FullMatrix()->getRowMap()->getComm();
869 Teuchos::reduceAll<local_ordinal_type, local_ordinal_type>(*rowComm, Teuchos::REDUCE_SUM,
localNumSingletonRows_, gRowsPtr);
870 Teuchos::reduceAll<local_ordinal_type, local_ordinal_type>(*rowComm, Teuchos::REDUCE_SUM,
localNumSingletonCols_, gColsPtr);
872 AnalysisDone_ =
true;
878template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
879Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
882 const Teuchos::RCP<vector_type_int>& mapColors,
int color,
883 bool locally_sort_gids) {
884 Teuchos::RCP<const map_type> reducedMap;
885 bool canRunOnHost = std::is_same_v<typename device_type::memory_space, Kokkos::HostSpace>;
886 if (run_on_host_ && canRunOnHost) {
888 std::vector<GlobalOrdinal> myReducedGlobalIndices;
891 auto myGlobalIndices = originalMap->getMyGlobalIndices();
894 for (
size_t i = 0; i < myGlobalIndices.size(); i++) {
896 int colorValue = mapColors->getData()[i];
897 if (colorValue == color) {
898 myReducedGlobalIndices.push_back(myGlobalIndices[i]);
904 Teuchos::ArrayView<const GlobalOrdinal>(myReducedGlobalIndices.data(), myReducedGlobalIndices.size()),
905 originalMap->getComm());
908 using IndexListType = Kokkos::View<GlobalOrdinal*, device_type>;
909 using functor_type = GenerateReducedMapFunctor<local_vector_int_type, local_map_type, IndexListType>;
910 auto mapColors_Data = mapColors->getLocalViewDevice(Tpetra::Access::ReadWrite);
913 size_t lclNumReducedElements = 0;
914 size_t lclNumElements = originalMap->getLocalNumElements();
916 functor_type functor(color, mapColors_Data);
917 Kokkos::parallel_reduce(
918 "CrsSingletonFilter_LinearProblem:GenerateReduceMap(count)", range_policy(0, lclNumElements),
919 functor, lclNumReducedElements);
922 IndexListType indexList;
924 auto lclMap = originalMap()->getLocalMap();
925 Kokkos::resize(indexList, lclNumReducedElements);
926 functor_type functor(color, mapColors_Data, lclMap, indexList);
927 Kokkos::parallel_for(
928 "CrsSingletonFilter_LinearProblem:GenerateReduceMap(insert)", range_policy(0, lclNumElements),
931 if (locally_sort_gids) {
937 const Tpetra::global_size_t INVALID = Tpetra::Details::OrdinalTraits<Tpetra::global_size_t>::invalid();
938 reducedMap = Teuchos::rcp(
new map_type(INVALID, indexList,
939 originalMap->getIndexBase(),
940 originalMap->getComm()));
948template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
951 const char tfecfFuncName[] =
"ConstructReducedProblem: ";
953 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(HaveReducedProblem_, std::runtime_error,
954 "Already have a reduced problem. Cannot do it again.");
956 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(Problem == Teuchos::null,
957 std::runtime_error,
"Problem is Teuchos::null.");
959 FullProblem_ = Problem;
960 FullMatrix_ = Teuchos::rcp_dynamic_cast<row_matrix_type>(Problem->getMatrix());
961 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
FullMatrix() == Teuchos::null,
962 std::runtime_error,
"Need a RowMatrix.");
963 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(Problem->getRHS() == Teuchos::null,
964 std::runtime_error,
"Need a RHS.");
965 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(Problem->getLHS() == Teuchos::null,
966 std::runtime_error,
"Need a LHS.");
968 Scalar zero = Teuchos::ScalarTraits<Scalar>::zero();
972 ReducedMatrixRowMap_ = GenerateReducedMap(FullMatrixRowMap(), RowMapColors_, 0);
973 ReducedMatrixColMap_ = GenerateReducedMap(FullMatrixColMap(), ColMapColors_, 0);
976 auto importer = FullCrsMatrix()->getCrsGraph()->getImporter();
977 if (importer != Teuchos::null) {
978 Teuchos::RCP<vector_type_int> DomainMapColors = Teuchos::rcp(
new vector_type_int(FullMatrixDomainMap()));
979 DomainMapColors->doExport(*ColMapColors_, *importer,
Tpetra::ABSMAX);
980 OrigReducedMatrixDomainMap_ = GenerateReducedMap(FullMatrixDomainMap(), DomainMapColors, 0);
985 auto exporter = FullCrsMatrix()->getCrsGraph()->getImporter();
986 if (FullMatrixIsCrsMatrix_) {
987 if (exporter != Teuchos::null) {
988 Teuchos::RCP<vector_type_int> RangeMapColors = Teuchos::rcp(
new vector_type_int(FullMatrixRangeMap()));
989 RangeMapColors->doExport(*ColMapColors_, *exporter,
Tpetra::ABSMAX);
990 ReducedMatrixRangeMap_ = GenerateReducedMap(FullMatrixRangeMap(), RangeMapColors, 0);
1000 if (!SymmetricElimination_) {
1001 ConstructRedistributeExporter(OrigReducedMatrixDomainMap_, ReducedMatrixRangeMap_,
1002 RedistributeDomainExporter_, ReducedMatrixDomainMap_);
1004 ReducedMatrixDomainMap_ = OrigReducedMatrixDomainMap_;
1005 OrigReducedMatrixDomainMap_ = Teuchos::null;
1006 RedistributeDomainExporter_ = Teuchos::null;
1010 Teuchos::RCP<multivector_type> FullRHS =
FullProblem()->getRHS();
1011 Teuchos::RCP<multivector_type> FullLHS =
FullProblem()->getLHS();
1012 local_ordinal_type NumVectors = FullLHS->getNumVectors();
1015 Full2ReducedLHSImporter_ = Teuchos::rcp(
new import_type(FullMatrixDomainMap(),
ReducedMatrixDomainMap()));
1016 Full2ReducedRHSImporter_ = Teuchos::rcp(
new import_type(FullRHS->getMap(),
ReducedMatrixRowMap()));
1019 tempExportX_ = Teuchos::rcp(
new multivector_type(FullMatrixColMap(), NumVectors));
1021 size_t NumEntries = 0;
1022 Teuchos::ArrayView<const Scalar> Values;
1023 Teuchos::Array<GlobalOrdinal> Indices;
1024 LocalOrdinal localNumRows =
FullMatrix()->getLocalNumRows();
1025 LocalOrdinal ColSingletonCounter = 0;
1028 bool canRunOnHost = std::is_same_v<typename device_type::memory_space, Kokkos::HostSpace>;
1029 if (run_on_host_ && canRunOnHost) {
1031 LocalOrdinal maxNumEntries = FullCrsMatrix()->getLocalMaxNumRowEntries();
1034 for (LocalOrdinal i = 0; i < localNumRows; i++) {
1035 GlobalOrdinal curGRID = FullMatrixRowMap()->getGlobalElement(i);
1037 GetRowGCIDs(i, NumEntries, Values, Indices);
1042 Teuchos::Array<GlobalOrdinal> filteredIndices;
1043 Teuchos::Array<Scalar> filteredValues;
1045 for (
typename Teuchos::Array<GlobalOrdinal>::size_type j = 0; j < Indices.size(); ++j) {
1047 filteredIndices.push_back(Indices[j]);
1048 filteredValues.push_back(Values[j]);
1053 if (!filteredIndices.empty()) {
1054 ReducedMatrix()->insertGlobalValues(curGRID, filteredIndices(), filteredValues());
1058 Teuchos::ArrayView<const LocalOrdinal> localIndices;
1059 GetRow(i, NumEntries, Values, localIndices);
1060 if (NumEntries == 1) {
1061 Scalar pivot = Values[0];
1062 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(pivot == zero, std::runtime_error,
1063 "Encountered zero row, unable to continue.");
1064 LocalOrdinal indX = localIndices[0];
1065 for (LocalOrdinal j = 0; j < NumVectors; j++) {
1066 auto rhsData = FullRHS->getData(j);
1067 auto exportData = tempExportX_->getDataNonConst(j);
1068 exportData[indX] = rhsData[i] / pivot;
1071 LocalOrdinal targetCol = ColSingletonColLIDs_[ColSingletonCounter];
1072 for (
size_t j = 0; j < NumEntries; j++) {
1073 if (localIndices[j] == targetCol) {
1074 Scalar pivot = Values[j];
1075 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(pivot == zero, std::runtime_error,
1076 "Encountered zero column, unable to continue.");
1077 ColSingletonPivotLIDs_[ColSingletonCounter] = j;
1078 ColSingletonPivots_[ColSingletonCounter] = pivot;
1079 ColSingletonCounter++;
1099 using graph_type =
typename local_matrix_type::StaticCrsGraphType;
1100 using row_map_type =
typename graph_type::row_map_type::non_const_type;
1101 using entries_type =
typename graph_type::entries_type::non_const_type;
1102 using values_type =
typename local_matrix_type::values_type;
1103 using functor_type = ConstructReducedProblemFunctor<local_ordinal_type, global_ordinal_type, local_map_type, local_matrix_type, row_map_type, entries_type, values_type>;
1106 auto lclFullRowMap = FullMatrixRowMap()->getLocalMap();
1107 auto lclFullColMap = FullMatrixColMap()->getLocalMap();
1111 auto lclFullMatrix = FullCrsMatrix_->getLocalMatrixDevice();
1114 row_map_type rowmap_view(
"rowmap_view", localNumReducedRows + 1);
1115 entries_type column_view(
"colind_view", nnzA);
1116 values_type values_view(
"values_view", nnzA);
1120 Kokkos::deep_copy(rowmap_view, 0);
1122 functor_type functor(lclFullRowMap, lclFullColMap, lclReducedRowMap, lclReducedColMap,
1123 lclFullMatrix, rowmap_view, column_view, values_view);
1124 Kokkos::parallel_reduce(
1125 "CrsSingletonFilter_LinearProblem:CountReducedProblem", range_policy(0, localNumRows),
1130 KokkosKernels::Impl::kk_inclusive_parallel_prefix_sum<execution_space>(1 + localNumReducedRows, rowmap_view);
1134 Kokkos::resize(column_view, nnzA);
1135 Kokkos::resize(values_view, nnzA);
1138 functor_type functor(lclFullRowMap, lclFullColMap, lclReducedRowMap, lclReducedColMap,
1139 lclFullMatrix, rowmap_view, column_view, values_view);
1140 Kokkos::parallel_for(
1141 "CrsSingletonFilter_LinearProblem:InsertReducedProblem", range_policy(0, localNumRows),
1146 graph_type static_graph(column_view, rowmap_view);
1147 local_matrix_type crsmat(
"CrsMatrix", localNumReducedRows, values_view, static_graph);
1158 using error_code_type =
typename Kokkos::View<int*, execution_space>;
1159 using functor_type = SolveSingletonProblemFunctor<scalar_type, local_ordinal_type, global_ordinal_type, Node, local_map_type, local_matrix_type,
1160 local_multivector_type, const_local_multivector_type,
1161 vector_view_type_int, vector_view_type_scalar, error_code_type>;
1162 auto lclFullRowMap = FullMatrixRowMap()->getLocalMap();
1163 auto lclFullColMap = FullMatrixColMap()->getLocalMap();
1166 auto lclFullMatrix = FullCrsMatrix_->getLocalMatrixDevice();
1168 auto localExportX = tempExportX_->getLocalViewDevice(Tpetra::Access::ReadWrite);
1169 auto localRHS = FullRHS->getLocalViewDevice(Tpetra::Access::ReadOnly);
1171 error_code_type error_code(
"singleton-bound-check", 2);
1172 Kokkos::deep_copy(error_code, 0);
1176 lclFullRowMap, lclFullColMap, lclReducedRowMap,
1177 lclFullMatrix, localExportX, localRHS,
1178 ColSingletonColLIDs_, ColSingletonRowLIDs_, ColSingletonPivotLIDs_, ColSingletonPivots_);
1179 Kokkos::parallel_for(
1180 "CrsSingletonFilter_LinearProblem:SolveSingletonProblem", range_policy(0, localNumRows),
1182 auto h_error = Kokkos::create_mirror_view(error_code);
1183 Kokkos::deep_copy(h_error, error_code);
1184 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(h_error(0) == 1, std::runtime_error,
1185 "ConstructReducedProblem: Encountered zero row, unable to continue.");
1186 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(h_error(0) == 2, std::runtime_error,
1187 "ConstructReducedProblem: Encountered zero column, unable to continue.");
1188 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(h_error(0) == 3, std::runtime_error,
1189 "ConstructReducedProblem: Unable to find my column.");
1198 ReducedLHS_->doImport(*FullLHS, *Full2ReducedLHSImporter_,
Tpetra::INSERT);
1200 FullLHS->putScalar(0.0);
1205 tempX_ = Teuchos::rcp(
new multivector_type(FullMatrixDomainMap(), NumVectors));
1206 tempB_ = Teuchos::rcp(
new multivector_type(FullRHS->getMap(), NumVectors));
1210 if (importer != Teuchos::null) {
1211 tempX_->doExport(*tempExportX_, *importer,
Tpetra::ADD);
1212 FullLHS->doExport(*tempExportX_, *importer,
Tpetra::ADD);
1214 tempX_->update(1.0, *tempExportX_, 0.0);
1215 FullLHS->update(1.0, *tempExportX_, 0.0);
1219 tempB_->update(1.0, *FullRHS, -1.0);
1221 ReducedRHS_ = Teuchos::rcp(
new multivector_type(
ReducedMatrixRowMap(), FullRHS->getNumVectors()));
1222 ReducedRHS_->doImport(*tempB_, *Full2ReducedRHSImporter_,
Tpetra::INSERT);
1229 ReducedProblem_ = Problem;
1230 ReducedMatrix_ = Teuchos::rcp(
dynamic_cast<crs_matrix_type*
>(Problem->getMatrix().getRawPtr()),
false);
1233 double fn = (double)
FullMatrix()->getGlobalNumRows();
1234 double fnnz = (double)
FullMatrix()->getGlobalNumEntries();
1237 double rnnz = (double)
ReducedMatrix()->getGlobalNumEntries();
1239 RatioOfDimensions_ = rn / fn;
1240 RatioOfNonzeros_ = rnnz / fnnz;
1241 HaveReducedProblem_ =
true;
1247template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1250 const char tfecfFuncName[] =
"UpdateReducedProblem: ";
1252 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!HaveReducedProblem_, std::runtime_error,
1253 "Must have a reduced problem.");
1254 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(Problem == Teuchos::null,
1255 std::runtime_error,
"Problem is Teuchos::null.");
1256 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
FullMatrix() == Teuchos::null,
1257 std::runtime_error,
"Need a RowMatrix.");
1258 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(Problem->getRHS() == Teuchos::null,
1259 std::runtime_error,
"Need a RHS.");
1260 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(Problem->getLHS() == Teuchos::null,
1261 std::runtime_error,
"Need a LHS.");
1263 Scalar zero = Teuchos::ScalarTraits<Scalar>::zero();
1267 Teuchos::RCP<multivector_type> FullRHS =
FullProblem()->getRHS();
1268 Teuchos::RCP<multivector_type> FullLHS =
FullProblem()->getLHS();
1270 local_ordinal_type NumVectors = FullLHS->getNumVectors();
1271 tempExportX_->putScalar(0.0);
1273 size_t NumEntries = 0;
1274 Teuchos::ArrayView<const Scalar> Values;
1275 Teuchos::Array<GlobalOrdinal> Indices;
1276 LocalOrdinal localNumRows =
FullMatrix()->getLocalNumRows();
1277 LocalOrdinal ColSingletonCounter = 0;
1280 bool canRunOnHost = std::is_same_v<typename device_type::memory_space, Kokkos::HostSpace>;
1281 if (run_on_host_ && canRunOnHost) {
1282 for (LocalOrdinal i = 0; i < localNumRows; i++) {
1283 GlobalOrdinal curGRID = FullMatrixRowMap()->getGlobalElement(i);
1285 GetRowGCIDs(i, NumEntries, Values, Indices);
1288 Teuchos::Array<GlobalOrdinal> filteredIndices;
1289 Teuchos::Array<Scalar> filteredValues;
1291 for (
typename Teuchos::Array<GlobalOrdinal>::size_type j = 0; j < Indices.size(); ++j) {
1293 filteredIndices.push_back(Indices[j]);
1294 filteredValues.push_back(Values[j]);
1299 if (!filteredIndices.empty()) {
1300 ReducedMatrix()->replaceGlobalValues(curGRID, filteredIndices(), filteredValues());
1306 Teuchos::ArrayView<const LocalOrdinal> localIndices;
1307 GetRow(i, NumEntries, Values, localIndices);
1308 if (NumEntries == 1) {
1309 Scalar pivot = Values[0];
1310 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(pivot == zero, std::runtime_error,
1311 "Encountered zero row, unable to continue.");
1312 LocalOrdinal indX = localIndices[0];
1313 for (LocalOrdinal j = 0; j < NumVectors; j++) {
1314 auto rhsData = FullRHS->getData(j);
1315 auto exportData = tempExportX_->getDataNonConst(j);
1316 exportData[indX] = rhsData[i] / pivot;
1319 LocalOrdinal j = ColSingletonPivotLIDs_[ColSingletonCounter];
1321 Scalar pivot = Values[j];
1322 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(pivot == zero, std::runtime_error,
1323 "Encountered zero column, unable to continue.");
1324 ColSingletonPivots_[ColSingletonCounter] = pivot;
1325 ColSingletonCounter++;
1332 using error_code_type =
typename Kokkos::View<int*, execution_space>;
1333 using functor_type = SolveSingletonProblemFunctor<scalar_type, local_ordinal_type, global_ordinal_type, Node, local_map_type, local_matrix_type,
1334 local_multivector_type, const_local_multivector_type,
1335 vector_view_type_int, vector_view_type_scalar, error_code_type>;
1337 auto lclFullRowMap = FullMatrixRowMap()->getLocalMap();
1338 auto lclFullColMap = FullMatrixColMap()->getLocalMap();
1341 auto lclFullMatrix = FullCrsMatrix_->getLocalMatrixDevice();
1343 auto localRHS = FullRHS->getLocalViewDevice(Tpetra::Access::ReadOnly);
1344 auto localExportX = tempExportX_->getLocalViewDevice(Tpetra::Access::ReadWrite);
1346 error_code_type error_code(
"singleton-bound-check", 2);
1347 Kokkos::deep_copy(error_code, 0);
1351 lclFullRowMap, lclFullColMap, lclReducedRowMap,
1352 lclFullMatrix, localExportX, localRHS,
1353 ColSingletonColLIDs_, ColSingletonRowLIDs_, ColSingletonPivotLIDs_, ColSingletonPivots_);
1354 Kokkos::parallel_reduce(
1355 "CrsSingletonFilter_LinearProblem:SolveSingletonProblem", range_policy(0, localNumRows),
1356 functor, ColSingletonCounter);
1359 auto h_error = Kokkos::create_mirror_view(error_code);
1360 Kokkos::deep_copy(h_error, error_code);
1361 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(h_error(0) == 1, std::runtime_error,
1362 "UpdateReducedProblem: Encountered zero row, unable to continue.");
1363 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(h_error(0) == 2, std::runtime_error,
1364 "UpdateReducedProblem: Encountered zero column, unable to continue.");
1365 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(h_error(0) == 3, std::runtime_error,
1366 "UpdateReducedProblem: Unable to find local column.");
1371 using functor_type = UpdateReducedProblemFunctor<local_ordinal_type, global_ordinal_type, local_map_type, local_matrix_type>;
1372 auto lclFullRowMap = FullMatrixRowMap()->getLocalMap();
1373 auto lclFullColMap = FullMatrixColMap()->getLocalMap();
1377 auto lclReducedMatrix = ReducedMatrix_->getLocalMatrixDevice();
1378 auto lclFullMatrix = FullCrsMatrix_->getLocalMatrixDevice();
1381 functor_type functor(lclFullRowMap, lclFullColMap, lclReducedRowMap, lclReducedColMap,
1382 lclFullMatrix, lclReducedMatrix);
1383 Kokkos::parallel_for(
1384 "CrsSingletonFilter_LinearProblem:UpdateReducedProblem", range_policy(0, localNumRows),
1390 std::runtime_error,
"Sanity Check " + std::to_string(ColSingletonCounter) +
" vs " + std::to_string(
localNumSingletonCols_) +
" (UpdateReducedProblem).");
1394 ReducedLHS_->putScalar(0.0);
1395 ReducedRHS_->doImport(*FullLHS, *Full2ReducedRHSImporter_,
Tpetra::INSERT);
1397 FullLHS->putScalar(0.0);
1402 tempX_->putScalar(0.0);
1403 tempB_->putScalar(0.0);
1408 auto importer = FullCrsMatrix()->getCrsGraph()->getImporter();
1409 if (importer != Teuchos::null) {
1410 tempX_->doExport(*tempExportX_, *importer,
Tpetra::ADD);
1411 FullLHS->doExport(*tempExportX_, *importer,
Tpetra::ADD);
1413 tempX_->update(1.0, *tempExportX_, 0.0);
1414 FullLHS->update(1.0, *tempExportX_, 0.0);
1418 tempB_->update(1.0, *FullRHS, -1.0);
1420 ReducedRHS_->putScalar(0.0);
1421 ReducedRHS_->doImport(*tempB_, *Full2ReducedRHSImporter_,
Tpetra::INSERT);
1425 ReducedProblem_ = Problem;
1426 ReducedMatrix_ = Teuchos::rcp(
dynamic_cast<crs_matrix_type*
>(Problem->getMatrix().getRawPtr()),
false);
1433template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1436 Teuchos::RCP<export_type>& RedistributeExporter,
1437 Teuchos::RCP<const map_type>& RedistributeMap) {
1438 const char tfecfFuncName[] =
"ConstructRedistributeExporter: ";
1440 auto IndexBase = SourceMap->getIndexBase();
1441 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(IndexBase != TargetMap->getIndexBase(), std::runtime_error,
1442 "Base indices do not match.");
1444 auto Comm = TargetMap->getComm();
1446 size_t TargetNumMyElements = TargetMap->getLocalNumElements();
1447 size_t SourceNumMyElements = SourceMap->getLocalNumElements();
1450 Teuchos::RCP<const map_type> ContiguousTargetMap =
1452 Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid(),
1453 TargetNumMyElements, IndexBase, Comm));
1456 Teuchos::RCP<const map_type> ContiguousSourceMap =
1458 Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid(),
1459 SourceNumMyElements, IndexBase, Comm));
1461 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1462 ContiguousSourceMap->getGlobalNumElements() != ContiguousTargetMap->getGlobalNumElements(),
1463 std::runtime_error,
"Global number of elements do not match.");
1466 auto SourceMapMyGlobalIndices = SourceMap->getMyGlobalIndices();
1469 Teuchos::RCP<Tpetra::MultiVector<GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node>> SourceIndices =
1473 for (
size_t i = 0; i < static_cast<size_t>(SourceMapMyGlobalIndices.size()); ++i) {
1474 SourceIndices->replaceLocalValue(i, 0,
static_cast<GlobalOrdinal
>(SourceMapMyGlobalIndices[i]));
1478 auto map = SourceIndices->getMap();
1480 Teuchos::RCP<Tpetra::Export<LocalOrdinal, GlobalOrdinal, Node>> Exporter =
1483 Teuchos::RCP<Tpetra::MultiVector<GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node>> TargetIndices =
1486 TargetIndices->doExport(*SourceIndices, *Exporter,
Tpetra::INSERT);
1491 Teuchos::ArrayView<const GlobalOrdinal>(TargetIndices->getData(0).getRawPtr(), TargetIndices->getLocalLength()),
1494 RedistributeExporter =
1501template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1505 Teuchos::RCP<multivector_type> FullLHS =
FullProblem()->getLHS();
1506 Teuchos::RCP<multivector_type> FullRHS =
FullProblem()->getRHS();
1508 tempX_->putScalar(Scalar(0.0));
1509 tempExportX_->putScalar(Scalar(0.0));
1512 tempX_->doExport(*ReducedLHS_, *Full2ReducedLHSImporter_,
Tpetra::ADD);
1513 FullLHS->update(Scalar(1.0), *tempX_, Scalar(1.0));
1522 size_t NumVectors = tempB_->getNumVectors();
1523 bool canRunOnHost = std::is_same_v<typename device_type::memory_space, Kokkos::HostSpace>;
1524 if (run_on_host_ && canRunOnHost) {
1526 LocalOrdinal i = ColSingletonRowLIDs_[k];
1527 LocalOrdinal j = ColSingletonColLIDs_[k];
1528 Scalar pivot = ColSingletonPivots_[k];
1529 for (
size_t jj = 0; jj < NumVectors; jj++) {
1530 auto tempExportXData = tempExportX_->getDataNonConst(jj);
1531 auto FullRHSData = FullRHS->getData(jj);
1532 auto tempBData = tempB_->getData(jj);
1533 tempExportXData[j] = (FullRHSData[i] - tempBData[i]) / pivot;
1537 using functor_type = ComputeFullSolutionFunctor<vector_view_type_int, vector_view_type_scalar,
1538 local_multivector_type, const_local_multivector_type>;
1539 auto localB = tempB_->getLocalViewDevice(Tpetra::Access::ReadOnly);
1540 auto localRHS = FullRHS->getLocalViewDevice(Tpetra::Access::ReadOnly);
1541 auto localX = tempExportX_->getLocalViewDevice(Tpetra::Access::ReadWrite);
1543 functor_type functor(ColSingletonRowLIDs_, ColSingletonColLIDs_, ColSingletonPivots_, localX, localRHS, localB);
1544 Kokkos::parallel_for(
1550 auto importer =
FullMatrix()->getGraph()->getImporter();
1551 if (importer != Teuchos::null) {
1552 tempX_->doExport(*tempExportX_, *importer,
Tpetra::ADD);
1554 tempX_->update(Scalar(1.0), *tempExportX_, Scalar(0.0));
1557 FullLHS->update(Scalar(1.0), *tempX_, Scalar(1.0));
1564template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1567 localMaxNumRowEntries_ = FullMatrix()->getLocalMaxNumRowEntries();
1570 FullCrsMatrix_ = Teuchos::rcp_dynamic_cast<crs_matrix_type>(FullMatrix());
1571 FullMatrixIsCrsMatrix_ = (FullCrsMatrix() != Teuchos::null);
1578template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1579void CrsSingletonFilter_LinearProblem<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
1580 GetRow(local_ordinal_type localRow,
size_t& NumIndices,
1581 Teuchos::Array<local_ordinal_type>& localIndices) {
1583 size_t maxNumEntries = FullCrsMatrix()->getLocalMaxNumRowEntries();
1584 nonconst_local_inds_host_view_type Indices(
"indices", maxNumEntries);
1585 nonconst_values_host_view_type Values(
"values", maxNumEntries);
1586 if (FullMatrixIsCrsMatrix_) {
1587 FullCrsMatrix()->getLocalRowCopy(localRow, Indices, Values, NumIndices);
1589 FullMatrix()->getLocalRowCopy(localRow, Indices, Values, NumIndices);
1596 localIndices.resize(NumIndices);
1597 for (
size_t i = 0; i < NumIndices; ++i) {
1598 localIndices[i] = Indices(i);
1605template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1607 GetRow(LocalOrdinal Row,
size_t& NumIndices, Teuchos::ArrayView<const Scalar>& Values,
1608 Teuchos::ArrayView<const LocalOrdinal>& Indices) {
1609 typename Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::local_inds_host_view_type localIndices;
1610 typename Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::values_host_view_type rowValues;
1612 if (FullMatrixIsCrsMatrix_) {
1613 FullCrsMatrix()->getLocalRowView(Row, localIndices, rowValues);
1615 NumIndices = localIndices.size();
1616 Values = Teuchos::ArrayView<const Scalar>(
reinterpret_cast<const Scalar*
>(rowValues.data()), rowValues.size());
1617 Indices = Teuchos::ArrayView<const LocalOrdinal>(localIndices.data(), localIndices.size());
1620 typename Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::nonconst_local_inds_host_view_type localIndicesCopy(
"localIndicesCopy", FullMatrix()->getLocalMaxNumRowEntries());
1621 typename Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::nonconst_values_host_view_type rowValuesCopy(
"rowValuesCopy", FullMatrix()->getLocalMaxNumRowEntries());
1623 FullMatrix()->getLocalRowCopy(Row, localIndicesCopy, rowValuesCopy, NumIndices);
1625 Values = Teuchos::ArrayView<const Scalar>(
reinterpret_cast<const Scalar*
>(rowValuesCopy.data()), NumIndices);
1626 Indices = Teuchos::ArrayView<const LocalOrdinal>(localIndicesCopy.data(), NumIndices);
1633template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1636 LocalOrdinal localRow,
1638 Teuchos::ArrayView<const Scalar>& Values,
1639 Teuchos::Array<GlobalOrdinal>& GlobalIndices) {
1641 typename Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::local_inds_host_view_type LocalIndices;
1642 typename Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::values_host_view_type RowValues;
1644 FullMatrix()->getLocalRowView(localRow, LocalIndices, RowValues);
1647 NumIndices = LocalIndices.size();
1648 GlobalIndices.resize(NumIndices);
1649 for (
size_t j = 0; j < NumIndices; ++j) {
1650 GlobalIndices[j] = FullMatrixColMap()->getGlobalElement(LocalIndices[j]);
1653 Values = Teuchos::ArrayView<const Scalar>(
reinterpret_cast<const Scalar*
>(RowValues.data()), RowValues.size());
1660template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1663 vector_type_LO ColProfiles,
1664 vector_type_LO NewColProfiles,
1665 vector_type_LO ColHasRowWithSingleton) {
1666 const char tfecfFuncName[] =
"CreatePostSolveArrays: ";
1668 if (localNumSingletonCols_ == 0)
return;
1671 Kokkos::resize(ColSingletonRowLIDs_, localNumSingletonCols_);
1672 Kokkos::resize(ColSingletonColLIDs_, localNumSingletonCols_);
1673 Kokkos::resize(ColSingletonPivotLIDs_, localNumSingletonCols_);
1674 Kokkos::resize(ColSingletonPivots_, localNumSingletonCols_);
1676 int NumMyColSingletonstmp = 0;
1679 bool canRunOnHost = std::is_same_v<typename device_type::memory_space, Kokkos::HostSpace>;
1680 if (run_on_host_ && canRunOnHost) {
1684 auto localRowIDofSingletonColData = localRowIDofSingletonCol.getLocalViewHost(Tpetra::Access::ReadOnly);
1685 auto ColProfilesData = ColProfiles.getLocalViewHost(Tpetra::Access::ReadOnly);
1686 auto RowMapColors_Data = RowMapColors_->getLocalViewHost(Tpetra::Access::ReadOnly);
1687 auto NewColProfilesData = NewColProfiles.getLocalViewHost(Tpetra::Access::ReadOnly);
1688 auto ColHasRowWithSingletonData = ColHasRowWithSingleton.getLocalViewHost(Tpetra::Access::ReadOnly);
1689 auto ColMapColors_Data = ColMapColors_->getLocalViewHost(Tpetra::Access::ReadWrite);
1691 for (
int j = 0; j < localNumCols; j++) {
1692 int i = localRowIDofSingletonColData(j, 0);
1693 if (ColProfilesData(j, 0) == 1 && RowMapColors_Data(i, 0) != 1) {
1694 ColSingletonRowLIDs_[NumMyColSingletonstmp] = i;
1695 ColSingletonColLIDs_[NumMyColSingletonstmp] = j;
1696 NumMyColSingletonstmp++;
1700 else if (NewColProfilesData(j, 0) == 0 && ColHasRowWithSingletonData(j, 0) != 1 && RowMapColors_Data(i, 0) == 0) {
1701 ColMapColors_Data(j, 0) = 1;
1710 auto localRowIDofSingletonColData = localRowIDofSingletonCol.getLocalViewDevice(Tpetra::Access::ReadOnly);
1711 auto ColProfilesData = ColProfiles.getLocalViewDevice(Tpetra::Access::ReadOnly);
1712 auto RowMapColors_Data = RowMapColors_->getLocalViewDevice(Tpetra::Access::ReadOnly);
1713 auto NewColProfilesData = NewColProfiles.getLocalViewDevice(Tpetra::Access::ReadOnly);
1714 auto ColHasRowWithSingletonData = ColHasRowWithSingleton.getLocalViewDevice(Tpetra::Access::ReadOnly);
1715 auto ColMapColors_Data = ColMapColors_->getLocalViewDevice(Tpetra::Access::ReadWrite);
1718 Kokkos::View<int*, execution_space> numSingletonCols(
"numSingletonCols", 1);
1719 Kokkos::deep_copy(numSingletonCols, 0);
1722 CreatePostSolveArraysFunctor functor(localRowIDofSingletonColData,
1723 ColSingletonRowLIDs_, ColSingletonColLIDs_,
1724 NewColProfilesData, ColProfilesData, ColHasRowWithSingletonData,
1725 ColMapColors_Data, RowMapColors_Data, numSingletonCols);
1726 Kokkos::parallel_for(
1727 "CrsSingletonFilter_LinearProblem:CreatePostSolveArrays", range_policy(0, localNumCols),
1731 auto h_numSingletonCols = Kokkos::create_mirror_view(numSingletonCols);
1732 Kokkos::deep_copy(h_numSingletonCols, numSingletonCols);
1733 NumMyColSingletonstmp = h_numSingletonCols(0);
1737 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(NumMyColSingletonstmp != localNumSingletonCols_,
1738 std::runtime_error,
"Sanity Check " + std::to_string(NumMyColSingletonstmp) +
" vs " + std::to_string(localNumSingletonCols_) +
" (CreatePostSolveArrays).");
1740 Kokkos::Experimental::sort_by_key(
execution_space(), ColSingletonRowLIDs_, ColSingletonColLIDs_);
1753#define TPETRA_CRSSINGLETONFILTER_INSTANT(SCALAR, LO, GO, NODE) \
1754 template class CrsSingletonFilter_LinearProblem<SCALAR, LO, GO, NODE>;
Declaration of the Tpetra::CrsSingletonFilter_LinearProblem class.
size_t getLocalNumCols() const override
The number of columns connected to the locally owned rows of this matrix.
A class for explicitly eliminating matrix rows and columns from a LinearProblem.
int NumSingletons() const
Return total number of singletons detected.
void rvs()
Reverse transfer of data.
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...
void fwd()
Forward transfer of data.
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.
local_ordinal_type localNumSingletonRows_
Number of singleton rows.
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.
CrsSingletonFilter_LinearProblem(bool run_on_host=false, bool verbose=false)
Constructor.
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.
double RatioOfDimensions() const
Returns ratio of reduced system to full system dimensions, returns -1.0 if reduced problem not constr...
void doImport(const SrcDistObject &source, const Import< LocalOrdinal, GlobalOrdinal, Node > &importer, const CombineMode CM, const bool restrictedMode=false)
void doExport(const SrcDistObject &source, const Export< LocalOrdinal, GlobalOrdinal, Node > &exporter, const CombineMode CM, const bool restrictedMode=false)
virtual Teuchos::RCP< const map_type > getMap() const
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
Class that encapulates linear problem (Ax = b).
One or more distributed dense vectors.
typename Kokkos::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
dual_view_type::t_dev::const_type getLocalViewDevice(Access::ReadOnlyStruct) const
Return a read-only, up-to-date view of this MultiVector's local data on device. This requires that th...
dual_view_type::t_host::const_type getLocalViewHost(Access::ReadOnlyStruct) const
Return a read-only, up-to-date view of this MultiVector's local data on host. This requires that ther...
void putScalar(const Scalar &value)
Set all values in the multivector with the given value.
void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)
Update: this = beta*this + alpha*A.
mag_type normInf() const
Return the infinity-norm of this Vector.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
size_t global_size_t
Global size_t object.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createNonContigMapWithNode(const Teuchos::ArrayView< const GlobalOrdinal > &elementList, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Nonmember constructor for a noncontiguous Map with a user-specified, possibly nondefault Kokkos Node ...
@ ABSMAX
Replace old value with maximum of magnitudes of old and new values.
@ INSERT
Insert new values that don't currently exist.