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 size_t k = lclReducedRowPtr(lclRowID);
182 for (
size_t j = lclFullRowPtr(i); j < lclFullRowPtr(i + 1); j++) {
183 GlobalOrdinal glbColID = lclFullColMap.getGlobalElement(lclFullColInd(j));
184 LocalOrdinal lclColID = lclReducedColMap.getLocalElement(glbColID);
185 if (lclColID != INVALID) {
188 lclReducedColInd[k] = lclColID;
189 lclReducedValues[k] = lclFullValues[j];
198template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node,
199 class LocalMap_type,
class LocalMatrix_type,
class LocalX_type,
class LocalB_type,
200 class View_type_int,
class View_type_scalar,
class Err_type>
201struct SolveSingletonProblemFunctor {
202 using local_ordinal_type = LocalOrdinal;
205 local_ordinal_type NumVectors;
206 local_ordinal_type localNumSingletonCols;
209 LocalMap_type lclFullRowMap;
210 LocalMap_type lclFullColMap;
211 LocalMap_type lclReducedRowMap;
213 LocalMatrix_type lclFullMatrix;
215 LocalX_type localExportX;
216 LocalB_type localRHS;
218 View_type_int ColSingletonColLIDs;
219 View_type_int ColSingletonRowLIDs;
220 View_type_int ColSingletonPivotLIDs;
221 View_type_scalar ColSingletonPivots;
224 SolveSingletonProblemFunctor(local_ordinal_type NumVectors_, local_ordinal_type localNumSingletonCols_, Err_type error_code_,
225 LocalMap_type lclFullRowMap_, LocalMap_type lclFullColMap_, LocalMap_type lclReducedRowMap_,
226 LocalMatrix_type lclFullMatrix_, LocalX_type localExportX_, LocalB_type localRHS_,
227 View_type_int colSingletonColLIDs_, View_type_int colSingletonRowLIDs_,
228 View_type_int colSingletonPivotLIDs_, View_type_scalar colSingletonPivots_)
229 : NumVectors(NumVectors_)
230 , localNumSingletonCols(localNumSingletonCols_)
231 , error_code(error_code_)
232 , lclFullRowMap(lclFullRowMap_)
233 , lclFullColMap(lclFullColMap_)
234 , lclReducedRowMap(lclReducedRowMap_)
235 , lclFullMatrix(lclFullMatrix_)
236 , localExportX(localExportX_)
237 , localRHS(localRHS_)
238 , ColSingletonColLIDs(colSingletonColLIDs_)
239 , ColSingletonRowLIDs(colSingletonRowLIDs_)
240 , ColSingletonPivotLIDs(colSingletonPivotLIDs_)
241 , ColSingletonPivots(colSingletonPivots_) {}
244 KOKKOS_INLINE_FUNCTION
245 void operator()(
const local_ordinal_type i)
const {
246 const LocalOrdinal INVALID = Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
247 const impl_scalar_type zero(0);
249 auto lclFullRowPtr = lclFullMatrix.graph.row_map;
250 auto lclFullColInd = lclFullMatrix.graph.entries;
251 auto lclFullValues = lclFullMatrix.values;
253 GlobalOrdinal glbID = lclFullRowMap.getGlobalElement(i);
254 LocalOrdinal lclID = lclReducedRowMap.getLocalElement(glbID);
256 if (lclID == INVALID) {
257 if (lclFullRowPtr(i + 1) == lclFullRowPtr(i) + 1) {
259 LocalOrdinal indX = lclFullColInd(lclFullRowPtr(i));
260 impl_scalar_type pivot = lclFullValues(lclFullRowPtr(i));
262 Kokkos::atomic_exchange(&error_code(0), 1);
264 for (LocalOrdinal j = 0; j < NumVectors; j++) {
265 localExportX(indX, j) = localRHS(i, j) / pivot;
272 for (local_ordinal_type j = 0; j < localNumSingletonCols; j++) {
273 if (ColSingletonRowLIDs[j] == i) {
278 Kokkos::atomic_exchange(&error_code(0), 3);
281 LocalOrdinal targetCol = ColSingletonColLIDs[myNum];
282 for (
size_t j = lclFullRowPtr(i); j < lclFullRowPtr(i + 1); j++) {
283 if (lclFullColInd[j] == targetCol) {
284 impl_scalar_type pivot = lclFullValues[j];
286 Kokkos::atomic_exchange(&error_code(0), 2);
288 ColSingletonPivotLIDs[myNum] = j - lclFullRowPtr(i);
289 ColSingletonPivots[myNum] = pivot;
300 KOKKOS_INLINE_FUNCTION
301 void operator()(
const local_ordinal_type i, local_ordinal_type& lclNumSingletonCols)
const {
302 const LocalOrdinal INVALID = Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
303 const impl_scalar_type zero(0);
305 auto lclFullRowPtr = lclFullMatrix.graph.row_map;
306 auto lclFullColInd = lclFullMatrix.graph.entries;
307 auto lclFullValues = lclFullMatrix.values;
309 GlobalOrdinal glbID = lclFullRowMap.getGlobalElement(i);
310 LocalOrdinal lclID = lclReducedRowMap.getLocalElement(glbID);
312 if (lclID == INVALID) {
314 if (lclFullRowPtr(i + 1) == lclFullRowPtr(i) + 1) {
316 LocalOrdinal indX = lclFullColInd(lclFullRowPtr(i));
317 impl_scalar_type pivot = lclFullValues(lclFullRowPtr(i));
319 Kokkos::atomic_exchange(&error_code(0), 1);
321 for (LocalOrdinal j = 0; j < NumVectors; j++) {
322 localExportX(indX, j) = localRHS(i, j) / pivot;
329 for (local_ordinal_type j = 0; j < localNumSingletonCols; j++) {
330 if (ColSingletonRowLIDs[j] == i) {
335 Kokkos::atomic_exchange(&error_code(0), 3);
337 size_t j = ColSingletonPivotLIDs[myNum] + lclFullRowPtr(i);
338 impl_scalar_type pivot = lclFullValues[j];
340 Kokkos::atomic_exchange(&error_code(0), 2);
342 ColSingletonPivots[myNum] = pivot;
344 lclNumSingletonCols++;
352template <
class View_type_
int,
class View_type_scalar,
class SOL_type,
class RHS_type>
353struct ComputeFullSolutionFunctor {
354 using scalar_type =
typename View_type_scalar::non_const_value_type;
356 View_type_int ColSingletonRowLIDs;
357 View_type_int ColSingletonColLIDs;
358 View_type_scalar ColSingletonPivots;
364 ComputeFullSolutionFunctor(View_type_int rowLIDs, View_type_int colLIDs, View_type_scalar pivots,
365 SOL_type X, RHS_type RHS, RHS_type B)
366 : ColSingletonRowLIDs(rowLIDs)
367 , ColSingletonColLIDs(colLIDs)
368 , ColSingletonPivots(pivots)
373 KOKKOS_INLINE_FUNCTION
374 void operator()(
const size_t k)
const {
375 int i = ColSingletonRowLIDs[k];
376 int j = ColSingletonColLIDs[k];
377 scalar_type pivot = ColSingletonPivots[k];
379 size_t NumVectors = localX.extent(1);
380 for (
size_t jj = 0; jj < NumVectors; jj++) {
381 localX(j, jj) = (localRHS(i, jj) - localB(i, jj)) / pivot;
386template <
class Map_color_type,
class LocalMap_type,
class IndexList_type>
387struct GenerateReducedMapFunctor {
389 Map_color_type mapColors;
390 LocalMap_type lclMap;
391 IndexList_type indexList;
394 using device_type =
typename Map_color_type::device_type;
395 Kokkos::View<size_t*, device_type> numView;
398 GenerateReducedMapFunctor(
int color_, Map_color_type mapColors_)
400 , mapColors(mapColors_) {}
403 GenerateReducedMapFunctor(
int color_, Map_color_type mapColors_, LocalMap_type lclMap_, IndexList_type indexList_)
405 , mapColors(mapColors_)
407 , indexList(indexList_) {
408 Kokkos::resize(numView, 1);
409 Kokkos::deep_copy(numView, 0);
413 KOKKOS_INLINE_FUNCTION
414 void operator()(
const size_t i,
size_t& num)
const {
415 if (mapColors(i, 0) == color) {
421 KOKKOS_INLINE_FUNCTION
422 void operator()(
const size_t i)
const {
423 if (mapColors(i, 0) == color) {
424 auto num = Kokkos::atomic_fetch_add(&numView(0), 1);
425 indexList(num) = lclMap.getGlobalElement(i);
432template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
435 : globalNumSingletonRows_(Teuchos::as<local_ordinal_type>(0))
436 , globalNumSingletonCols_(Teuchos::as<local_ordinal_type>(0))
437 , RatioOfDimensions_(0.0)
438 , RatioOfNonzeros_(0.0)
439 , HaveReducedProblem_(false)
440 , AnalysisDone_(false)
441 , SymmetricElimination_(true)
442 , localMaxNumRowEntries_(Teuchos::as<local_ordinal_type>(0))
443 , FullMatrixIsCrsMatrix_(false)
444 , run_on_host_(run_on_host)
445 , verbose_(verbose) {
450template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
451typename CrsSingletonFilter_LinearProblem<Scalar, LocalOrdinal, GlobalOrdinal, Node>::NewType
453operator()(
const CrsSingletonFilter_LinearProblem::OriginalType& originalLinearProblem) {
454 analyze(originalLinearProblem);
460template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
462 analyze(
const CrsSingletonFilter_LinearProblem::OriginalType& originalLinearProblem) {
463 this->origObj_ = originalLinearProblem;
465 FullMatrix_ = originalLinearProblem->getMatrix();
469 if (verbose_ &&
FullMatrix()->getComm()->getRank() == 0) {
470 std::cout <<
"\nAnalyzed Singleton Problem:\n";
471 std::cout <<
"---------------------------\n";
474 if (verbose_ &&
FullMatrix()->getComm()->getRank() == 0) {
475 std::cout <<
"Singletons Detected!" << std::endl;
476 std::cout <<
"Num Singletons: " <<
NumSingletons() << std::endl;
479 if (verbose_ &&
FullMatrix()->getComm()->getRank() == 0)
480 std::cout <<
"No Singletons Detected!" << std::endl;
483 if (verbose_ &&
FullMatrix()->getComm()->getRank() == 0)
484 std::cout <<
"---------------------------\n\n";
491template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
492typename CrsSingletonFilter_LinearProblem<Scalar, LocalOrdinal, GlobalOrdinal, Node>::NewType
495 const char tfecfFuncName[] =
"construct: ";
497 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(this->origObj_ == Teuchos::null, std::runtime_error,
498 "Linear problem (orgiObj_) have not been set. Call analyze() first.");
505 std::cout <<
"\nConstructedSingleton Problem:\n";
506 std::cout <<
"---------------------------\n";
509 std::cout <<
"---------------------------\n\n";
512 return this->newObj_;
517template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
525template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
533template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
535 Analyze(
const Teuchos::RCP<row_matrix_type>& fullMatrix) {
536 const char tfecfFuncName[] =
"Analyze: ";
538 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(AnalysisDone_, std::runtime_error,
539 "Analyze() already done once. Cannot do it again.");
541 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(fullMatrix == Teuchos::null,
542 std::runtime_error,
"Input matrix is Teuchos::null.");
544 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(fullMatrix->getGlobalNumRows() == 0,
545 std::runtime_error,
"Full matrix has zero dimension.");
547 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(fullMatrix->getGlobalNumEntries() == 0,
548 std::runtime_error,
"Full matrix has no nonzero terms.");
550 FullMatrix_ = fullMatrix;
553 vector_type_int ColProfiles(FullMatrixColMap());
555 vector_type_int ColHasRowWithSingleton(FullMatrixColMap());
560 vector_type_LO localRowIDofSingletonCol(FullMatrixColMap());
561 localRowIDofSingletonCol.
putScalar(Teuchos::OrdinalTraits<LocalOrdinal>::invalid());
564 RowMapColors_ = Teuchos::rcp(
new vector_type_int(FullMatrixRowMap()));
565 ColMapColors_ = Teuchos::rcp(
new vector_type_int(FullMatrixColMap()));
567 local_ordinal_type localNumRows =
FullMatrix()->getLocalNumRows();
568 local_ordinal_type localNumCols =
FullMatrix()->getLocalNumCols();
571 InitFullMatrixAccess();
576 size_t NumIndices = 1;
579 Teuchos::Array<local_ordinal_type> localIndices;
580 auto ColProfilesData = ColProfiles.
getLocalViewHost(Tpetra::Access::ReadWrite);
581 auto localRowIDofSingletonColData = localRowIDofSingletonCol.
getLocalViewHost(Tpetra::Access::ReadWrite);
582 auto ColHasRowWithSingletonData = ColHasRowWithSingleton.
getLocalViewHost(Tpetra::Access::ReadWrite);
583 auto RowMapColors_Data = RowMapColors_->getLocalViewHost(Tpetra::Access::ReadWrite);
584 auto ColMapColors_Data = ColMapColors_->getLocalViewHost(Tpetra::Access::ReadWrite);
586 for (
int i = 0; i < localNumRows; i++) {
588 GetRow(i, NumIndices, localIndices);
589 for (
size_t j = 0; j < NumIndices; j++) {
590 local_ordinal_type ColumnIndex = localIndices[j];
593 if (
static_cast<size_t>(ColumnIndex) >= ColProfilesData.extent(0)) {
594 std::cout <<
"Error: ColumnIndex out of bounds: " << ColumnIndex << std::endl;
598 ColProfilesData(ColumnIndex, 0)++;
600 if (
static_cast<size_t>(ColumnIndex) >= localRowIDofSingletonColData.extent(0)) {
601 std::cout <<
"Error: ColumnIndex out of bounds for localRowIDofSingletonColData: "
602 << ColumnIndex << std::endl;
608 localRowIDofSingletonColData(ColumnIndex, 0) = i;
611 if (NumIndices == 1) {
612 int j2 = localIndices[0];
613 ColHasRowWithSingletonData(j2, 0)++;
614 RowMapColors_Data(i, 0) = 1;
615 ColMapColors_Data(j2, 0) = 1;
620 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!FullMatrixIsCrsMatrix_, std::runtime_error,
621 "Error: FullMatrix is not CrsMatrix");
624 auto localRowIDofSingletonColData = localRowIDofSingletonCol.
getLocalViewDevice(Tpetra::Access::ReadWrite);
625 auto ColHasRowWithSingletonData = ColHasRowWithSingleton.
getLocalViewDevice(Tpetra::Access::ReadWrite);
626 auto RowMapColors_Data = RowMapColors_->getLocalViewDevice(Tpetra::Access::ReadWrite);
627 auto ColMapColors_Data = ColMapColors_->getLocalViewDevice(Tpetra::Access::ReadWrite);
629 Kokkos::View<int*, execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged | Kokkos::Atomic>>
630 ColProfilesAtomic(ColProfilesData.data(), ColProfilesData.extent(0));
631 Kokkos::View<int*, execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged | Kokkos::Atomic>>
632 ColHasRowWithSingletonAtomic(ColHasRowWithSingletonData.data(), ColHasRowWithSingletonData.extent(0));
633 Kokkos::View<int*, execution_space, Kokkos::MemoryTraits<Kokkos::Unmanaged | Kokkos::Atomic>>
634 ColMapColors_Atomic(ColMapColors_Data.data(), ColMapColors_Data.extent(0));
635 Kokkos::View<int*, execution_space> error_code(
"singleton-bound-check", 2);
636 Kokkos::deep_copy(error_code, 0);
638 auto lclRowPtr = FullCrsMatrix_->getLocalRowPtrsDevice();
639 auto lclColInd = FullCrsMatrix_->getLocalIndicesDevice();
641 Kokkos::parallel_reduce(
642 "CrsSingletonFilter_LinearProblem:Analyze(find-singleton-row)", range_policy(0, localNumRows),
643 KOKKOS_LAMBDA(
const size_t i, local_ordinal_type& lclNumSingletonRows) {
645 for (
size_t k = lclRowPtr(i); k < lclRowPtr(i + 1); k++) {
646 local_ordinal_type ColumnIndex = lclColInd(k);
649 if (
static_cast<size_t>(ColumnIndex) >= ColProfilesData.extent(0)) {
650 Kokkos::atomic_exchange(&error_code(0), ColumnIndex + 1);
652 ColProfilesAtomic(ColumnIndex)++;
656 if (
static_cast<size_t>(ColumnIndex) >= localRowIDofSingletonColData.extent(0)) {
657 Kokkos::atomic_exchange(&error_code(1), ColumnIndex + 1);
663 Kokkos::atomic_max(&localRowIDofSingletonColData(ColumnIndex, 0), i);
667 if (lclRowPtr(i + 1) == lclRowPtr(i) + 1) {
668 local_ordinal_type ColumnIndex = lclColInd(lclRowPtr(i));
669 RowMapColors_Data(i, 0) = 1;
672 ColHasRowWithSingletonAtomic(ColumnIndex)++;
673 ColMapColors_Atomic(ColumnIndex) = 1;
674 lclNumSingletonRows++;
681 auto h_error = Kokkos::create_mirror_view(error_code);
682 Kokkos::deep_copy(h_error, error_code);
683 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(h_error(0) > 0, std::runtime_error,
684 "Error: ColumnIndex out of bounds: " + std::to_string(h_error(0)));
685 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(h_error(1) > 0, std::runtime_error,
686 "Error: ColumnIndex out of bounds for localRowIDofSingletonColData " + std::to_string(h_error(1)));
697 vector_type_int NewColProfiles(ColProfiles.
getMap());
698 NewColProfiles.
update(1.0, ColProfiles, 0.0);
701 auto importer = FullCrsMatrix()->getCrsGraph()->getImporter();
702 if (importer != Teuchos::null) {
703 vector_type_int tmpVec(FullMatrixDomainMap());
709 tmpVec.
doExport(ColHasRowWithSingleton, *importer,
ADD);
722 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(ColHasRowWithSingleton.
normInf() > 1, std::runtime_error,
723 "At least one column is associated with two singleton rows, can't handle it.");
726 vector_type_int RowHasColWithSingleton(
FullMatrix()->getRowMap());
729 size_t NumIndices = 1;
732 Teuchos::Array<local_ordinal_type> localIndices;
734 auto ColProfilesData = ColProfiles.
getLocalViewHost(Tpetra::Access::ReadOnly);
735 auto localRowIDofSingletonColData = localRowIDofSingletonCol.
getLocalViewHost(Tpetra::Access::ReadOnly);
736 auto ColHasRowWithSingletonData = ColHasRowWithSingleton.
getLocalViewHost(Tpetra::Access::ReadOnly);
738 auto RowMapColors_Data = RowMapColors_->getLocalViewHost(Tpetra::Access::ReadWrite);
739 auto ColMapColors_Data = ColMapColors_->getLocalViewHost(Tpetra::Access::ReadWrite);
741 auto NewColProfilesData = NewColProfiles.
getLocalViewHost(Tpetra::Access::ReadWrite);
742 auto RowHasColWithSingletonData = RowHasColWithSingleton.
getLocalViewHost(Tpetra::Access::ReadWrite);
745 for (local_ordinal_type j = 0; j < localNumCols; j++) {
746 local_ordinal_type i2 = localRowIDofSingletonColData(j, 0);
748 if (ColProfilesData(j, 0) == 1) {
750 if (RowMapColors_Data(i2, 0) != 1) {
751 RowHasColWithSingletonData(i2, 0)++;
752 RowMapColors_Data(i2, 0) = 2;
753 ColMapColors_Data(j, 0) = 1;
758 GetRow(i2, NumIndices, localIndices);
759 for (
size_t jj = 0; jj < NumIndices; jj++) {
760 NewColProfilesData(localIndices[jj], 0)--;
765 else if (ColHasRowWithSingletonData(j, 0) == 1 && RowMapColors_Data(i2, 0) != 1) {
766 ColMapColors_Data(j, 0) = 1;
771 auto localRowIDofSingletonColData = localRowIDofSingletonCol.
getLocalViewDevice(Tpetra::Access::ReadOnly);
772 auto ColHasRowWithSingletonData = ColHasRowWithSingleton.
getLocalViewDevice(Tpetra::Access::ReadOnly);
774 auto RowMapColors_Data = RowMapColors_->getLocalViewDevice(Tpetra::Access::ReadWrite);
775 auto ColMapColors_Data = ColMapColors_->getLocalViewDevice(Tpetra::Access::ReadWrite);
777 auto NewColProfilesData = NewColProfiles.
getLocalViewDevice(Tpetra::Access::ReadWrite);
778 auto RowHasColWithSingletonData = RowHasColWithSingleton.
getLocalViewDevice(Tpetra::Access::ReadWrite);
780 auto lclRowPtr = FullCrsMatrix_->getLocalRowPtrsDevice();
781 auto lclColInd = FullCrsMatrix_->getLocalIndicesDevice();
784 Kokkos::parallel_reduce(
785 "CrsSingletonFilter_LinearProblem:Analyze(find-singleton-column)", range_policy(0, localNumCols),
786 KOKKOS_LAMBDA(
const size_t j, local_ordinal_type& lclNumSingletonCols) {
788 if (ColProfilesData(j, 0) == 1) {
791 local_ordinal_type i = localRowIDofSingletonColData(j, 0);
799 if (RowMapColors_Data(i, 0) != 1) {
800 RowMapColors_Data(i, 0) = 2;
801 ColMapColors_Data(j, 0) = 1;
802 lclNumSingletonCols++;
805 RowHasColWithSingletonData(i, 0)++;
811 for (
size_t k = lclRowPtr(i); k < lclRowPtr(i + 1); k++) {
812 NewColProfilesData(lclColInd(k), 0)--;
818 Kokkos::parallel_for(
819 "CrsSingletonFilter_LinearProblem:Analyze(find-non-singleton-column)", range_policy(0, localNumCols),
820 KOKKOS_LAMBDA(
const size_t j) {
822 if (ColProfilesData(j, 0) != 1) {
825 local_ordinal_type i = localRowIDofSingletonColData(j, 0);
833 if (ColHasRowWithSingletonData(j, 0) == 1 && RowMapColors_Data(i, 0) != 1) {
836 ColMapColors_Data(j, 0) = 1;
843 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(RowHasColWithSingleton.
normInf() > 1, std::runtime_error,
844 "At least one row is associated with two singleton columns, can't handle it.");
847 CreatePostSolveArrays(localRowIDofSingletonCol, ColProfiles, NewColProfiles, ColHasRowWithSingleton);
849 auto RowMapColors_Data = RowMapColors_->getLocalViewHost(Tpetra::Access::ReadWrite);
850 for (local_ordinal_type i = 0; i < localNumRows; i++) {
851 if (RowMapColors_Data(i, 0) == 2) RowMapColors_Data(i, 0) = 1;
854 auto RowMapColors_Data = RowMapColors_->getLocalViewDevice(Tpetra::Access::ReadWrite);
855 Kokkos::parallel_for(
856 "CrsSingletonFilter_LinearProblem:Analyze(convert-rowmap-color)", range_policy(0, localNumRows),
857 KOKKOS_LAMBDA(
const size_t i) {
858 if (RowMapColors_Data(i, 0) == 2) RowMapColors_Data(i, 0) = 1;
862 const Teuchos::Ptr<local_ordinal_type> gRowsPtr(&globalNumSingletonRows_);
863 const Teuchos::Ptr<local_ordinal_type> gColsPtr(&globalNumSingletonCols_);
864 auto rowComm =
FullMatrix()->getRowMap()->getComm();
865 Teuchos::reduceAll<local_ordinal_type, local_ordinal_type>(*rowComm, Teuchos::REDUCE_SUM,
localNumSingletonRows_, gRowsPtr);
866 Teuchos::reduceAll<local_ordinal_type, local_ordinal_type>(*rowComm, Teuchos::REDUCE_SUM,
localNumSingletonCols_, gColsPtr);
868 AnalysisDone_ =
true;
874template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
875Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
878 const Teuchos::RCP<vector_type_int>& mapColors,
int color,
879 bool locally_sort_gids) {
880 Teuchos::RCP<const map_type> reducedMap;
881 bool canRunOnHost = std::is_same_v<typename device_type::memory_space, Kokkos::HostSpace>;
882 if (run_on_host_ && canRunOnHost) {
884 std::vector<GlobalOrdinal> myReducedGlobalIndices;
887 auto myGlobalIndices = originalMap->getMyGlobalIndices();
890 for (
size_t i = 0; i < myGlobalIndices.size(); i++) {
892 int colorValue = mapColors->getData()[i];
893 if (colorValue == color) {
894 myReducedGlobalIndices.push_back(myGlobalIndices[i]);
900 Teuchos::ArrayView<const GlobalOrdinal>(myReducedGlobalIndices.data(), myReducedGlobalIndices.size()),
901 originalMap->getComm());
904 using IndexListType = Kokkos::View<GlobalOrdinal*, device_type>;
905 using functor_type = GenerateReducedMapFunctor<local_vector_int_type, local_map_type, IndexListType>;
906 auto mapColors_Data = mapColors->getLocalViewDevice(Tpetra::Access::ReadWrite);
909 size_t lclNumReducedElements = 0;
910 size_t lclNumElements = originalMap->getLocalNumElements();
912 functor_type functor(color, mapColors_Data);
913 Kokkos::parallel_reduce(
914 "CrsSingletonFilter_LinearProblem:GenerateReduceMap(count)", range_policy(0, lclNumElements),
915 functor, lclNumReducedElements);
918 IndexListType indexList;
920 auto lclMap = originalMap()->getLocalMap();
921 Kokkos::resize(indexList, lclNumReducedElements);
922 functor_type functor(color, mapColors_Data, lclMap, indexList);
923 Kokkos::parallel_for(
924 "CrsSingletonFilter_LinearProblem:GenerateReduceMap(insert)", range_policy(0, lclNumElements),
927 if (locally_sort_gids) {
933 const Tpetra::global_size_t INVALID = Tpetra::Details::OrdinalTraits<Tpetra::global_size_t>::invalid();
934 reducedMap = Teuchos::rcp(
new map_type(INVALID, indexList,
935 originalMap->getIndexBase(),
936 originalMap->getComm()));
944template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
947 const char tfecfFuncName[] =
"ConstructReducedProblem: ";
949 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(HaveReducedProblem_, std::runtime_error,
950 "Already have a reduced problem. Cannot do it again.");
952 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(Problem == Teuchos::null,
953 std::runtime_error,
"Problem is Teuchos::null.");
955 FullProblem_ = Problem;
956 FullMatrix_ = Teuchos::rcp_dynamic_cast<row_matrix_type>(Problem->getMatrix());
957 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
FullMatrix() == Teuchos::null,
958 std::runtime_error,
"Need a RowMatrix.");
959 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(Problem->getRHS() == Teuchos::null,
960 std::runtime_error,
"Need a RHS.");
961 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(Problem->getLHS() == Teuchos::null,
962 std::runtime_error,
"Need a LHS.");
964 Scalar zero = Teuchos::ScalarTraits<Scalar>::zero();
968 ReducedMatrixRowMap_ = GenerateReducedMap(FullMatrixRowMap(), RowMapColors_, 0);
969 ReducedMatrixColMap_ = GenerateReducedMap(FullMatrixColMap(), ColMapColors_, 0);
972 auto importer = FullCrsMatrix()->getCrsGraph()->getImporter();
973 if (importer != Teuchos::null) {
974 Teuchos::RCP<vector_type_int> DomainMapColors = Teuchos::rcp(
new vector_type_int(FullMatrixDomainMap()));
975 DomainMapColors->doExport(*ColMapColors_, *importer,
Tpetra::ABSMAX);
976 OrigReducedMatrixDomainMap_ = GenerateReducedMap(FullMatrixDomainMap(), DomainMapColors, 0);
981 auto exporter = FullCrsMatrix()->getCrsGraph()->getImporter();
982 if (FullMatrixIsCrsMatrix_) {
983 if (exporter != Teuchos::null) {
984 Teuchos::RCP<vector_type_int> RangeMapColors = Teuchos::rcp(
new vector_type_int(FullMatrixRangeMap()));
985 RangeMapColors->doExport(*ColMapColors_, *exporter,
Tpetra::ABSMAX);
986 ReducedMatrixRangeMap_ = GenerateReducedMap(FullMatrixRangeMap(), RangeMapColors, 0);
996 if (!SymmetricElimination_) {
997 ConstructRedistributeExporter(OrigReducedMatrixDomainMap_, ReducedMatrixRangeMap_,
998 RedistributeDomainExporter_, ReducedMatrixDomainMap_);
1000 ReducedMatrixDomainMap_ = OrigReducedMatrixDomainMap_;
1001 OrigReducedMatrixDomainMap_ = Teuchos::null;
1002 RedistributeDomainExporter_ = Teuchos::null;
1006 Teuchos::RCP<multivector_type> FullRHS =
FullProblem()->getRHS();
1007 Teuchos::RCP<multivector_type> FullLHS =
FullProblem()->getLHS();
1008 local_ordinal_type NumVectors = FullLHS->getNumVectors();
1011 Full2ReducedLHSImporter_ = Teuchos::rcp(
new import_type(FullMatrixDomainMap(),
ReducedMatrixDomainMap()));
1012 Full2ReducedRHSImporter_ = Teuchos::rcp(
new import_type(FullRHS->getMap(),
ReducedMatrixRowMap()));
1015 tempExportX_ = Teuchos::rcp(
new multivector_type(FullMatrixColMap(), NumVectors));
1017 size_t NumEntries = 0;
1018 Teuchos::ArrayView<const Scalar> Values;
1019 Teuchos::Array<GlobalOrdinal> Indices;
1020 LocalOrdinal localNumRows =
FullMatrix()->getLocalNumRows();
1021 LocalOrdinal ColSingletonCounter = 0;
1024 bool canRunOnHost = std::is_same_v<typename device_type::memory_space, Kokkos::HostSpace>;
1025 if (run_on_host_ && canRunOnHost) {
1027 LocalOrdinal maxNumEntries = FullCrsMatrix()->getLocalMaxNumRowEntries();
1030 for (LocalOrdinal i = 0; i < localNumRows; i++) {
1031 GlobalOrdinal curGRID = FullMatrixRowMap()->getGlobalElement(i);
1033 GetRowGCIDs(i, NumEntries, Values, Indices);
1038 Teuchos::Array<GlobalOrdinal> filteredIndices;
1039 Teuchos::Array<Scalar> filteredValues;
1041 for (
typename Teuchos::Array<GlobalOrdinal>::size_type j = 0; j < Indices.size(); ++j) {
1043 filteredIndices.push_back(Indices[j]);
1044 filteredValues.push_back(Values[j]);
1049 if (!filteredIndices.empty()) {
1050 ReducedMatrix()->insertGlobalValues(curGRID, filteredIndices(), filteredValues());
1054 Teuchos::ArrayView<const LocalOrdinal> localIndices;
1055 GetRow(i, NumEntries, Values, localIndices);
1056 if (NumEntries == 1) {
1057 Scalar pivot = Values[0];
1058 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(pivot == zero, std::runtime_error,
1059 "Encountered zero row, unable to continue.");
1060 LocalOrdinal indX = localIndices[0];
1061 for (LocalOrdinal j = 0; j < NumVectors; j++) {
1062 auto rhsData = FullRHS->getData(j);
1063 auto exportData = tempExportX_->getDataNonConst(j);
1064 exportData[indX] = rhsData[i] / pivot;
1067 LocalOrdinal targetCol = ColSingletonColLIDs_[ColSingletonCounter];
1068 for (
size_t j = 0; j < NumEntries; j++) {
1069 if (localIndices[j] == targetCol) {
1070 Scalar pivot = Values[j];
1071 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(pivot == zero, std::runtime_error,
1072 "Encountered zero column, unable to continue.");
1073 ColSingletonPivotLIDs_[ColSingletonCounter] = j;
1074 ColSingletonPivots_[ColSingletonCounter] = pivot;
1075 ColSingletonCounter++;
1095 using graph_type =
typename local_matrix_type::StaticCrsGraphType;
1096 using row_map_type =
typename graph_type::row_map_type::non_const_type;
1097 using entries_type =
typename graph_type::entries_type::non_const_type;
1098 using values_type =
typename local_matrix_type::values_type;
1099 using functor_type = ConstructReducedProblemFunctor<local_ordinal_type, global_ordinal_type, local_map_type, local_matrix_type, row_map_type, entries_type, values_type>;
1102 auto lclFullRowMap = FullMatrixRowMap()->getLocalMap();
1103 auto lclFullColMap = FullMatrixColMap()->getLocalMap();
1107 auto lclFullMatrix = FullCrsMatrix_->getLocalMatrixDevice();
1110 row_map_type rowmap_view(
"rowmap_view", localNumReducedRows + 1);
1111 entries_type column_view(
"colind_view", nnzA);
1112 values_type values_view(
"values_view", nnzA);
1116 Kokkos::deep_copy(rowmap_view, 0);
1118 functor_type functor(lclFullRowMap, lclFullColMap, lclReducedRowMap, lclReducedColMap,
1119 lclFullMatrix, rowmap_view, column_view, values_view);
1120 Kokkos::parallel_reduce(
1121 "CrsSingletonFilter_LinearProblem:CountReducedProblem", range_policy(0, localNumRows),
1126#if KOKKOSKERNELS_VERSION >= 50299
1127 KokkosKernels::inclusive_parallel_prefix_sum(execution_space(), rowmap_view);
1129 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) {
1283 for (LocalOrdinal i = 0; i < localNumRows; i++) {
1284 GlobalOrdinal curGRID = FullMatrixRowMap()->getGlobalElement(i);
1286 GetRowGCIDs(i, NumEntries, Values, Indices);
1289 Teuchos::Array<GlobalOrdinal> filteredIndices;
1290 Teuchos::Array<Scalar> filteredValues;
1292 for (
typename Teuchos::Array<GlobalOrdinal>::size_type j = 0; j < Indices.size(); ++j) {
1294 filteredIndices.push_back(Indices[j]);
1295 filteredValues.push_back(Values[j]);
1300 if (!filteredIndices.empty()) {
1301 ReducedMatrix()->replaceGlobalValues(curGRID, filteredIndices(), filteredValues());
1307 Teuchos::ArrayView<const LocalOrdinal> localIndices;
1308 GetRow(i, NumEntries, Values, localIndices);
1309 if (NumEntries == 1) {
1310 Scalar pivot = Values[0];
1311 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(pivot == zero, std::runtime_error,
1312 "Encountered zero row, unable to continue.");
1313 LocalOrdinal indX = localIndices[0];
1314 for (LocalOrdinal j = 0; j < NumVectors; j++) {
1315 auto rhsData = FullRHS->getData(j);
1316 auto exportData = tempExportX_->getDataNonConst(j);
1317 exportData[indX] = rhsData[i] / pivot;
1320 LocalOrdinal j = ColSingletonPivotLIDs_[ColSingletonCounter];
1322 Scalar pivot = Values[j];
1323 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(pivot == zero, std::runtime_error,
1324 "Encountered zero column, unable to continue.");
1325 ColSingletonPivots_[ColSingletonCounter] = pivot;
1326 ColSingletonCounter++;
1334 using error_code_type =
typename Kokkos::View<int*, execution_space>;
1335 using functor_type = SolveSingletonProblemFunctor<scalar_type, local_ordinal_type, global_ordinal_type, Node, local_map_type, local_matrix_type,
1336 local_multivector_type, const_local_multivector_type,
1337 vector_view_type_int, vector_view_type_scalar, error_code_type>;
1339 auto lclFullRowMap = FullMatrixRowMap()->getLocalMap();
1340 auto lclFullColMap = FullMatrixColMap()->getLocalMap();
1343 auto lclFullMatrix = FullCrsMatrix_->getLocalMatrixDevice();
1345 auto localRHS = FullRHS->getLocalViewDevice(Tpetra::Access::ReadOnly);
1346 auto localExportX = tempExportX_->getLocalViewDevice(Tpetra::Access::ReadWrite);
1348 error_code_type error_code(
"singleton-bound-check", 2);
1349 Kokkos::deep_copy(error_code, 0);
1353 lclFullRowMap, lclFullColMap, lclReducedRowMap,
1354 lclFullMatrix, localExportX, localRHS,
1355 ColSingletonColLIDs_, ColSingletonRowLIDs_, ColSingletonPivotLIDs_, ColSingletonPivots_);
1356 Kokkos::parallel_reduce(
1357 "CrsSingletonFilter_LinearProblem:SolveSingletonProblem", range_policy(0, localNumRows),
1358 functor, ColSingletonCounter);
1361 auto h_error = Kokkos::create_mirror_view(error_code);
1362 Kokkos::deep_copy(h_error, error_code);
1363 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(h_error(0) == 1, std::runtime_error,
1364 "UpdateReducedProblem: Encountered zero row, unable to continue.");
1365 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(h_error(0) == 2, std::runtime_error,
1366 "UpdateReducedProblem: Encountered zero column, unable to continue.");
1367 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(h_error(0) == 3, std::runtime_error,
1368 "UpdateReducedProblem: Unable to find local column.");
1372 using functor_type = UpdateReducedProblemFunctor<local_ordinal_type, global_ordinal_type, local_map_type, local_matrix_type>;
1373 auto lclFullRowMap = FullMatrixRowMap()->getLocalMap();
1374 auto lclFullColMap = FullMatrixColMap()->getLocalMap();
1378 auto lclReducedMatrix = ReducedMatrix_->getLocalMatrixDevice();
1379 auto lclFullMatrix = FullCrsMatrix_->getLocalMatrixDevice();
1382 functor_type functor(lclFullRowMap, lclFullColMap, lclReducedRowMap, lclReducedColMap,
1383 lclFullMatrix, lclReducedMatrix);
1384 Kokkos::parallel_for(
1385 "CrsSingletonFilter_LinearProblem:UpdateReducedProblem", range_policy(0, localNumRows),
1391 std::runtime_error,
"Sanity Check " + std::to_string(ColSingletonCounter) +
" vs " + std::to_string(
localNumSingletonCols_) +
" (UpdateReducedProblem).");
1395 ReducedLHS_->putScalar(0.0);
1396 ReducedRHS_->doImport(*FullLHS, *Full2ReducedRHSImporter_,
Tpetra::INSERT);
1398 FullLHS->putScalar(0.0);
1403 tempX_->putScalar(0.0);
1404 tempB_->putScalar(0.0);
1409 auto importer = FullCrsMatrix()->getCrsGraph()->getImporter();
1410 if (importer != Teuchos::null) {
1411 tempX_->doExport(*tempExportX_, *importer,
Tpetra::ADD);
1412 FullLHS->doExport(*tempExportX_, *importer,
Tpetra::ADD);
1414 tempX_->update(1.0, *tempExportX_, 0.0);
1415 FullLHS->update(1.0, *tempExportX_, 0.0);
1419 tempB_->update(1.0, *FullRHS, -1.0);
1421 ReducedRHS_->putScalar(0.0);
1422 ReducedRHS_->doImport(*tempB_, *Full2ReducedRHSImporter_,
Tpetra::INSERT);
1426 ReducedProblem_ = Problem;
1427 ReducedMatrix_ = Teuchos::rcp(
dynamic_cast<crs_matrix_type*
>(Problem->getMatrix().getRawPtr()),
false);
1434template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1437 Teuchos::RCP<export_type>& RedistributeExporter,
1438 Teuchos::RCP<const map_type>& RedistributeMap) {
1439 const char tfecfFuncName[] =
"ConstructRedistributeExporter: ";
1441 auto IndexBase = SourceMap->getIndexBase();
1442 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(IndexBase != TargetMap->getIndexBase(), std::runtime_error,
1443 "Base indices do not match.");
1445 auto Comm = TargetMap->getComm();
1447 size_t TargetNumMyElements = TargetMap->getLocalNumElements();
1448 size_t SourceNumMyElements = SourceMap->getLocalNumElements();
1451 Teuchos::RCP<const map_type> ContiguousTargetMap =
1453 Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid(),
1454 TargetNumMyElements, IndexBase, Comm));
1457 Teuchos::RCP<const map_type> ContiguousSourceMap =
1459 Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid(),
1460 SourceNumMyElements, IndexBase, Comm));
1462 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1463 ContiguousSourceMap->getGlobalNumElements() != ContiguousTargetMap->getGlobalNumElements(),
1464 std::runtime_error,
"Global number of elements do not match.");
1467 auto SourceMapMyGlobalIndices = SourceMap->getMyGlobalIndices();
1470 Teuchos::RCP<Tpetra::MultiVector<GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node>> SourceIndices =
1474 for (
size_t i = 0; i < static_cast<size_t>(SourceMapMyGlobalIndices.size()); ++i) {
1475 SourceIndices->replaceLocalValue(i, 0,
static_cast<GlobalOrdinal
>(SourceMapMyGlobalIndices[i]));
1479 auto map = SourceIndices->getMap();
1481 Teuchos::RCP<Tpetra::Export<LocalOrdinal, GlobalOrdinal, Node>> Exporter =
1484 Teuchos::RCP<Tpetra::MultiVector<GlobalOrdinal, LocalOrdinal, GlobalOrdinal, Node>> TargetIndices =
1487 TargetIndices->doExport(*SourceIndices, *Exporter,
Tpetra::INSERT);
1492 Teuchos::ArrayView<const GlobalOrdinal>(TargetIndices->getData(0).getRawPtr(), TargetIndices->getLocalLength()),
1495 RedistributeExporter =
1502template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1506 Teuchos::RCP<multivector_type> FullLHS =
FullProblem()->getLHS();
1507 Teuchos::RCP<multivector_type> FullRHS =
FullProblem()->getRHS();
1509 tempX_->putScalar(Scalar(0.0));
1510 tempExportX_->putScalar(Scalar(0.0));
1513 tempX_->doExport(*ReducedLHS_, *Full2ReducedLHSImporter_,
Tpetra::ADD);
1514 FullLHS->update(Scalar(1.0), *tempX_, Scalar(1.0));
1523 size_t NumVectors = tempB_->getNumVectors();
1524 bool canRunOnHost = std::is_same_v<typename device_type::memory_space, Kokkos::HostSpace>;
1525 if (run_on_host_ && canRunOnHost) {
1527 LocalOrdinal i = ColSingletonRowLIDs_[k];
1528 LocalOrdinal j = ColSingletonColLIDs_[k];
1529 Scalar pivot = ColSingletonPivots_[k];
1530 for (
size_t jj = 0; jj < NumVectors; jj++) {
1531 auto tempExportXData = tempExportX_->getDataNonConst(jj);
1532 auto FullRHSData = FullRHS->getData(jj);
1533 auto tempBData = tempB_->getData(jj);
1534 tempExportXData[j] = (FullRHSData[i] - tempBData[i]) / pivot;
1538 using functor_type = ComputeFullSolutionFunctor<vector_view_type_int, vector_view_type_scalar,
1539 local_multivector_type, const_local_multivector_type>;
1540 auto localB = tempB_->getLocalViewDevice(Tpetra::Access::ReadOnly);
1541 auto localRHS = FullRHS->getLocalViewDevice(Tpetra::Access::ReadOnly);
1542 auto localX = tempExportX_->getLocalViewDevice(Tpetra::Access::ReadWrite);
1544 functor_type functor(ColSingletonRowLIDs_, ColSingletonColLIDs_, ColSingletonPivots_, localX, localRHS, localB);
1545 Kokkos::parallel_for(
1551 auto importer =
FullMatrix()->getGraph()->getImporter();
1552 if (importer != Teuchos::null) {
1553 tempX_->doExport(*tempExportX_, *importer,
Tpetra::ADD);
1555 tempX_->update(Scalar(1.0), *tempExportX_, Scalar(0.0));
1558 FullLHS->update(Scalar(1.0), *tempX_, Scalar(1.0));
1565template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1568 localMaxNumRowEntries_ = FullMatrix()->getLocalMaxNumRowEntries();
1571 FullCrsMatrix_ = Teuchos::rcp_dynamic_cast<crs_matrix_type>(FullMatrix());
1572 FullMatrixIsCrsMatrix_ = (FullCrsMatrix() != Teuchos::null);
1579template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1580void CrsSingletonFilter_LinearProblem<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
1581 GetRow(local_ordinal_type localRow,
size_t& NumIndices,
1582 Teuchos::Array<local_ordinal_type>& localIndices) {
1584 size_t maxNumEntries = FullCrsMatrix()->getLocalMaxNumRowEntries();
1585 nonconst_local_inds_host_view_type Indices(
"indices", maxNumEntries);
1586 nonconst_values_host_view_type Values(
"values", maxNumEntries);
1587 if (FullMatrixIsCrsMatrix_) {
1588 FullCrsMatrix()->getLocalRowCopy(localRow, Indices, Values, NumIndices);
1590 FullMatrix()->getLocalRowCopy(localRow, Indices, Values, NumIndices);
1597 localIndices.resize(NumIndices);
1598 for (
size_t i = 0; i < NumIndices; ++i) {
1599 localIndices[i] = Indices(i);
1606template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1608 GetRow(LocalOrdinal Row,
size_t& NumIndices, Teuchos::ArrayView<const Scalar>& Values,
1609 Teuchos::ArrayView<const LocalOrdinal>& Indices) {
1610 typename Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::local_inds_host_view_type localIndices;
1611 typename Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::values_host_view_type rowValues;
1613 if (FullMatrixIsCrsMatrix_) {
1614 FullCrsMatrix()->getLocalRowView(Row, localIndices, rowValues);
1616 NumIndices = localIndices.size();
1617 Values = Teuchos::ArrayView<const Scalar>(
reinterpret_cast<const Scalar*
>(rowValues.data()), rowValues.size());
1618 Indices = Teuchos::ArrayView<const LocalOrdinal>(localIndices.data(), localIndices.size());
1621 typename Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::nonconst_local_inds_host_view_type localIndicesCopy(
"localIndicesCopy", FullMatrix()->getLocalMaxNumRowEntries());
1622 typename Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::nonconst_values_host_view_type rowValuesCopy(
"rowValuesCopy", FullMatrix()->getLocalMaxNumRowEntries());
1624 FullMatrix()->getLocalRowCopy(Row, localIndicesCopy, rowValuesCopy, NumIndices);
1626 Values = Teuchos::ArrayView<const Scalar>(
reinterpret_cast<const Scalar*
>(rowValuesCopy.data()), NumIndices);
1627 Indices = Teuchos::ArrayView<const LocalOrdinal>(localIndicesCopy.data(), NumIndices);
1634template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1637 LocalOrdinal localRow,
1639 Teuchos::ArrayView<const Scalar>& Values,
1640 Teuchos::Array<GlobalOrdinal>& GlobalIndices) {
1642 typename Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::local_inds_host_view_type LocalIndices;
1643 typename Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>::values_host_view_type RowValues;
1645 FullMatrix()->getLocalRowView(localRow, LocalIndices, RowValues);
1648 NumIndices = LocalIndices.size();
1649 GlobalIndices.resize(NumIndices);
1650 for (
size_t j = 0; j < NumIndices; ++j) {
1651 GlobalIndices[j] = FullMatrixColMap()->getGlobalElement(LocalIndices[j]);
1654 Values = Teuchos::ArrayView<const Scalar>(
reinterpret_cast<const Scalar*
>(RowValues.data()), RowValues.size());
1661template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1664 vector_type_LO ColProfiles,
1665 vector_type_LO NewColProfiles,
1666 vector_type_LO ColHasRowWithSingleton) {
1667 const char tfecfFuncName[] =
"CreatePostSolveArrays: ";
1669 if (localNumSingletonCols_ == 0)
return;
1672 Kokkos::resize(ColSingletonRowLIDs_, localNumSingletonCols_);
1673 Kokkos::resize(ColSingletonColLIDs_, localNumSingletonCols_);
1674 Kokkos::resize(ColSingletonPivotLIDs_, localNumSingletonCols_);
1675 Kokkos::resize(ColSingletonPivots_, localNumSingletonCols_);
1677 int NumMyColSingletonstmp = 0;
1680 bool canRunOnHost = std::is_same_v<typename device_type::memory_space, Kokkos::HostSpace>;
1681 if (run_on_host_ && canRunOnHost) {
1685 auto localRowIDofSingletonColData = localRowIDofSingletonCol.getLocalViewHost(Tpetra::Access::ReadOnly);
1686 auto ColProfilesData = ColProfiles.getLocalViewHost(Tpetra::Access::ReadOnly);
1687 auto RowMapColors_Data = RowMapColors_->getLocalViewHost(Tpetra::Access::ReadOnly);
1688 auto NewColProfilesData = NewColProfiles.getLocalViewHost(Tpetra::Access::ReadOnly);
1689 auto ColHasRowWithSingletonData = ColHasRowWithSingleton.getLocalViewHost(Tpetra::Access::ReadOnly);
1690 auto ColMapColors_Data = ColMapColors_->getLocalViewHost(Tpetra::Access::ReadWrite);
1692 for (
int j = 0; j < localNumCols; j++) {
1693 int i = localRowIDofSingletonColData(j, 0);
1694 if (ColProfilesData(j, 0) == 1 && RowMapColors_Data(i, 0) != 1) {
1695 ColSingletonRowLIDs_[NumMyColSingletonstmp] = i;
1696 ColSingletonColLIDs_[NumMyColSingletonstmp] = j;
1697 NumMyColSingletonstmp++;
1701 else if (NewColProfilesData(j, 0) == 0 && ColHasRowWithSingletonData(j, 0) != 1 && RowMapColors_Data(i, 0) == 0) {
1702 ColMapColors_Data(j, 0) = 1;
1711 auto localRowIDofSingletonColData = localRowIDofSingletonCol.getLocalViewDevice(Tpetra::Access::ReadOnly);
1712 auto ColProfilesData = ColProfiles.getLocalViewDevice(Tpetra::Access::ReadOnly);
1713 auto RowMapColors_Data = RowMapColors_->getLocalViewDevice(Tpetra::Access::ReadOnly);
1714 auto NewColProfilesData = NewColProfiles.getLocalViewDevice(Tpetra::Access::ReadOnly);
1715 auto ColHasRowWithSingletonData = ColHasRowWithSingleton.getLocalViewDevice(Tpetra::Access::ReadOnly);
1716 auto ColMapColors_Data = ColMapColors_->getLocalViewDevice(Tpetra::Access::ReadWrite);
1719 Kokkos::View<int*, execution_space> numSingletonCols(
"numSingletonCols", 1);
1720 Kokkos::deep_copy(numSingletonCols, 0);
1723 CreatePostSolveArraysFunctor functor(localRowIDofSingletonColData,
1724 ColSingletonRowLIDs_, ColSingletonColLIDs_,
1725 NewColProfilesData, ColProfilesData, ColHasRowWithSingletonData,
1726 ColMapColors_Data, RowMapColors_Data, numSingletonCols);
1727 Kokkos::parallel_for(
1728 "CrsSingletonFilter_LinearProblem:CreatePostSolveArrays", range_policy(0, localNumCols),
1732 auto h_numSingletonCols = Kokkos::create_mirror_view(numSingletonCols);
1733 Kokkos::deep_copy(h_numSingletonCols, numSingletonCols);
1734 NumMyColSingletonstmp = h_numSingletonCols(0);
1738 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(NumMyColSingletonstmp != localNumSingletonCols_,
1739 std::runtime_error,
"Sanity Check " + std::to_string(NumMyColSingletonstmp) +
" vs " + std::to_string(localNumSingletonCols_) +
" (CreatePostSolveArrays).");
1741 Kokkos::Experimental::sort_by_key(
execution_space(), ColSingletonRowLIDs_, ColSingletonColLIDs_);
1754#define TPETRA_CRSSINGLETONFILTER_INSTANT(SCALAR, LO, GO, NODE) \
1755 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 KokkosKernels::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.