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 {
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)
449 , verbose_(verbose) {
454template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
455typename CrsSingletonFilter_LinearProblem<Scalar, LocalOrdinal, GlobalOrdinal, Node>::NewType
464template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
471 Analyze(FullMatrix());
473 if (verbose_ && FullMatrix()->getComm()->getRank() == 0) {
474 std::cout <<
"\nAnalyzed Singleton Problem:\n";
475 std::cout <<
"---------------------------\n";
477 if (SingletonsDetected()) {
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
502 "Linear problem (orgiObj_) have not been set. Call analyze() first.");
504 ConstructReducedProblem(this->origObj_);
506 this->newObj_ = ReducedProblem();
508 if (verbose_ && SingletonsDetected() && FullMatrix()->getComm()->getRank() == 0) {
509 std::cout <<
"\nConstructedSingleton Problem:\n";
510 std::cout <<
"---------------------------\n";
511 std::cout <<
"RatioOfDimensions: " << RatioOfDimensions() << std::endl;
512 std::cout <<
"RatioOfNonzeros: " << RatioOfNonzeros() << std::endl;
513 std::cout <<
"---------------------------\n\n";
516 return this->newObj_;
521template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
524 UpdateReducedProblem(FullProblem());
529template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
532 ComputeFullSolution();
537template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
543 "Analyze() already done once. Cannot do it again.");
546 std::runtime_error,
"Input matrix is Teuchos::null.");
549 std::runtime_error,
"Full matrix has zero dimension.");
552 std::runtime_error,
"Full matrix has no nonzero terms.");
571 local_ordinal_type
localNumRows = FullMatrix()->getLocalNumRows();
572 local_ordinal_type
localNumCols = FullMatrix()->getLocalNumCols();
575 InitFullMatrixAccess();
578 localNumSingletonRows_ = 0;
584 auto ColProfilesData =
ColProfiles.getLocalViewHost(Tpetra::Access::ReadWrite);
587 auto RowMapColors_Data = RowMapColors_->getLocalViewHost(Tpetra::Access::ReadWrite);
588 auto ColMapColors_Data = ColMapColors_->getLocalViewHost(Tpetra::Access::ReadWrite);
597 if (
static_cast<size_t>(
ColumnIndex) >= ColProfilesData.extent(0)) {
598 std::cout <<
"Error: ColumnIndex out of bounds: " <<
ColumnIndex << std::endl;
605 std::cout <<
"Error: ColumnIndex out of bounds for localRowIDofSingletonColData: "
617 ColHasRowWithSingletonData(
j2, 0)++;
618 RowMapColors_Data(
i, 0) = 1;
619 ColMapColors_Data(
j2, 0) = 1;
620 localNumSingletonRows_++;
625 "Error: FullMatrix is not CrsMatrix");
627 auto ColProfilesData =
ColProfiles.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>>
635 Kokkos::View<int*, execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged | Kokkos::Atomic>>
637 Kokkos::View<int*, execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged | Kokkos::Atomic>>
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),
653 if (
static_cast<size_t>(
ColumnIndex) >= ColProfilesData.extent(0)) {
654 Kokkos::atomic_exchange(&error_code(0),
ColumnIndex + 1);
661 Kokkos::atomic_exchange(&error_code(1),
ColumnIndex + 1);
673 RowMapColors_Data(
i, 0) = 1;
681 localNumSingletonRows_);
685 auto h_error = Kokkos::create_mirror_view(error_code);
686 Kokkos::deep_copy(
h_error, error_code);
688 "Error: ColumnIndex out of bounds: " + std::to_string(
h_error(0)));
690 "Error: ColumnIndex out of bounds for localRowIDofSingletonColData " + std::to_string(
h_error(1)));
705 auto importer = FullCrsMatrix()->getCrsGraph()->getImporter();
727 "At least one column is associated with two singleton rows, can't handle it.");
729 localNumSingletonCols_ = 0;
738 auto ColProfilesData =
ColProfiles.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);
752 if (ColProfilesData(
j, 0) == 1) {
754 if (RowMapColors_Data(
i2, 0) != 1) {
756 RowMapColors_Data(
i2, 0) = 2;
757 ColMapColors_Data(
j, 0) = 1;
758 localNumSingletonCols_++;
769 else if (ColHasRowWithSingletonData(
j, 0) == 1 && RowMapColors_Data(
i2, 0) != 1) {
770 ColMapColors_Data(
j, 0) = 1;
774 auto ColProfilesData =
ColProfiles.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);
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),
792 if (ColProfilesData(
j, 0) == 1) {
803 if (RowMapColors_Data(
i, 0) != 1) {
804 RowMapColors_Data(
i, 0) = 2;
805 ColMapColors_Data(
j, 0) = 1;
821 localNumSingletonCols_);
822 Kokkos::parallel_for(
823 "CrsSingletonFilter_LinearProblem:Analyze(find-non-singleton-column)", range_policy(0,
localNumCols),
826 if (ColProfilesData(
j, 0) != 1) {
837 if (ColHasRowWithSingletonData(
j, 0) == 1 && RowMapColors_Data(
i, 0) != 1) {
840 ColMapColors_Data(
j, 0) = 1;
848 "At least one row is associated with two singleton columns, can't handle it.");
853 auto RowMapColors_Data = RowMapColors_->getLocalViewHost(Tpetra::Access::ReadWrite);
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),
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,
885 bool canRunOnHost = std::is_same_v<typename device_type::memory_space, Kokkos::HostSpace>;
903 reducedMap = createNonContigMapWithNode<LocalOrdinal, GlobalOrdinal, Node>(
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) {
933 Kokkos::sort(execution_space(), indexList);
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>
954 "Already have a reduced problem. Cannot do it again.");
957 std::runtime_error,
"Problem is Teuchos::null.");
960 FullMatrix_ = Teuchos::rcp_dynamic_cast<row_matrix_type>(
Problem->getMatrix());
962 std::runtime_error,
"Need a RowMatrix.");
964 std::runtime_error,
"Need a RHS.");
966 std::runtime_error,
"Need a LHS.");
968 Scalar zero = Teuchos::ScalarTraits<Scalar>::zero();
971 if (SingletonsDetected()) {
972 ReducedMatrixRowMap_ = GenerateReducedMap(FullMatrixRowMap(), RowMapColors_, 0);
973 ReducedMatrixColMap_ = GenerateReducedMap(FullMatrixColMap(), ColMapColors_, 0);
976 auto importer = FullCrsMatrix()->getCrsGraph()->getImporter();
980 OrigReducedMatrixDomainMap_ = GenerateReducedMap(FullMatrixDomainMap(),
DomainMapColors, 0);
982 OrigReducedMatrixDomainMap_ = ReducedMatrixColMap();
985 auto exporter = FullCrsMatrix()->getCrsGraph()->getImporter();
986 if (FullMatrixIsCrsMatrix_) {
990 ReducedMatrixRangeMap_ = GenerateReducedMap(FullMatrixRangeMap(),
RangeMapColors, 0);
992 ReducedMatrixRangeMap_ = ReducedMatrixRowMap();
994 ReducedMatrixRangeMap_ = ReducedMatrixRowMap();
999 SymmetricElimination_ = ReducedMatrixRangeMap()->isSameAs(*OrigReducedMatrixDomainMap_);
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));
1022 Teuchos::ArrayView<const Scalar>
Values;
1023 Teuchos::Array<GlobalOrdinal>
Indices;
1028 bool canRunOnHost = std::is_same_v<typename device_type::memory_space, Kokkos::HostSpace>;
1036 if (ReducedMatrixRowMap()->isNodeGlobalElement(
curGRID)) {
1045 for (
typename Teuchos::Array<GlobalOrdinal>::size_type
j = 0;
j <
Indices.size(); ++
j) {
1046 if (ReducedMatrixColMap()->isNodeGlobalElement(
Indices[
j])) {
1063 "Encountered zero row, unable to continue.");
1067 auto exportData = tempExportX_->getDataNonConst(
j);
1076 "Encountered zero column, unable to continue.");
1090 ReducedMatrix()->fillComplete(ReducedMatrixDomainMap(), ReducedMatrixRangeMap());
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;
1106 auto lclFullRowMap = FullMatrixRowMap()->getLocalMap();
1107 auto lclFullColMap = FullMatrixColMap()->getLocalMap();
1108 auto lclReducedRowMap = ReducedMatrixRowMap()->getLocalMap();
1109 auto lclReducedColMap = ReducedMatrixColMap()->getLocalMap();
1111 auto lclFullMatrix = FullCrsMatrix_->getLocalMatrixDevice();
1124 Kokkos::parallel_reduce(
1125 "CrsSingletonFilter_LinearProblem:CountReducedProblem", range_policy(0,
localNumRows),
1140 Kokkos::parallel_for(
1141 "CrsSingletonFilter_LinearProblem:InsertReducedProblem", range_policy(0,
localNumRows),
1153 ReducedMatrix_ = Teuchos::rcp(
new crs_matrix_type(
crsmat, ReducedMatrixRowMap(), ReducedMatrixColMap(), ReducedMatrixDomainMap(), ReducedMatrixRangeMap()));
1160 local_multivector_type, const_local_multivector_type,
1162 auto lclFullRowMap = FullMatrixRowMap()->getLocalMap();
1163 auto lclFullColMap = FullMatrixColMap()->getLocalMap();
1164 auto lclReducedRowMap = ReducedMatrixRowMap()->getLocalMap();
1166 auto lclFullMatrix = FullCrsMatrix_->getLocalMatrixDevice();
1168 auto localExportX = tempExportX_->getLocalViewDevice(Tpetra::Access::ReadWrite);
1169 auto localRHS =
FullRHS->getLocalViewDevice(Tpetra::Access::ReadOnly);
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);
1185 "ConstructReducedProblem: Encountered zero row, unable to continue.");
1187 "ConstructReducedProblem: Encountered zero column, unable to continue.");
1189 "ConstructReducedProblem: Unable to find my column.");
1197 ReducedLHS_ = Teuchos::rcp(
new multivector_type(ReducedMatrixDomainMap(), NumVectors));
1205 tempX_ = Teuchos::rcp(
new multivector_type(FullMatrixDomainMap(), NumVectors));
1214 tempX_->update(1.0, *tempExportX_, 0.0);
1215 FullLHS->update(1.0, *tempExportX_, 0.0);
1218 FullMatrix()->apply(*tempX_, *tempB_);
1219 tempB_->update(1.0, *
FullRHS, -1.0);
1222 ReducedRHS_->doImport(*tempB_, *Full2ReducedRHSImporter_,
Tpetra::INSERT);
1226 ReducedMatrix(), ReducedLHS_, ReducedRHS_));
1233 double fn = (
double)FullMatrix()->getGlobalNumRows();
1234 double fnnz = (
double)FullMatrix()->getGlobalNumEntries();
1236 double rn = (
double)ReducedMatrix()->getGlobalNumRows();
1237 double rnnz = (
double)ReducedMatrix()->getGlobalNumEntries();
1239 RatioOfDimensions_ =
rn /
fn;
1241 HaveReducedProblem_ =
true;
1247template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1253 "Must have a reduced problem.");
1255 std::runtime_error,
"Problem is Teuchos::null.");
1257 std::runtime_error,
"Need a RowMatrix.");
1259 std::runtime_error,
"Need a RHS.");
1261 std::runtime_error,
"Need a LHS.");
1263 Scalar zero = Teuchos::ScalarTraits<Scalar>::zero();
1265 if (SingletonsDetected()) {
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);
1274 Teuchos::ArrayView<const Scalar>
Values;
1275 Teuchos::Array<GlobalOrdinal>
Indices;
1280 bool canRunOnHost = std::is_same_v<typename device_type::memory_space, Kokkos::HostSpace>;
1284 if (ReducedMatrixRowMap()->isNodeGlobalElement(
curGRID)) {
1291 for (
typename Teuchos::Array<GlobalOrdinal>::size_type
j = 0;
j <
Indices.size(); ++
j) {
1292 if (ReducedMatrixColMap()->isNodeGlobalElement(
Indices[
j])) {
1311 "Encountered zero row, unable to continue.");
1315 auto exportData = tempExportX_->getDataNonConst(
j);
1323 "Encountered zero column, unable to continue.");
1334 local_multivector_type, const_local_multivector_type,
1337 auto lclFullRowMap = FullMatrixRowMap()->getLocalMap();
1338 auto lclFullColMap = FullMatrixColMap()->getLocalMap();
1339 auto lclReducedRowMap = ReducedMatrixRowMap()->getLocalMap();
1341 auto lclFullMatrix = FullCrsMatrix_->getLocalMatrixDevice();
1343 auto localRHS =
FullRHS->getLocalViewDevice(Tpetra::Access::ReadOnly);
1344 auto localExportX = tempExportX_->getLocalViewDevice(Tpetra::Access::ReadWrite);
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),
1359 auto h_error = Kokkos::create_mirror_view(error_code);
1360 Kokkos::deep_copy(
h_error, error_code);
1362 "UpdateReducedProblem: Encountered zero row, unable to continue.");
1364 "UpdateReducedProblem: Encountered zero column, unable to continue.");
1366 "UpdateReducedProblem: Unable to find local column.");
1372 auto lclFullRowMap = FullMatrixRowMap()->getLocalMap();
1373 auto lclFullColMap = FullMatrixColMap()->getLocalMap();
1374 auto lclReducedRowMap = ReducedMatrixRowMap()->getLocalMap();
1375 auto lclReducedColMap = ReducedMatrixColMap()->getLocalMap();
1377 auto lclReducedMatrix = ReducedMatrix_->getLocalMatrixDevice();
1378 auto lclFullMatrix = FullCrsMatrix_->getLocalMatrixDevice();
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);
1402 tempX_->putScalar(0.0);
1403 tempB_->putScalar(0.0);
1408 auto importer = FullCrsMatrix()->getCrsGraph()->getImporter();
1413 tempX_->update(1.0, *tempExportX_, 0.0);
1414 FullLHS->update(1.0, *tempExportX_, 0.0);
1417 FullMatrix()->apply(*tempX_, *tempB_);
1418 tempB_->update(1.0, *
FullRHS, -1.0);
1420 ReducedRHS_->putScalar(0.0);
1421 ReducedRHS_->doImport(*tempB_, *Full2ReducedRHSImporter_,
Tpetra::INSERT);
1433template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1438 const char tfecfFuncName[] =
"ConstructRedistributeExporter: ";
1442 "Base indices do not match.");
1451 Teuchos::rcp(
new const map_type(
1452 Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid(),
1457 Teuchos::rcp(
new const map_type(
1458 Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid(),
1463 std::runtime_error,
"Global number of elements do not match.");
1469 Teuchos::RCP<Tpetra::MultiVector<GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node>>
SourceIndices =
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>
1504 if (SingletonsDetected()) {
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);
1518 FullMatrix()->apply(*
FullLHS, *tempB_);
1522 size_t NumVectors = tempB_->getNumVectors();
1523 bool canRunOnHost = std::is_same_v<typename device_type::memory_space, Kokkos::HostSpace>;
1525 for (
int k = 0;
k < localNumSingletonCols_;
k++) {
1529 for (
size_t jj = 0;
jj < NumVectors;
jj++) {
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(
1545 "CrsSingletonFilter_LinearProblem:ComputeFullSolution", range_policy(0, localNumSingletonCols_),
1550 auto importer = FullMatrix()->getGraph()->getImporter();
1554 tempX_->update(
Scalar(1.0), *tempExportX_,
Scalar(0.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>
1606void CrsSingletonFilter_LinearProblem<Scalar, LocalOrdinal, GlobalOrdinal, 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>
1634void CrsSingletonFilter_LinearProblem<Scalar, LocalOrdinal, GlobalOrdinal, 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>
1661void CrsSingletonFilter_LinearProblem<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
1662 CreatePostSolveArrays(vector_type_LO localRowIDofSingletonCol,
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>;
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.
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
typename Kokkos::ArithTraits< Scalar >::val_type impl_scalar_type
The type used internally in place of Scalar.
A distributed dense vector.
int local_ordinal_type
Default value of Scalar template parameter.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
@ ABSMAX
Replace old value with maximum of magnitudes of old and new values.
@ INSERT
Insert new values that don't currently exist.