10 #ifndef IFPACK2_BLOCKTRIDICONTAINER_DEF_HPP
11 #define IFPACK2_BLOCKTRIDICONTAINER_DEF_HPP
15 #include <Tpetra_Distributor.hpp>
16 #include <Tpetra_BlockMultiVector.hpp>
17 #include <Tpetra_BlockCrsMatrix_Helpers.hpp>
19 #include <Kokkos_ArithTraits.hpp>
20 #include <KokkosBatched_Util.hpp>
21 #include <KokkosBatched_Vector.hpp>
22 #include <KokkosBatched_AddRadial_Decl.hpp>
23 #include <KokkosBatched_AddRadial_Impl.hpp>
24 #include <KokkosBatched_Gemm_Decl.hpp>
25 #include <KokkosBatched_Gemm_Serial_Impl.hpp>
26 #include <KokkosBatched_Gemv_Decl.hpp>
27 #include <KokkosBatched_Trsm_Decl.hpp>
28 #include <KokkosBatched_Trsm_Serial_Impl.hpp>
29 #include <KokkosBatched_Trsv_Decl.hpp>
30 #include <KokkosBatched_Trsv_Serial_Impl.hpp>
31 #include <KokkosBatched_LU_Decl.hpp>
32 #include <KokkosBatched_LU_Serial_Impl.hpp>
35 #include "Ifpack2_BlockTriDiContainer_impl.hpp"
46 template <
typename MatrixType>
48 BlockTriDiContainer<MatrixType, BlockTriDiContainerDetails::ImplSimdTag>
51 const bool overlapCommAndComp,
52 const bool useSeqMethod,
54 const bool explicitConversion)
56 IFPACK2_BLOCKHELPER_TIMER_WITH_FENCE(
"BlockTriDiContainer::initInternal", initInternal,
typename BlockHelperDetails::ImplType<MatrixType>::execution_space);
60 IFPACK2_BLOCKHELPER_TIMER(
"BlockTriDiContainer::createImpl", createImpl);
61 impl_ =
Teuchos::rcp(
new BlockTriDiContainerDetails::ImplObject<MatrixType>());
62 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
65 using impl_type = BlockHelperDetails::ImplType<MatrixType>;
69 IFPACK2_BLOCKHELPER_TIMER(
"BlockTriDiContainer::setA", setA);
70 if (explicitConversion) {
71 impl_->A = Teuchos::rcp_dynamic_cast<
const block_crs_matrix_type>(matrix);
72 if (impl_->A.is_null()) {
74 (block_size == -1,
"A pointwise matrix and block_size = -1 were given as inputs.");
76 IFPACK2_BLOCKHELPER_TIMER(
"BlockTriDiContainer::setA::convertToBlockCrsMatrix", convertToBlockCrsMatrix);
77 impl_->A = Tpetra::convertToBlockCrsMatrix(*Teuchos::rcp_dynamic_cast<const crs_matrix_type>(matrix), block_size,
true);
78 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
85 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
88 impl_->tpetra_importer = Teuchos::null;
89 impl_->async_importer = Teuchos::null;
93 IFPACK2_BLOCKHELPER_TIMER(
"BlockTriDiContainer::createBlockCrsTpetraImporter useSeqMethod", useSeqMethod);
95 impl_->tpetra_importer = BlockTriDiContainerDetails::createBlockCrsTpetraImporter<MatrixType>(impl_->A);
97 impl_->tpetra_importer = importer;
98 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
102 IFPACK2_BLOCKHELPER_TIMER(
"BlockTriDiContainer::createBlockCrsTpetraImporter", createBlockCrsTpetraImporter);
105 impl_->async_importer = BlockTriDiContainerDetails::createBlockCrsAsyncImporter<MatrixType>(impl_->A);
106 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
115 impl_->overlap_communication_and_computation = overlapCommAndComp;
118 IFPACK2_BLOCKHELPER_TIMER(
"BlockTriDiContainer::createZ", createZ);
119 impl_->Z =
typename impl_type::tpetra_multivector_type();
120 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
123 IFPACK2_BLOCKHELPER_TIMER(
"BlockTriDiContainer::createW", createW);
124 impl_->W =
typename impl_type::impl_scalar_type_1d_view();
125 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
128 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
131 template <
typename MatrixType>
133 BlockTriDiContainer<MatrixType, BlockTriDiContainerDetails::ImplSimdTag>
136 IFPACK2_BLOCKHELPER_TIMER(
"BlockTriDiContainer::clearInternal", clearInternal);
137 using impl_type = BlockHelperDetails::ImplType<MatrixType>;
138 using part_interface_type = BlockHelperDetails::PartInterface<MatrixType>;
139 using block_tridiags_type = BlockTriDiContainerDetails::BlockTridiags<MatrixType>;
140 using amd_type = BlockHelperDetails::AmD<MatrixType>;
141 using norm_manager_type = BlockHelperDetails::NormManager<MatrixType>;
143 impl_->A = Teuchos::null;
144 impl_->tpetra_importer = Teuchos::null;
145 impl_->async_importer = Teuchos::null;
147 impl_->Z =
typename impl_type::tpetra_multivector_type();
148 impl_->W =
typename impl_type::impl_scalar_type_1d_view();
150 impl_->part_interface = part_interface_type();
151 impl_->block_tridiags = block_tridiags_type();
152 impl_->a_minus_d = amd_type();
153 impl_->work =
typename impl_type::vector_type_1d_view();
154 impl_->norm_manager = norm_manager_type();
156 impl_ = Teuchos::null;
157 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
160 template <
typename MatrixType>
166 :
Container<MatrixType>(matrix, partitions, pointIndexed), partitions_(partitions)
168 IFPACK2_BLOCKHELPER_TIMER(
"BlockTriDiContainer::BlockTriDiContainer",
BlockTriDiContainer);
169 const bool useSeqMethod =
false;
170 const bool overlapCommAndComp =
false;
171 initInternal(matrix, importer, overlapCommAndComp, useSeqMethod);
172 n_subparts_per_part_ = -1;
174 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
177 template <
typename MatrixType>
181 const int n_subparts_per_part,
182 const bool overlapCommAndComp,
183 const bool useSeqMethod,
184 const int block_size,
185 const bool explicitConversion)
186 :
Container<MatrixType>(matrix, partitions, false), partitions_(partitions)
188 IFPACK2_BLOCKHELPER_TIMER(
"BlockTriDiContainer::BlockTriDiContainer",
BlockTriDiContainer);
189 initInternal(matrix, Teuchos::null, overlapCommAndComp, useSeqMethod, block_size, explicitConversion);
190 n_subparts_per_part_ = n_subparts_per_part;
191 block_size_ = block_size;
192 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
195 template <
typename MatrixType>
201 template <
typename MatrixType>
206 if (List.
isType<
int>(
"partitioner: subparts per part"))
207 n_subparts_per_part_ = List.
get<
int>(
"partitioner: subparts per part");
208 if (List.
isType<
int>(
"partitioner: block size"))
209 block_size_ = List.
get<
int>(
"partitioner: block size");
212 template <
typename MatrixType>
217 IFPACK2_BLOCKHELPER_TIMER(
"BlockTriDiContainer::initialize", initialize);
218 this->IsInitialized_ =
true;
220 auto bA = Teuchos::rcp_dynamic_cast<
const block_crs_matrix_type>(impl_->A);
223 (block_size_ == -1,
"A pointwise matrix and block_size = -1 were given as inputs.");
225 IFPACK2_BLOCKHELPER_TIMER(
"BlockTriDiContainer::initialize::getBlockCrsGraph", getBlockCrsGraph);
226 auto A = Teuchos::rcp_dynamic_cast<
const crs_matrix_type>(impl_->A);
227 impl_->blockGraph = Tpetra::getBlockCrsGraph(*A, block_size_,
true);
228 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
232 impl_->blockGraph = Teuchos::rcpFromRef(bA->getCrsGraph());
237 IFPACK2_BLOCKHELPER_TIMER(
"BlockTriDiContainer::createPartInterfaceBlockTridiagsNormManager", createPartInterfaceBlockTridiagsNormManager);
238 impl_->part_interface = BlockTriDiContainerDetails::createPartInterface<MatrixType>(impl_->A, impl_->blockGraph, partitions_, n_subparts_per_part_);
239 impl_->block_tridiags = BlockTriDiContainerDetails::createBlockTridiags<MatrixType>(impl_->part_interface);
241 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
246 this->IsComputed_ =
false;
249 BlockTriDiContainerDetails::performSymbolicPhase<MatrixType>
252 impl_->part_interface,
253 impl_->block_tridiags,
255 impl_->overlap_communication_and_computation);
257 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
260 template <
typename MatrixType>
265 IFPACK2_BLOCKHELPER_TIMER(
"BlockTriDiContainer::compute", compute);
266 this->IsComputed_ =
false;
267 if (!this->isInitialized())
270 BlockTriDiContainerDetails::performNumericPhase<MatrixType>
273 impl_->part_interface, impl_->block_tridiags,
274 Kokkos::ArithTraits<magnitude_type>::zero());
276 this->IsComputed_ =
true;
277 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
280 template <
typename MatrixType>
285 IFPACK2_BLOCKHELPER_TIMER(
"BlockTriDiContainer::clearBlocks", clearBlocks);
287 this->IsInitialized_ =
false;
288 this->IsComputed_ =
false;
290 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
293 template <
typename MatrixType>
295 BlockTriDiContainer<MatrixType, BlockTriDiContainerDetails::ImplSimdTag>
296 ::applyInverseJacobi (
const mv_type& X, mv_type& Y, scalar_type dampingFactor,
297 bool zeroStartingSolution,
int numSweeps)
const
299 IFPACK2_BLOCKHELPER_TIMER(
"BlockTriDiContainer::applyInverseJacobi", applyInverseJacobi);
300 const magnitude_type tol = Kokkos::ArithTraits<magnitude_type>::zero();
301 const int check_tol_every = 1;
303 BlockTriDiContainerDetails::applyInverseJacobi<MatrixType>
306 impl_->tpetra_importer,
307 impl_->async_importer,
308 impl_->overlap_communication_and_computation,
309 X, Y, impl_->Z, impl_->W,
310 impl_->part_interface, impl_->block_tridiags, impl_->a_minus_d,
314 zeroStartingSolution,
318 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
321 template <
typename MatrixType>
322 typename BlockTriDiContainer<MatrixType, BlockTriDiContainerDetails::ImplSimdTag>::ComputeParameters
326 return ComputeParameters();
329 template <
typename MatrixType>
334 IFPACK2_BLOCKHELPER_TIMER(
"BlockTriDiContainer::compute", compute);
335 this->IsComputed_ =
false;
336 if (!this->isInitialized())
339 BlockTriDiContainerDetails::performNumericPhase<MatrixType>
342 impl_->part_interface, impl_->block_tridiags,
343 in.addRadiallyToDiagonal);
345 this->IsComputed_ =
true;
346 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
349 template <
typename MatrixType>
359 template <
typename MatrixType>
363 const ApplyParameters& in)
const
365 IFPACK2_BLOCKHELPER_TIMER(
"BlockTriDiContainer::applyInverseJacobi", applyInverseJacobi);
368 r_val = BlockTriDiContainerDetails::applyInverseJacobi<MatrixType>
371 impl_->tpetra_importer,
372 impl_->async_importer,
373 impl_->overlap_communication_and_computation,
374 X, Y, impl_->Z, impl_->W,
375 impl_->part_interface, impl_->block_tridiags, impl_->a_minus_d,
379 in.zeroStartingSolution,
382 in.checkToleranceEvery);
384 IFPACK2_BLOCKHELPER_TIMER_FENCE(
typename BlockHelperDetails::ImplType<MatrixType>::execution_space)
388 template <
typename MatrixType>
392 return impl_->norm_manager.getNorms0();
395 template <
typename MatrixType>
399 return impl_->norm_manager.getNormsFinal();
402 template <
typename MatrixType>
406 scalar_type , scalar_type )
const
409 <<
"because you want to use this container's performance-portable Jacobi iteration. In "
410 <<
"that case, set \"relaxation: type\" to \"MT Split Jacobi\" rather than \"Jacobi\".");
413 template <
typename MatrixType>
422 template <
typename MatrixType>
433 template <
typename MatrixType>
438 std::ostringstream oss;
440 if (this->isInitialized()) {
441 if (this->isComputed()) {
442 oss <<
"{status = initialized, computed";
445 oss <<
"{status = initialized, not computed";
449 oss <<
"{status = not initialized, not computed";
456 template <
typename MatrixType>
464 os <<
"================================================================================" << endl
465 <<
"Ifpack2::BlockTriDiContainer" << endl
466 <<
"Number of blocks = " << this->numBlocks_ << endl
467 <<
"isInitialized() = " << this->IsInitialized_ << endl
468 <<
"isComputed() = " << this->IsComputed_ << endl
469 <<
"================================================================================" << endl
473 template <
typename MatrixType>
476 ::getName() {
return "Ifpack2::BlockTriDiContainer::ImplSimdTag"; }
478 #define IFPACK2_BLOCKTRIDICONTAINER_INSTANT(S,LO,GO,N) \
479 template class Ifpack2::BlockTriDiContainer< Tpetra::RowMatrix<S, LO, GO, N> >;
Ifpack2::BlockTriDiContainer class declaration.
T & get(const std::string &name, T def_value)
Store and solve local block tridiagonal linear problems.
Definition: Ifpack2_BlockTriDiContainer_decl.hpp:101
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
#define TEUCHOS_TEST_FOR_EXCEPT_MSG(throw_exception_test, msg)
Definition: Ifpack2_BlockHelper.hpp:350
BlockTriDiContainer(const Teuchos::RCP< const row_matrix_type > &matrix, const Teuchos::Array< Teuchos::Array< local_ordinal_type > > &partitions, const Teuchos::RCP< const import_type > &importer, bool pointIndexed)
Constructor.
Definition: Ifpack2_BlockTriDiContainer_def.hpp:162
virtual std::string description() const
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
Interface for creating and solving a set of local linear problems.
Definition: Ifpack2_Container_decl.hpp:79
bool isType(const std::string &name) const
ComputeParameters createDefaultComputeParameters() const
Create a ComputeParameters struct with default values.
Definition: Ifpack2_BlockTriDiContainer_def.hpp:324
#define TEUCHOS_ASSERT(assertion_test)