279 typedef MatrixType matrix_type;
280 typedef typename MatrixType::scalar_type scalar_type;
281 typedef typename MatrixType::local_ordinal_type local_ordinal_type;
282 typedef typename MatrixType::global_ordinal_type global_ordinal_type;
283 typedef typename MatrixType::node_type node_type;
289 typedef typename KokkosKernels::ArithTraits<impl_scalar_type>::mag_type magnitude_type;
291 typedef typename BlockTridiagScalarType<impl_scalar_type>::type btdm_scalar_type;
292 typedef typename KokkosKernels::ArithTraits<btdm_scalar_type>::mag_type btdm_magnitude_type;
303 typedef typename node_device_type::execution_space node_execution_space;
304 typedef typename node_device_type::memory_space node_memory_space;
306#if defined(KOKKOS_ENABLE_CUDA) && defined(IFPACK2_BLOCKHELPER_USE_CUDA_SPACE)
308 typedef node_execution_space execution_space;
309 typedef typename std::conditional<std::is_same<node_memory_space, Kokkos::CudaUVMSpace>::value,
311 node_memory_space>::type memory_space;
312 typedef Kokkos::Device<execution_space, memory_space> device_type;
315 typedef node_execution_space execution_space;
316 typedef node_memory_space memory_space;
319 typedef Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> tpetra_multivector_type;
320 typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> tpetra_map_type;
321 typedef Tpetra::Import<local_ordinal_type, global_ordinal_type, node_type> tpetra_import_type;
322 typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> tpetra_row_matrix_type;
323 typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> tpetra_crs_matrix_type;
324 typedef Tpetra::CrsGraph<local_ordinal_type, global_ordinal_type, node_type> tpetra_crs_graph_type;
325 typedef Tpetra::BlockCrsMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> tpetra_block_crs_matrix_type;
326 typedef typename tpetra_block_crs_matrix_type::little_block_type tpetra_block_access_view_type;
327 typedef Tpetra::BlockMultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> tpetra_block_multivector_type;
328 typedef typename tpetra_block_crs_matrix_type::crs_graph_type::local_graph_device_type local_crs_graph_type;
333 template <
typename T,
int l>
335 template <
typename T>
336 using SIMD = KB::SIMD<T>;
337 template <
typename T,
typename M>
338 using DefaultVectorLength = KB::DefaultVectorLength<T, M>;
339 template <
typename T,
typename M>
340 using DefaultInternalVectorLength = KB::DefaultInternalVectorLength<T, M>;
342 static constexpr int vector_length = DefaultVectorLength<btdm_scalar_type, memory_space>::value;
343 static constexpr int internal_vector_length = DefaultInternalVectorLength<btdm_scalar_type, memory_space>::value;
344 static constexpr int half_vector_length = (vector_length > 1) ? (vector_length / 2) : 1;
352 typedef Kokkos::View<size_type **, device_type> size_type_2d_view;
353 typedef Kokkos::View<int64_t ***, Kokkos::LayoutRight, device_type> i64_3d_view;
354 typedef Kokkos::View<local_ordinal_type *, device_type> local_ordinal_type_1d_view;
355 typedef Kokkos::View<local_ordinal_type **, device_type> local_ordinal_type_2d_view;
357 typedef Kokkos::View<impl_scalar_type *, device_type> impl_scalar_type_1d_view;
358 typedef Kokkos::View<impl_scalar_type *, node_device_type> impl_scalar_type_1d_view_tpetra;
361 typedef Kokkos::View<impl_scalar_type **, Kokkos::LayoutLeft, device_type> impl_scalar_type_2d_view;
362 typedef Kokkos::View<impl_scalar_type **, Kokkos::LayoutLeft, node_device_type> impl_scalar_type_2d_view_tpetra;
363 typedef Kokkos::View<const impl_scalar_type **, Kokkos::LayoutLeft, node_device_type> const_impl_scalar_type_2d_view_tpetra;
366 typedef Kokkos::View<vector_type *, device_type> vector_type_1d_view;
367 typedef Kokkos::View<vector_type ***, Kokkos::LayoutRight, device_type> vector_type_3d_view;
368 typedef Kokkos::View<vector_type ****, Kokkos::LayoutRight, device_type> vector_type_4d_view;
369 typedef Kokkos::View<internal_vector_type ***, Kokkos::LayoutRight, device_type> internal_vector_type_3d_view;
370 typedef Kokkos::View<internal_vector_type ****, Kokkos::LayoutRight, device_type> internal_vector_type_4d_view;
371 typedef Kokkos::View<internal_vector_type *****, Kokkos::LayoutRight, device_type> internal_vector_type_5d_view;
372 typedef Kokkos::View<btdm_scalar_type **, Kokkos::LayoutRight, device_type> btdm_scalar_type_2d_view;
373 typedef Kokkos::View<btdm_scalar_type ***, Kokkos::LayoutRight, device_type> btdm_scalar_type_3d_view;
374 typedef Kokkos::View<btdm_scalar_type ****, Kokkos::LayoutRight, device_type> btdm_scalar_type_4d_view;
375 typedef Kokkos::View<btdm_scalar_type *****, Kokkos::LayoutRight, device_type> btdm_scalar_type_5d_view;
484 using magnitude_type =
typename impl_type::magnitude_type;
488 int sweep_step_, sweep_step_upper_bound_;
489#ifdef HAVE_IFPACK2_MPI
490 MPI_Request mpi_request_;
493 magnitude_type work_[3];
498 NormManager(
const Teuchos::RCP<
const Teuchos::Comm<int> > &comm) {
500 sweep_step_upper_bound_ = 1;
501 collective_ = comm->getSize() > 1;
503#ifdef HAVE_IFPACK2_MPI
504 const auto mpi_comm = Teuchos::rcp_dynamic_cast<const Teuchos::MpiComm<int> >(comm);
505 TEUCHOS_ASSERT(!mpi_comm.is_null());
506 comm_ = *mpi_comm->getRawMpiComm();
509 const magnitude_type zero(0), minus_one(-1);
512 work_[2] = minus_one;
516 void setCheckFrequency(
const int sweep_step) {
517 TEUCHOS_TEST_FOR_EXCEPT_MSG(sweep_step < 1, "sweep step must be >= 1
");
518 sweep_step_upper_bound_ = sweep_step;
522 // Get the buffer into which to store rank-local squared norms.
523 magnitude_type *getBuffer() { return &work_[0]; }
525 // Call MPI_Iallreduce to find the global squared norms.
526 void ireduce(const int sweep, const bool force = false) {
527 if (!force && sweep % sweep_step_) return;
529 IFPACK2_BLOCKHELPER_TIMER("BlockTriDi::NormManager::Ireduce
", Ireduce);
532#ifdef HAVE_IFPACK2_MPI
533 auto send_data = &work_[1];
534 auto recv_data = &work_[0];
536#if defined(IFPACK2_BLOCKTRIDICONTAINER_USE_MPI_3)
537 MPI_Iallreduce(send_data, recv_data, 1,
538 Teuchos::Details::MpiTypeTraits<magnitude_type>::getType(),
539 MPI_SUM, comm_, &mpi_request_);
541 MPI_Allreduce(send_data, recv_data, 1,
542 Teuchos::Details::MpiTypeTraits<magnitude_type>::getType(),
549 // Check if the norm-based termination criterion is met. tol2 is the
550 // tolerance squared. Sweep is the sweep index. If not every iteration is
551 // being checked, this function immediately returns false. If a check must
552 // be done at this iteration, it waits for the reduction triggered by
553 // ireduce to complete, then checks the global norm against the tolerance.
554 bool checkDone(const int sweep, const magnitude_type tol2, const bool force = false) {
556 if (sweep <= 0) return false;
558 IFPACK2_BLOCKHELPER_TIMER("BlockTriDi::NormManager::CheckDone
", CheckDone);
560 TEUCHOS_ASSERT(sweep >= 1);
561 if (!force && (sweep - 1) % sweep_step_) return false;
563#ifdef HAVE_IFPACK2_MPI
564#if defined(IFPACK2_BLOCKTRIDICONTAINER_USE_MPI_3)
565 MPI_Wait(&mpi_request_, MPI_STATUS_IGNORE);
575 r_val = (work_[0] < tol2 * work_[2]);
579 const auto adjusted_sweep_step = 2 * sweep_step_;
580 if (adjusted_sweep_step < sweep_step_upper_bound_) {
581 sweep_step_ = adjusted_sweep_step;
583 sweep_step_ = sweep_step_upper_bound_;
588 // After termination has occurred, finalize the norms for use in
589 // get_norms{0,final}.
591 work_[0] = std::sqrt(work_[0]); // after converged
593 work_[2] = std::sqrt(work_[2]); // first norm
594 // if work_[2] is minus one, then norm is not requested.
597 // Report norms to the caller.
598 const magnitude_type getNorms0() const { return work_[2]; }
599 const magnitude_type getNormsFinal() const { return work_[0]; }