From: Jan Philipp Thiele Date: Mon, 8 Jul 2024 08:58:02 +0000 (+0200) Subject: Rework and restructure type definitions of TpetraWrappers classes X-Git-Tag: v9.6.0-rc1~106^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a7485378ab6717ac5e7ab7eb5d32a295b71b393;p=dealii.git Rework and restructure type definitions of TpetraWrappers classes --- diff --git a/include/deal.II/lac/trilinos_tpetra_block_sparse_matrix.templates.h b/include/deal.II/lac/trilinos_tpetra_block_sparse_matrix.templates.h index e4b67e4c3d..e80102f439 100644 --- a/include/deal.II/lac/trilinos_tpetra_block_sparse_matrix.templates.h +++ b/include/deal.II/lac/trilinos_tpetra_block_sparse_matrix.templates.h @@ -99,7 +99,7 @@ namespace LinearAlgebra const bool exchange_data) { # ifdef DEBUG - std::vector tpetra_maps; + std::vector> tpetra_maps; for (size_type i = 0; i < block_sparsity_pattern.n_block_rows(); ++i) tpetra_maps.push_back( parallel_partitioning[i].make_tpetra_map(communicator, false)); diff --git a/include/deal.II/lac/trilinos_tpetra_communication_pattern.h b/include/deal.II/lac/trilinos_tpetra_communication_pattern.h index e12c9bbc32..ed276e12d9 100644 --- a/include/deal.II/lac/trilinos_tpetra_communication_pattern.h +++ b/include/deal.II/lac/trilinos_tpetra_communication_pattern.h @@ -18,6 +18,10 @@ #include +#include "deal.II/base/memory_space.h" + +#include + #ifdef DEAL_II_TRILINOS_WITH_TPETRA # include @@ -39,6 +43,7 @@ namespace LinearAlgebra class CommunicationPattern : public Utilities::MPI::CommunicationPatternBase { public: + using MemorySpace = dealii::MemorySpace::Host; /** * Initialize the communication pattern. * @@ -83,25 +88,25 @@ namespace LinearAlgebra /** * Return the underlying Tpetra::Import object. */ - const Tpetra::Import & + const TpetraTypes::ImportType & get_tpetra_import() const; /** * Return a Teuchos::RCP to the underlying Tpetra::Import object. */ - Teuchos::RCP> + Teuchos::RCP> get_tpetra_import_rcp() const; /** * Return the underlying Tpetra::Export object. */ - const Tpetra::Export & + const TpetraTypes::ExportType & get_tpetra_export() const; /** * Return a Teuchos::RCP to the underlying Tpetra::Export object. */ - Teuchos::RCP> + Teuchos::RCP> get_tpetra_export_rcp() const; private: @@ -113,14 +118,12 @@ namespace LinearAlgebra /** * Teuchos::RCP to the Tpetra::Import object used. */ - Teuchos::RCP> - tpetra_import; + Teuchos::RCP> tpetra_import; /** * Teuchos::RCP to the Tpetra::Export object used. */ - Teuchos::RCP> - tpetra_export; + Teuchos::RCP> tpetra_export; }; } // end of namespace TpetraWrappers } // end of namespace LinearAlgebra diff --git a/include/deal.II/lac/trilinos_tpetra_solver_direct.h b/include/deal.II/lac/trilinos_tpetra_solver_direct.h index 68a6523d9b..0b96bb7f9b 100644 --- a/include/deal.II/lac/trilinos_tpetra_solver_direct.h +++ b/include/deal.II/lac/trilinos_tpetra_solver_direct.h @@ -19,6 +19,8 @@ #include "deal.II/grid/grid_generator.h" +#include "deal.II/lac/trilinos_tpetra_types.h" + #include #ifdef DEAL_II_TRILINOS_WITH_TPETRA @@ -70,34 +72,6 @@ namespace LinearAlgebra class SolverDirectBase { public: - /** - * Declare the type for container size. - */ - using size_type = dealii::types::signed_global_dof_index; - - /** - * Typedef for the NodeType - */ -# if DEAL_II_TRILINOS_VERSION_GTE(14, 2, 0) - using NodeType = Tpetra::KokkosCompat::KokkosDeviceWrapperNode< - typename MemorySpace::kokkos_space::execution_space, - typename MemorySpace::kokkos_space>; -# else - using NodeType = Kokkos::Compat::KokkosDeviceWrapperNode< - typename MemorySpace::kokkos_space::execution_space, - typename MemorySpace::kokkos_space>; -# endif - - /** - * Typedef for the LinearOperator type - */ - using LinearOperator = Tpetra::Operator; - - /** - * Typedef for the MultiVector type - */ - using MultiVector = Tpetra::MultiVector; - /** * Destructor. */ @@ -172,8 +146,8 @@ namespace LinearAlgebra * A structure that contains the Trilinos solver object. */ Teuchos::RCP< - Amesos2::Solver::MatrixType, - MultiVector>> + Amesos2::Solver, + TpetraTypes::MultiVectorType>> solver; /* diff --git a/include/deal.II/lac/trilinos_tpetra_solver_direct.templates.h b/include/deal.II/lac/trilinos_tpetra_solver_direct.templates.h index c73e78fdfd..ddca9270ae 100644 --- a/include/deal.II/lac/trilinos_tpetra_solver_direct.templates.h +++ b/include/deal.II/lac/trilinos_tpetra_solver_direct.templates.h @@ -18,6 +18,7 @@ #include #include "deal.II/lac/solver_control.h" +#include "deal.II/lac/trilinos_tpetra_types.h" #include @@ -68,8 +69,9 @@ namespace LinearAlgebra { // Allocate the Amesos2 solver with the concrete solver, if possible. solver = - Amesos2::create::MatrixType, - MultiVector>(solver_type, A.trilinos_rcp()); + Amesos2::create, + TpetraTypes::MultiVectorType>( + solver_type, A.trilinos_rcp()); solver->setParameters(Teuchos::rcpFromRef(parameter_list)); // Now do the actual factorization, which is a two step procedure. @@ -140,11 +142,9 @@ namespace LinearAlgebra const Vector &b) { solver = - Amesos2::create::MatrixType, - MultiVector>(solver_type, - A.trilinos_rcp(), - x.trilinos_rcp(), - b.trilinos_rcp()); + Amesos2::create, + TpetraTypes::MultiVectorType>( + solver_type, A.trilinos_rcp(), x.trilinos_rcp(), b.trilinos_rcp()); do_solve(); } diff --git a/include/deal.II/lac/trilinos_tpetra_sparse_matrix.h b/include/deal.II/lac/trilinos_tpetra_sparse_matrix.h index 73a483cbbb..01e9567cf5 100644 --- a/include/deal.II/lac/trilinos_tpetra_sparse_matrix.h +++ b/include/deal.II/lac/trilinos_tpetra_sparse_matrix.h @@ -159,46 +159,6 @@ namespace LinearAlgebra */ using value_type = Number; - /** - * Typedef for the NodeType - */ -# if DEAL_II_TRILINOS_VERSION_GTE(14, 2, 0) - using NodeType = Tpetra::KokkosCompat::KokkosDeviceWrapperNode< - typename MemorySpace::kokkos_space::execution_space, - typename MemorySpace::kokkos_space>; -# else - using NodeType = Kokkos::Compat::KokkosDeviceWrapperNode< - typename MemorySpace::kokkos_space::execution_space, - typename MemorySpace::kokkos_space>; -# endif - - /** - * Typedef for Tpetra::CrsMatrix - */ - using MatrixType = - Tpetra::CrsMatrix; - - /** - * Typedef for Tpetra::Map - */ - using MapType = - Tpetra::Map; - - /** - * Typedef for Tpetra::CrsGraph - */ - using GraphType = - Tpetra::CrsGraph; - - /** - * Typedef for Tpetra::Vector - */ - using VectorType = Tpetra:: - Vector; - /** * @name Constructors and initialization. */ @@ -1033,7 +993,7 @@ namespace LinearAlgebra * href="https://docs.trilinos.org/dev/packages/tpetra/doc/html/classTpetra_1_1CrsMatrix.html">Tpetra::CrsMatrix * class. */ - const MatrixType & + const TpetraTypes::MatrixType & trilinos_matrix() const; /** @@ -1042,7 +1002,7 @@ namespace LinearAlgebra * href="https://docs.trilinos.org/dev/packages/tpetra/doc/html/classTpetra_1_1CrsMatrix.html">Tpetra::CrsMatrix * class. */ - MatrixType & + TpetraTypes::MatrixType & trilinos_matrix(); /** @@ -1054,7 +1014,7 @@ namespace LinearAlgebra * href="https://docs.trilinos.org/dev/packages/tpetra/doc/html/classTpetra_1_1CrsMatrix.html">Tpetra::CrsMatrix * class. */ - Teuchos::RCP + Teuchos::RCP> trilinos_rcp() const; /** @@ -1066,7 +1026,7 @@ namespace LinearAlgebra * href="https://docs.trilinos.org/dev/packages/tpetra/doc/html/classTpetra_1_1CrsMatrix.html">Tpetra::CrsMatrix * class. */ - Teuchos::RCP + Teuchos::RCP> trilinos_rcp(); /** @} */ @@ -1273,14 +1233,14 @@ namespace LinearAlgebra * information from the column space map is used to speed up the * assembly process. */ - Teuchos::RCP column_space_map; + Teuchos::RCP> column_space_map; /** * A sparse matrix object in Trilinos to be used for finite element based * problems which allows for assembling into non-local elements. The * actual type, a sparse matrix, is set in the constructor. */ - Teuchos::RCP matrix; + Teuchos::RCP> matrix; /** * A boolean variable to hold information on whether the matrix is @@ -1955,11 +1915,7 @@ namespace LinearAlgebra template - inline const Tpetra::CrsMatrix< - Number, - int, - types::signed_global_dof_index, - typename SparseMatrix::NodeType> & + inline const TpetraTypes::MatrixType & SparseMatrix::trilinos_matrix() const { return *matrix; @@ -1968,11 +1924,7 @@ namespace LinearAlgebra template - inline Tpetra::CrsMatrix< - Number, - int, - types::signed_global_dof_index, - typename SparseMatrix::NodeType> & + inline TpetraTypes::MatrixType & SparseMatrix::trilinos_matrix() { return *matrix; @@ -1981,11 +1933,7 @@ namespace LinearAlgebra template - inline Teuchos::RCP::NodeType>> + inline Teuchos::RCP> SparseMatrix::trilinos_rcp() const { return matrix.getConst(); @@ -1994,11 +1942,7 @@ namespace LinearAlgebra template - inline Teuchos::RCP< - Tpetra::CrsMatrix::NodeType>> + inline Teuchos::RCP> SparseMatrix::trilinos_rcp() { return matrix; @@ -2102,10 +2046,10 @@ namespace LinearAlgebra } # if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0) - typename SparseMatrix::MatrixType:: + typename TpetraTypes::MatrixType:: nonconst_global_inds_host_view_type col_indices(colnum_cache->data(), colnums); - typename SparseMatrix::MatrixType:: + typename TpetraTypes::MatrixType:: nonconst_values_host_view_type values(value_cache->data(), colnums); # else Teuchos::ArrayView col_indices( diff --git a/include/deal.II/lac/trilinos_tpetra_sparse_matrix.templates.h b/include/deal.II/lac/trilinos_tpetra_sparse_matrix.templates.h index efdb94cf39..be980905b2 100644 --- a/include/deal.II/lac/trilinos_tpetra_sparse_matrix.templates.h +++ b/include/deal.II/lac/trilinos_tpetra_sparse_matrix.templates.h @@ -17,6 +17,10 @@ #include +#include "deal.II/base/types.h" + +#include "deal.II/lac/trilinos_tpetra_types.h" + #ifdef DEAL_II_TRILINOS_WITH_TPETRA # include @@ -97,11 +101,11 @@ namespace LinearAlgebra // get a Kokkos::DualView auto mirror_view_dst = Kokkos::create_mirror_view_and_copy( typename MemorySpace::kokkos_space{}, kokkos_view_dst); - typename SparseMatrix::VectorType::dual_view_type + typename TpetraTypes::VectorType::dual_view_type kokkos_dual_view_dst(mirror_view_dst, kokkos_view_dst); // create the Tpetra::Vector - typename SparseMatrix::VectorType tpetra_dst( + typename TpetraTypes::VectorType tpetra_dst( M.trilinos_matrix().getRangeMap(), kokkos_dual_view_dst); // For the src vector: @@ -112,11 +116,11 @@ namespace LinearAlgebra // get a Kokkos::DualView auto mirror_view_src = Kokkos::create_mirror_view_and_copy( typename MemorySpace::kokkos_space{}, kokkos_view_src); - typename SparseMatrix::VectorType::dual_view_type + typename TpetraTypes::VectorType::dual_view_type kokkos_dual_view_src(mirror_view_src, kokkos_view_src); // create the Tpetra::Vector - typename SparseMatrix::VectorType tpetra_src( + typename TpetraTypes::VectorType tpetra_src( M.trilinos_matrix().getDomainMap(), kokkos_dual_view_src); M.trilinos_matrix().apply(tpetra_src, tpetra_dst, mode, alpha, beta); @@ -144,38 +148,24 @@ namespace LinearAlgebra { using size_type = dealii::types::signed_global_dof_index; - template - using MapType = - Tpetra::Map; - - template - using MatrixType = - Tpetra::CrsMatrix; - - template - using GraphType = - Tpetra::CrsGraph; - template void - reinit_matrix(const IndexSet &row_parallel_partitioning, - const IndexSet &column_parallel_partitioning, - const SparsityPatternType &sparsity_pattern, - const bool exchange_data, - const MPI_Comm communicator, - Teuchos::RCP> &column_space_map, - Teuchos::RCP> &matrix) + reinit_matrix( + const IndexSet &row_parallel_partitioning, + const IndexSet &column_parallel_partitioning, + const SparsityPatternType &sparsity_pattern, + const bool exchange_data, + const MPI_Comm communicator, + Teuchos::RCP> &column_space_map, + Teuchos::RCP> &matrix) { // release memory before reallocation matrix.reset(); // Get the Tpetra::Maps - Teuchos::RCP> row_space_map = + Teuchos::RCP> row_space_map = row_parallel_partitioning.make_tpetra_map_rcp(communicator, false); column_space_map = @@ -202,7 +192,7 @@ namespace LinearAlgebra communicator, exchange_data); matrix = Utilities::Trilinos::internal::make_rcp< - MatrixType>( + TpetraTypes::MatrixType>( trilinos_sparsity.trilinos_sparsity_pattern()); return; @@ -224,12 +214,14 @@ namespace LinearAlgebra // internal reordering is done on ints only, and we can leave the // doubles aside. # if DEAL_II_TRILINOS_VERSION_GTE(12, 16, 0) - Teuchos::RCP> graph = - Utilities::Trilinos::internal::make_rcp>( - row_space_map, n_entries_per_row); + Teuchos::RCP> graph = + Utilities::Trilinos::internal::make_rcp< + TpetraTypes::GraphType>(row_space_map, + n_entries_per_row); # else - Teuchos::RCP> graph = - Utilities::Trilinos::internal::make_rcp>( + Teuchos::RCP> graph = + Utilities::Trilinos::internal::make_rcp< + TpetraTypes::GraphType>( row_space_map, Teuchos::arcpFromArray(n_entries_per_row)); # endif @@ -266,28 +258,28 @@ namespace LinearAlgebra AssertDimension(sparsity_pattern.n_cols(), graph->getGlobalNumCols()); // And now finally generate the matrix. - matrix = - Utilities::Trilinos::internal::make_rcp>( - graph); + matrix = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MatrixType>(graph); } - template + template void - reinit_matrix(const IndexSet &row_parallel_partitioning, - const IndexSet &column_parallel_partitioning, - const DynamicSparsityPattern &sparsity_pattern, - const bool exchange_data, - const MPI_Comm communicator, - Teuchos::RCP> &column_space_map, - Teuchos::RCP> &matrix) + reinit_matrix( + const IndexSet &row_parallel_partitioning, + const IndexSet &column_parallel_partitioning, + const DynamicSparsityPattern &sparsity_pattern, + const bool exchange_data, + const MPI_Comm communicator, + Teuchos::RCP> &column_space_map, + Teuchos::RCP> &matrix) { // release memory before reallocation matrix.reset(); // Get the Tpetra::Maps - Teuchos::RCP> row_space_map = + Teuchos::RCP> row_space_map = row_parallel_partitioning.make_tpetra_map_rcp(communicator, false); column_space_map = @@ -314,7 +306,7 @@ namespace LinearAlgebra communicator, exchange_data); matrix = Utilities::Trilinos::internal::make_rcp< - MatrixType>( + TpetraTypes::MatrixType>( trilinos_sparsity.trilinos_sparsity_pattern()); return; @@ -355,12 +347,14 @@ namespace LinearAlgebra // internal reordering is done on ints only, and we can leave the // doubles aside. # if DEAL_II_TRILINOS_VERSION_GTE(12, 16, 0) - Teuchos::RCP> graph = - Utilities::Trilinos::internal::make_rcp>( - row_space_map, n_entries_per_row); + Teuchos::RCP> graph = + Utilities::Trilinos::internal::make_rcp< + TpetraTypes::GraphType>(row_space_map, + n_entries_per_row); # else - Teuchos::RCP> graph = - Utilities::Trilinos::internal::make_rcp>( + Teuchos::RCP> graph = + Utilities::Trilinos::internal::make_rcp< + TpetraTypes::GraphType>( row_space_map, Teuchos::arcpFromArray(n_entries_per_row)); # endif @@ -396,9 +390,8 @@ namespace LinearAlgebra AssertDimension(sparsity_pattern.n_cols(), graph->getGlobalNumCols()); // And now finally generate the matrix. - matrix = - Utilities::Trilinos::internal::make_rcp>( - graph); + matrix = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MatrixType>(graph); } } // namespace SparseMatrixImpl @@ -413,20 +406,23 @@ namespace LinearAlgebra // thread on a configuration with MPI will still get a parallel interface. template SparseMatrix::SparseMatrix() - : column_space_map(Utilities::Trilinos::internal::make_rcp( + : column_space_map(Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MapType>( 0, 0, Utilities::Trilinos::tpetra_comm_self())) { // Prepare the graph - Teuchos::RCP graph = - Utilities::Trilinos::internal::make_rcp(column_space_map, - column_space_map, - 0); + Teuchos::RCP> graph = + Utilities::Trilinos::internal::make_rcp< + TpetraTypes::GraphType>(column_space_map, + column_space_map, + 0); graph->fillComplete(); // Create the matrix from the graph - matrix = Utilities::Trilinos::internal::make_rcp(graph); + matrix = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MatrixType>(graph); compressed = false; } @@ -436,11 +432,13 @@ namespace LinearAlgebra template SparseMatrix::SparseMatrix( const SparsityPattern &sparsity_pattern) - : matrix(Utilities::Trilinos::internal::make_rcp( + : matrix(Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MatrixType>( sparsity_pattern.trilinos_sparsity_pattern())) { column_space_map = - Teuchos::rcp_const_cast(sparsity_pattern.domain_partitioner()); + Teuchos::rcp_const_cast>( + sparsity_pattern.domain_partitioner()); compressed = false; compress(VectorOperation::add); } @@ -452,13 +450,16 @@ namespace LinearAlgebra const size_type m, const size_type n, const unsigned int n_max_entries_per_row) - : column_space_map(Utilities::Trilinos::internal::make_rcp( - n, + : column_space_map(Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MapType>( + static_cast(n), 0, Utilities::Trilinos::tpetra_comm_self())) - , matrix(Utilities::Trilinos::internal::make_rcp( - Utilities::Trilinos::internal::make_rcp( - m, + , matrix(Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MatrixType>( + Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MapType>( + static_cast(m), 0, Utilities::Trilinos::tpetra_comm_self()), column_space_map, @@ -473,7 +474,8 @@ namespace LinearAlgebra const size_type m, const size_type n, const std::vector &n_entries_per_row) - : column_space_map(Utilities::Trilinos::internal::make_rcp( + : column_space_map(Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MapType>( n, 0, Utilities::Trilinos::tpetra_comm_self())) @@ -481,8 +483,10 @@ namespace LinearAlgebra { std::vector entries_per_row_size_type(n_entries_per_row.begin(), n_entries_per_row.end()); - matrix = Utilities::Trilinos::internal::make_rcp( - Utilities::Trilinos::internal::make_rcp( + matrix = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MatrixType>( + Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MapType>( m, 0, Utilities::Trilinos::tpetra_comm_self()), column_space_map, # if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0) @@ -530,7 +534,7 @@ namespace LinearAlgebra SparseMatrix::reinit( const SparsityPatternType &sparsity_pattern) { - SparseMatrixImpl::reinit_matrix( + SparseMatrixImpl::reinit_matrix( complete_index_set(sparsity_pattern.n_rows()), complete_index_set(sparsity_pattern.n_cols()), sparsity_pattern, @@ -555,8 +559,10 @@ namespace LinearAlgebra // reinit with a (distributed) Trilinos sparsity pattern. column_space_map = - Teuchos::rcp_const_cast(sparsity_pattern.domain_partitioner()); - matrix = Utilities::Trilinos::internal::make_rcp( + Teuchos::rcp_const_cast>( + sparsity_pattern.domain_partitioner()); + matrix = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MatrixType>( sparsity_pattern.trilinos_sparsity_pattern()); compressed = false; @@ -574,7 +580,8 @@ namespace LinearAlgebra const unsigned int n_max_entries_per_row) : column_space_map( parallel_partitioning.make_tpetra_map_rcp(communicator, false)) - , matrix(Utilities::Trilinos::internal::make_rcp( + , matrix(Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MatrixType>( column_space_map, n_max_entries_per_row)) , compressed(false) @@ -594,10 +601,12 @@ namespace LinearAlgebra Teuchos::Array n_entries_per_row_array(n_entries_per_row.begin(), n_entries_per_row.end()); # if DEAL_II_TRILINOS_VERSION_GTE(12, 16, 0) - matrix = Utilities::Trilinos::internal::make_rcp( - column_space_map, n_entries_per_row_array); + matrix = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MatrixType>(column_space_map, + n_entries_per_row_array); # else - matrix = Utilities::Trilinos::internal::make_rcp( + matrix = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MatrixType>( column_space_map, Teuchos::arcpFromArray(n_entries_per_row_array)); # endif } @@ -612,7 +621,8 @@ namespace LinearAlgebra const size_type n_max_entries_per_row) : column_space_map( col_parallel_partitioning.make_tpetra_map_rcp(communicator, false)) - , matrix(Utilities::Trilinos::internal::make_rcp( + , matrix(Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MatrixType>( row_parallel_partitioning.make_tpetra_map_rcp(communicator, false), n_max_entries_per_row)) , compressed(false) @@ -633,11 +643,13 @@ namespace LinearAlgebra Teuchos::Array n_entries_per_row_array(n_entries_per_row.begin(), n_entries_per_row.end()); # if DEAL_II_TRILINOS_VERSION_GTE(12, 16, 0) - matrix = Utilities::Trilinos::internal::make_rcp( + matrix = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MatrixType>( row_parallel_partitioning.make_tpetra_map_rcp(communicator, false), n_entries_per_row_array); # else - matrix = Utilities::Trilinos::internal::make_rcp( + matrix = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MatrixType>( row_parallel_partitioning.make_tpetra_map_rcp(communicator, false), Teuchos::arcpFromArray(n_entries_per_row_array)); # endif @@ -675,7 +687,7 @@ namespace LinearAlgebra const MPI_Comm communicator, const bool exchange_data) { - SparseMatrixImpl::reinit_matrix( + SparseMatrixImpl::reinit_matrix( row_parallel_partitioning, col_parallel_partitioning, sparsity_pattern, @@ -1200,8 +1212,12 @@ namespace LinearAlgebra matrix->getDomainMap(), matrix->getRangeMap(), Teuchos::null); + // needs a local typedef or Assert thinks it gets more arguments than it + // does... + using MatrixType = TpetraTypes::MatrixType; Assert(dynamic_cast(result.get()), ExcInternalError()); - matrix.reset(dynamic_cast(result.release().get())); + matrix.reset(dynamic_cast *>( + result.release().get())); } @@ -1243,10 +1259,12 @@ namespace LinearAlgebra col_indices_vector.resize(nnz); values_vector.resize(nnz); # if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0) - typename MatrixType::nonconst_local_inds_host_view_type - col_indices(col_indices_vector.data(), nnz); - typename MatrixType::nonconst_values_host_view_type values( - values_vector.data(), nnz); + typename TpetraTypes::MatrixType:: + nonconst_local_inds_host_view_type col_indices( + col_indices_vector.data(), nnz); + typename TpetraTypes::MatrixType:: + nonconst_values_host_view_type values(values_vector.data(), + nnz); # else Teuchos::ArrayView col_indices(col_indices_vector); Teuchos::ArrayView values(values_vector); @@ -1293,15 +1311,17 @@ namespace LinearAlgebra // Perform a deep copy # if DEAL_II_TRILINOS_VERSION_GTE(12, 18, 1) - matrix = - Utilities::Trilinos::internal::make_rcp(*source.matrix, - Teuchos::Copy); + matrix = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MatrixType>(*source.matrix, + Teuchos::Copy); # else matrix = source.matrix->clone( Utilities::Trilinos::internal::make_rcp()); # endif - column_space_map = Teuchos::rcp_const_cast(matrix->getColMap()); - compressed = source.compressed; + column_space_map = + Teuchos::rcp_const_cast>( + matrix->getColMap()); + compressed = source.compressed; } @@ -1313,18 +1333,21 @@ namespace LinearAlgebra // When we clear the matrix, reset // the pointer and generate an // empty matrix. - column_space_map = Utilities::Trilinos::internal::make_rcp( + column_space_map = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MapType>( 0, 0, Utilities::Trilinos::tpetra_comm_self()); // Prepare the graph - Teuchos::RCP graph = - Utilities::Trilinos::internal::make_rcp(column_space_map, - column_space_map, - 0); + Teuchos::RCP> graph = + Utilities::Trilinos::internal::make_rcp< + TpetraTypes::GraphType>(column_space_map, + column_space_map, + 0); graph->fillComplete(); // Create the matrix from the graph - matrix = Utilities::Trilinos::internal::make_rcp(graph); + matrix = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MatrixType>(graph); compressed = true; } @@ -1402,8 +1425,11 @@ namespace LinearAlgebra else { # if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0) - typename MatrixType::values_host_view_type values; - typename MatrixType::local_inds_host_view_type indices; + typename TpetraTypes::MatrixType::values_host_view_type + values; + typename TpetraTypes::MatrixType:: + local_inds_host_view_type indices; # else Teuchos::ArrayView values; Teuchos::ArrayView indices; @@ -1482,10 +1508,11 @@ namespace LinearAlgebra // Prepare pointers for extraction of a view of the row. size_t nnz_present = matrix->getNumEntriesInLocalRow(trilinos_i); # if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0) - typename MatrixType::nonconst_local_inds_host_view_type col_indices( - "indices", nnz_present); - typename MatrixType::nonconst_values_host_view_type values( - "values", nnz_present); + typename TpetraTypes::MatrixType:: + nonconst_local_inds_host_view_type col_indices("indices", + nnz_present); + typename TpetraTypes::MatrixType:: + nonconst_values_host_view_type values("values", nnz_present); # else std::vector col_indices_vector(nnz_present); Teuchos::ArrayView col_indices(col_indices_vector); diff --git a/include/deal.II/lac/trilinos_tpetra_sparsity_pattern.h b/include/deal.II/lac/trilinos_tpetra_sparsity_pattern.h index 3bd929ca6a..ed209670a4 100644 --- a/include/deal.II/lac/trilinos_tpetra_sparsity_pattern.h +++ b/include/deal.II/lac/trilinos_tpetra_sparsity_pattern.h @@ -17,6 +17,10 @@ #include +#include "deal.II/base/types.h" + +#include "deal.II/lac/trilinos_tpetra_types.h" + #ifdef DEAL_II_TRILINOS_WITH_TPETRA # include @@ -83,20 +87,7 @@ namespace LinearAlgebra /** * Declare type for container size. */ - using size_type = dealii::types::signed_global_dof_index; - - /** - * Typedef for the NodeType - */ -# if DEAL_II_TRILINOS_VERSION_GTE(14, 2, 0) - using NodeType = Tpetra::KokkosCompat::KokkosDeviceWrapperNode< - typename MemorySpace::kokkos_space::execution_space, - typename MemorySpace::kokkos_space>; -# else - using NodeType = Kokkos::Compat::KokkosDeviceWrapperNode< - typename MemorySpace::kokkos_space::execution_space, - typename MemorySpace::kokkos_space>; -# endif + using size_type = dealii::types::global_dof_index; /** * Constructor. @@ -195,20 +186,7 @@ namespace LinearAlgebra /** * Declare type for container size. */ - using size_type = size_t; - - /** - * Typedef for the NodeType - */ -# if DEAL_II_TRILINOS_VERSION_GTE(14, 2, 0) - using NodeType = Tpetra::KokkosCompat::KokkosDeviceWrapperNode< - typename MemorySpace::kokkos_space::execution_space, - typename MemorySpace::kokkos_space>; -# else - using NodeType = Kokkos::Compat::KokkosDeviceWrapperNode< - typename MemorySpace::kokkos_space::execution_space, - typename MemorySpace::kokkos_space>; -# endif + using size_type = types::global_dof_index; /** * Constructor. Create an iterator into the matrix @p matrix for the @@ -313,39 +291,12 @@ namespace LinearAlgebra /** * Declare type for container size. */ - using size_type = dealii::types::signed_global_dof_index; - - /** - * Typedef for the NodeType - */ -# if DEAL_II_TRILINOS_VERSION_GTE(14, 2, 0) - using NodeType = Tpetra::KokkosCompat::KokkosDeviceWrapperNode< - typename MemorySpace::kokkos_space::execution_space, - typename MemorySpace::kokkos_space>; -# else - using NodeType = Kokkos::Compat::KokkosDeviceWrapperNode< - typename MemorySpace::kokkos_space::execution_space, - typename MemorySpace::kokkos_space>; -# endif - + using size_type = dealii::types::global_dof_index; /** * Declare an alias for the iterator class. */ using const_iterator = SparsityPatternIterators::Iterator; - /** - * Typedef for Tpetra::Map - */ - using MapType = - Tpetra::Map; - - /** - * Typedef for Tpetra::Graph - */ - using GraphType = - Tpetra::CrsGraph; - - /** * @name Basic constructors and initialization */ @@ -854,7 +805,7 @@ namespace LinearAlgebra * Return a Teuchos::RCP to the underlying Trilinos Tpetra::CrsGraph * data that stores the sparsity pattern. */ - Teuchos::RCP + Teuchos::RCP> trilinos_sparsity_pattern() const; /** @@ -863,7 +814,7 @@ namespace LinearAlgebra * pattern, i.e., the partitioning of the vectors matrices based on this * sparsity pattern are multiplied with. */ - Teuchos::RCP + Teuchos::RCP> domain_partitioner() const; /** @@ -872,7 +823,7 @@ namespace LinearAlgebra * i.e., the partitioning of the vectors that are result from matrix- * vector products. */ - Teuchos::RCP + Teuchos::RCP> range_partitioner() const; /** @@ -1036,14 +987,14 @@ namespace LinearAlgebra * Teuchos::RCP to the user-supplied Tpetra Trilinos mapping of the matrix * columns that assigns parts of the matrix to the individual processes. */ - Teuchos::RCP column_space_map; + Teuchos::RCP> column_space_map; /** * A sparsity pattern object in Trilinos to be used for finite element * based problems which allows for adding non-local elements to the * pattern. */ - Teuchos::RCP graph; + Teuchos::RCP> graph; /** * A sparsity pattern object for the non-local part of the sparsity @@ -1051,7 +1002,7 @@ namespace LinearAlgebra * when the particular constructor or reinit method with writable_rows * argument is set */ - Teuchos::RCP nonlocal_graph; + Teuchos::RCP> nonlocal_graph; // TODO: currently only for double friend class SparseMatrix; @@ -1274,9 +1225,7 @@ namespace LinearAlgebra // place the iterator on the first entry // past this line, or at the end of the // matrix - for (size_type i = r + 1; - i < static_cast(n_rows()); - ++i) + for (size_type i = r + 1; i < n_rows(); ++i) if (row_length(i) > 0) return const_iterator(this, i, 0); @@ -1392,10 +1341,9 @@ namespace LinearAlgebra template - inline Teuchos::RCP< - Tpetra::CrsGraph::NodeType>> + inline Teuchos::RCP>> SparsityPattern::trilinos_sparsity_pattern() const { return graph; diff --git a/include/deal.II/lac/trilinos_tpetra_types.h b/include/deal.II/lac/trilinos_tpetra_types.h new file mode 100644 index 0000000000..5dda027e86 --- /dev/null +++ b/include/deal.II/lac/trilinos_tpetra_types.h @@ -0,0 +1,137 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2018 - 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + +#ifndef dealii_trilinos_tpetra_types_h +#define dealii_trilinos_tpetra_types_h + +#include + +#include "deal.II/base/types.h" + +#ifdef DEAL_II_TRILINOS_WITH_TPETRA + +# include + +// Forward declarations +# ifndef DOXYGEN +# include +# include +# include +# include +# include +# include +# include +# include + +# endif + +DEAL_II_NAMESPACE_OPEN + +namespace LinearAlgebra +{ + namespace TpetraWrappers + { + + namespace TpetraTypes + { + /** + * local ordinate (processor local indices). + */ + using LO = int; + /** + * global ordinate (global indices). + */ + using GO = types::signed_global_dof_index; + + +# if DEAL_II_TRILINOS_VERSION_GTE(14, 2, 0) + /** + * Where and how calculations should be executed, + * i.e. Host (Serial,OpenMP) or Device (GPU) + */ + // + template + using NodeType = Tpetra::KokkosCompat::KokkosDeviceWrapperNode< + typename MemorySpace::kokkos_space::execution_space, + typename MemorySpace::kokkos_space>; +# else + template + using NodeType = Kokkos::Compat::KokkosDeviceWrapperNode< + typename MemorySpace::kokkos_space::execution_space, + typename MemorySpace::kokkos_space>; +# endif + + + /** + * Communication between processors. + */ + template + using ExportType = Tpetra::Export>; + + /** + * Communication between processors. + */ + template + using ImportType = Tpetra::Import>; + + /** + * Tpetra equivalent of IndexSet. + */ + template + using MapType = Tpetra::Map>; + + /** + * Tpetra sparsity pattern type. + */ + template + using GraphType = Tpetra::CrsGraph>; + + /** + * Tpetra Vector type. + */ + template + using VectorType = Tpetra::Vector>; + + /** + * Tpetra type for a row column vectors. + */ + template + using MultiVectorType = + Tpetra::MultiVector>; + + + /** + * General Tpetra class for a linear operator, + * e.g. a Matrix or Preconditioner. + * + */ + template + using LinearOperator = + Tpetra::Operator>; + + + /** + * Tpetra type for a parallel distributed sparse matrix in Crs or CSR + * format. + */ + template + using MatrixType = + Tpetra::CrsMatrix>; + } // namespace TpetraTypes + } // namespace TpetraWrappers +} // namespace LinearAlgebra +DEAL_II_NAMESPACE_CLOSE +#endif + +#endif diff --git a/include/deal.II/lac/trilinos_tpetra_vector.h b/include/deal.II/lac/trilinos_tpetra_vector.h index 8e44eb0b49..8af54bcc45 100644 --- a/include/deal.II/lac/trilinos_tpetra_vector.h +++ b/include/deal.II/lac/trilinos_tpetra_vector.h @@ -18,6 +18,10 @@ #include +#include "deal.II/base/types.h" + +#include + #ifdef DEAL_II_TRILINOS_WITH_TPETRA # include @@ -100,6 +104,7 @@ namespace LinearAlgebra */ namespace TpetraWrappers { + /** * This class defines type aliases that are used in vector classes * within the TpetraWrappers namespace. @@ -107,7 +112,7 @@ namespace LinearAlgebra class VectorTraits { public: - using size_type = dealii::types::global_dof_index; + using size_type = types::global_dof_index; }; /** @@ -125,7 +130,7 @@ namespace LinearAlgebra /** * Declare type for container size. */ - using size_type = VectorTraits::size_type; + using size_type = types::global_dof_index; /** * This class implements a wrapper for accessing the Trilinos Tpetra @@ -286,29 +291,12 @@ namespace LinearAlgebra /** * Declare some of the standard types used in all containers. */ -# if DEAL_II_TRILINOS_VERSION_GTE(14, 2, 0) - using NodeType = Tpetra::KokkosCompat::KokkosDeviceWrapperNode< - typename MemorySpace::kokkos_space::execution_space, - typename MemorySpace::kokkos_space>; -# else - using NodeType = Kokkos::Compat::KokkosDeviceWrapperNode< - typename MemorySpace::kokkos_space::execution_space, - typename MemorySpace::kokkos_space>; -# endif using value_type = Number; using real_type = typename numbers::NumberTraits::real_type; - using size_type = VectorTraits::size_type; + using size_type = types::global_dof_index; using reference = internal::VectorReference; using const_reference = const internal::VectorReference; - using MapType = - Tpetra::Map; - using VectorType = Tpetra:: - Vector; - using ExportType = - Tpetra::Export; - using ImportType = - Tpetra::Import; /** * @name 1: Basic Object-handling @@ -330,7 +318,8 @@ namespace LinearAlgebra /** * Copy constructor from Teuchos::RCP. */ - Vector(const Teuchos::RCP V); + Vector( + const Teuchos::RCP> V); /** * TODO: This is not used @@ -912,29 +901,28 @@ namespace LinearAlgebra * Return a const reference to the underlying Trilinos * Tpetra::Vector class. */ - const Tpetra::Vector & + const TpetraTypes::VectorType & trilinos_vector() const; /** * Return a (modifiable) reference to the underlying Trilinos * Tpetra::Vector class. */ - Tpetra::Vector & + TpetraTypes::VectorType & trilinos_vector(); /** * Return a const Teuchos::RCP to the underlying Trilinos * Tpetra::Vector class. */ - Teuchos::RCP< - const Tpetra::Vector> + Teuchos::RCP> trilinos_rcp() const; /** * Return a (modifiable) Teuchos::RCP to the underlying Trilinos * Tpetra::Vector class. */ - Teuchos::RCP> + Teuchos::RCP> trilinos_rcp(); /** @@ -1056,14 +1044,15 @@ namespace LinearAlgebra /** * Teuchos::RCP to the actual Tpetra vector object. */ - Teuchos::RCP vector; + Teuchos::RCP> vector; /** * A vector object in Trilinos to be used for collecting the non-local * elements if the vector was constructed with an additional IndexSet * describing ghost elements. */ - Teuchos::RCP nonlocal_vector; + Teuchos::RCP> + nonlocal_vector; /** * IndexSet of the elements of the last imported vector. diff --git a/include/deal.II/lac/trilinos_tpetra_vector.templates.h b/include/deal.II/lac/trilinos_tpetra_vector.templates.h index c28a18481c..0a3cd3ffed 100644 --- a/include/deal.II/lac/trilinos_tpetra_vector.templates.h +++ b/include/deal.II/lac/trilinos_tpetra_vector.templates.h @@ -81,11 +81,10 @@ namespace LinearAlgebra : Subscriptor() , compressed(true) , has_ghost(false) - , vector(Utilities::Trilinos::internal::make_rcp( - Utilities::Trilinos::internal::make_rcp( - 0, - 0, - Utilities::Trilinos::tpetra_comm_self()))) + , vector(Utilities::Trilinos::internal::make_rcp< + TpetraTypes::VectorType>( + Utilities::Trilinos::internal::make_rcp>(0, 0, Utilities::Trilinos::tpetra_comm_self()))) {} @@ -95,19 +94,21 @@ namespace LinearAlgebra : Subscriptor() , compressed(V.compressed) , has_ghost(V.has_ghost) - , vector( - Utilities::Trilinos::internal::make_rcp(*V.vector, - Teuchos::Copy)) + , vector(Utilities::Trilinos::internal::make_rcp< + TpetraTypes::VectorType>(*V.vector, + Teuchos::Copy)) { if (!V.nonlocal_vector.is_null()) - nonlocal_vector = Utilities::Trilinos::internal::make_rcp( - *V.nonlocal_vector, Teuchos::Copy); + nonlocal_vector = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::VectorType>(*V.nonlocal_vector, + Teuchos::Copy); } template - Vector::Vector(const Teuchos::RCP V) + Vector::Vector( + const Teuchos::RCP> V) : Subscriptor() , compressed(true) , has_ghost(V->getMap()->isOneToOne() == false) @@ -122,7 +123,8 @@ namespace LinearAlgebra : Subscriptor() , compressed(true) , has_ghost(false) - , vector(Utilities::Trilinos::internal::make_rcp( + , vector(Utilities::Trilinos::internal::make_rcp< + TpetraTypes::VectorType>( parallel_partitioner.make_tpetra_map_rcp(communicator, true))) {} @@ -140,20 +142,23 @@ namespace LinearAlgebra IndexSet parallel_partitioner = locally_owned_entries; parallel_partitioner.add_indices(ghost_entries); - vector = Utilities::Trilinos::internal::make_rcp( + vector = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::VectorType>( parallel_partitioner.make_tpetra_map_rcp(communicator, true)); compressed = true; } else { - Teuchos::RCP map = + Teuchos::RCP> map = locally_owned_entries.make_tpetra_map_rcp(communicator, false); - vector = Utilities::Trilinos::internal::make_rcp(map); + vector = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::VectorType>(map); IndexSet nonlocal_entries(ghost_entries); nonlocal_entries.subtract_set(locally_owned_entries); - nonlocal_vector = Utilities::Trilinos::internal::make_rcp( + nonlocal_vector = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::VectorType>( nonlocal_entries.make_tpetra_map_rcp(communicator, true)); compressed = false; @@ -176,8 +181,10 @@ namespace LinearAlgebra void Vector::clear() { - vector = Utilities::Trilinos::internal::make_rcp( - Utilities::Trilinos::internal::make_rcp( + vector = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::VectorType>( + Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MapType>( 0, 0, Utilities::Trilinos::tpetra_comm_self())); has_ghost = false; compressed = true; @@ -197,7 +204,8 @@ namespace LinearAlgebra compressed = true; has_ghost = false; - vector = Utilities::Trilinos::internal::make_rcp( + vector = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::VectorType>( parallel_partitioner.make_tpetra_map_rcp(communicator, true)); } @@ -220,20 +228,22 @@ namespace LinearAlgebra IndexSet parallel_partitioner = locally_owned_entries; parallel_partitioner.add_indices(ghost_entries); - vector = Utilities::Trilinos::internal::make_rcp( + vector = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::VectorType>( parallel_partitioner.make_tpetra_map_rcp(communicator, true)); compressed = true; } else { - Teuchos::RCP map = + Teuchos::RCP> map = locally_owned_entries.make_tpetra_map_rcp(communicator, false); if (!vector->getMap()->isSameAs(*map)) { vector.reset(); - vector = Utilities::Trilinos::internal::make_rcp(map); + vector = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::VectorType>(map); } else vector->putScalar(0); @@ -241,7 +251,8 @@ namespace LinearAlgebra IndexSet nonlocal_entries(ghost_entries); nonlocal_entries.subtract_set(locally_owned_entries); - nonlocal_vector = Utilities::Trilinos::internal::make_rcp( + nonlocal_vector = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::VectorType>( nonlocal_entries.make_tpetra_map_rcp(communicator, true)); compressed = false; @@ -385,7 +396,7 @@ namespace LinearAlgebra "Therefore, compress() must be called on this " "vector first.")); - Teuchos::RCP importer = + Teuchos::RCP> importer = Tpetra::createImport(V.vector->getMap(), vector->getMap()); // Since we are distributing the vector from a one-to-one map @@ -396,9 +407,9 @@ namespace LinearAlgebra else { vector.reset(); - vector = - Utilities::Trilinos::internal::make_rcp(*V.vector, - Teuchos::Copy); + vector = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::VectorType>(*V.vector, + Teuchos::Copy); compressed = V.compressed; has_ghost = V.has_ghost; @@ -424,7 +435,8 @@ namespace LinearAlgebra nonlocal_vector.reset(); Teuchos::Array vector_data(V.begin(), V.end()); - vector = Utilities::Trilinos::internal::make_rcp( + vector = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::VectorType>( V.locally_owned_elements().make_tpetra_map_rcp(), vector_data); has_ghost = false; @@ -494,10 +506,11 @@ namespace LinearAlgebra "LinearAlgebra::TpetraWrappers::CommunicationPattern.")); } - Teuchos::RCP tpetra_export = + Teuchos::RCP> tpetra_export = tpetra_comm_pattern->get_tpetra_export_rcp(); - VectorType source_vector(tpetra_export->getSourceMap()); + TpetraTypes::VectorType source_vector( + tpetra_export->getSourceMap()); { # if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0) @@ -605,8 +618,8 @@ namespace LinearAlgebra // elements, maybe there is a better workaround. Tpetra::Vector dummy( vector->getMap(), false); - ImportType data_exchange(V.trilinos_vector().getMap(), - dummy.getMap()); + TpetraTypes::ImportType data_exchange( + V.trilinos_vector().getMap(), dummy.getMap()); dummy.doImport(V.trilinos_vector(), data_exchange, Tpetra::INSERT); vector->update(1.0, dummy, 1.0); @@ -1105,7 +1118,7 @@ namespace LinearAlgebra else DEAL_II_NOT_IMPLEMENTED(); - Teuchos::RCP exporter = + Teuchos::RCP> exporter = Tpetra::createExport(nonlocal_vector->getMap(), vector->getMap()); vector->doExport(*nonlocal_vector, *exporter, tpetra_operation); @@ -1116,7 +1129,7 @@ namespace LinearAlgebra template - const Tpetra::Vector & + const TpetraTypes::VectorType & Vector::trilinos_vector() const { return *vector; @@ -1125,7 +1138,7 @@ namespace LinearAlgebra template - Tpetra::Vector & + TpetraTypes::VectorType & Vector::trilinos_vector() { return *vector; @@ -1134,7 +1147,7 @@ namespace LinearAlgebra template - Teuchos::RCP> + Teuchos::RCP> Vector::trilinos_rcp() { return vector; @@ -1143,8 +1156,7 @@ namespace LinearAlgebra template - Teuchos::RCP< - const Tpetra::Vector> + Teuchos::RCP> Vector::trilinos_rcp() const { return vector.getConst(); diff --git a/include/deal.II/lac/vector.templates.h b/include/deal.II/lac/vector.templates.h index 139d7a6b69..cc7b511dbb 100644 --- a/include/deal.II/lac/vector.templates.h +++ b/include/deal.II/lac/vector.templates.h @@ -198,13 +198,13 @@ Vector::Vector( // Copy the distributed vector to // a local one at all processors // that know about the original vector. - typename LinearAlgebra::TpetraWrappers::Vector::VectorType + LinearAlgebra::TpetraWrappers::TpetraTypes::VectorType localized_vector(complete_index_set(size()).make_tpetra_map_rcp(), v.get_mpi_communicator()); - Teuchos::RCP::ImportType> + Teuchos::RCP> importer = Tpetra::createImport(v.trilinos_vector().getMap(), localized_vector.getMap()); @@ -888,13 +888,13 @@ Vector::operator=( // Copy the distributed vector to // a local one at all processors // that know about the original vector. - typename LinearAlgebra::TpetraWrappers::Vector::VectorType + LinearAlgebra::TpetraWrappers::TpetraTypes::VectorType localized_vector(complete_index_set(size()).make_tpetra_map_rcp(), v.get_mpi_communicator()); - Teuchos::RCP::ImportType> + Teuchos::RCP> importer = Tpetra::createImport(v.trilinos_vector().getMap(), localized_vector.getMap()); diff --git a/source/lac/trilinos_tpetra_communication_pattern.cc b/source/lac/trilinos_tpetra_communication_pattern.cc index 184f38ae19..a4dd925139 100644 --- a/source/lac/trilinos_tpetra_communication_pattern.cc +++ b/source/lac/trilinos_tpetra_communication_pattern.cc @@ -12,6 +12,9 @@ // // ------------------------------------------------------------------------ +#include "deal.II/base/memory_space.h" + +#include "deal.II/lac/trilinos_tpetra_types.h" #include #ifdef DEAL_II_TRILINOS_WITH_TPETRA @@ -84,7 +87,7 @@ namespace LinearAlgebra - Teuchos::RCP> + Teuchos::RCP> CommunicationPattern::get_tpetra_import_rcp() const { return tpetra_import; @@ -100,7 +103,7 @@ namespace LinearAlgebra - Teuchos::RCP> + Teuchos::RCP> CommunicationPattern::get_tpetra_export_rcp() const { return tpetra_export; diff --git a/source/lac/trilinos_tpetra_sparsity_pattern.cc b/source/lac/trilinos_tpetra_sparsity_pattern.cc index c7be32eb78..91ccd3234a 100644 --- a/source/lac/trilinos_tpetra_sparsity_pattern.cc +++ b/source/lac/trilinos_tpetra_sparsity_pattern.cc @@ -60,10 +60,8 @@ namespace LinearAlgebra // get a representation of the present row std::size_t ncols; # if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0) - typename Tpetra::CrsGraph< - int, - dealii::types::signed_global_dof_index, - NodeType>::nonconst_global_inds_host_view_type + typename TpetraTypes::GraphType< + MemorySpace>::nonconst_global_inds_host_view_type column_indices_view(colnum_cache->data(), colnum_cache->size()); # else Teuchos::ArrayView @@ -86,14 +84,15 @@ namespace LinearAlgebra template SparsityPattern::SparsityPattern() { - column_space_map = Utilities::Trilinos::internal::make_rcp( + column_space_map = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MapType>( TrilinosWrappers::types::int_type(0), TrilinosWrappers::types::int_type(0), Utilities::Trilinos::tpetra_comm_self()); - graph = - Utilities::Trilinos::internal::make_rcp(column_space_map, - column_space_map, - 0); + graph = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::GraphType>(column_space_map, + column_space_map, + 0); graph->fillComplete(); } @@ -137,14 +136,15 @@ namespace LinearAlgebra SparsityPattern::SparsityPattern( const SparsityPattern &input_sparsity) : SparsityPatternBase(input_sparsity) - , column_space_map(Utilities::Trilinos::internal::make_rcp( + , column_space_map(Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MapType>( 0, 0, Utilities::Trilinos::tpetra_comm_self())) - , graph( - Utilities::Trilinos::internal::make_rcp(column_space_map, - column_space_map, - 0)) + , graph(Utilities::Trilinos::internal::make_rcp< + TpetraTypes::GraphType>(column_space_map, + column_space_map, + 0)) { (void)input_sparsity; Assert(input_sparsity.n_rows() == 0, @@ -263,26 +263,15 @@ namespace LinearAlgebra template using size_type = typename SparsityPattern::size_type; - template - using MapType = - Tpetra::Map::NodeType>; - - template - using GraphType = - Tpetra::CrsGraph::NodeType>; - template void - reinit_sp(const Teuchos::RCP> &row_map, - const Teuchos::RCP> &col_map, - const size_type n_entries_per_row, - Teuchos::RCP> &column_space_map, - Teuchos::RCP> &graph, - Teuchos::RCP> &nonlocal_graph) + reinit_sp( + const Teuchos::RCP> &row_map, + const Teuchos::RCP> &col_map, + const size_type n_entries_per_row, + Teuchos::RCP> &column_space_map, + Teuchos::RCP> &graph, + Teuchos::RCP> &nonlocal_graph) { Assert(row_map->isOneToOne(), ExcMessage("Row map must be 1-to-1, i.e., no overlap between " @@ -303,20 +292,23 @@ namespace LinearAlgebra // columns as well. If we use a recent Trilinos version, we can also // require building a non-local graph which gives us thread-safe // initialization. - graph = Utilities::Trilinos::internal::make_rcp>( - row_map, row_map, n_entries_per_row); + graph = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::GraphType>(row_map, + row_map, + n_entries_per_row); } template void - reinit_sp(const Teuchos::RCP> &row_map, - const Teuchos::RCP> &col_map, - const std::vector> &n_entries_per_row, - Teuchos::RCP> &column_space_map, - Teuchos::RCP> &graph, - Teuchos::RCP> &nonlocal_graph) + reinit_sp( + const Teuchos::RCP> &row_map, + const Teuchos::RCP> &col_map, + const std::vector> &n_entries_per_row, + Teuchos::RCP> &column_space_map, + Teuchos::RCP> &graph, + Teuchos::RCP> &nonlocal_graph) { Assert(row_map->isOneToOne(), ExcMessage("Row map must be 1-to-1, i.e., no overlap between " @@ -363,21 +355,24 @@ namespace LinearAlgebra ExcMessage( "You are requesting to store more elements than global ordinal type allows.")); - graph = Utilities::Trilinos::internal::make_rcp>( - row_map, col_map, local_entries_per_row); + graph = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::GraphType>(row_map, + col_map, + local_entries_per_row); } template void - reinit_sp(const Teuchos::RCP> &row_map, - const Teuchos::RCP> &col_map, - const SparsityPatternType &sp, - [[maybe_unused]] const bool exchange_data, - Teuchos::RCP> &column_space_map, - Teuchos::RCP> &graph, - Teuchos::RCP> &nonlocal_graph) + reinit_sp( + const Teuchos::RCP> &row_map, + const Teuchos::RCP> &col_map, + const SparsityPatternType &sp, + [[maybe_unused]] const bool exchange_data, + Teuchos::RCP> &column_space_map, + Teuchos::RCP> &graph, + Teuchos::RCP> &nonlocal_graph) { nonlocal_graph.reset(); graph.reset(); @@ -385,9 +380,8 @@ namespace LinearAlgebra AssertDimension(sp.n_rows(), row_map->getGlobalNumElements()); AssertDimension(sp.n_cols(), col_map->getGlobalNumElements()); - column_space_map = - Utilities::Trilinos::internal::make_rcp>( - *col_map); + column_space_map = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MapType>(*col_map); Assert(row_map->isContiguous() == true, ExcMessage( @@ -417,13 +411,13 @@ namespace LinearAlgebra # if DEAL_II_TRILINOS_VERSION_GTE(12, 16, 0) if (row_map->getComm()->getSize() > 1) - graph = - Utilities::Trilinos::internal::make_rcp>( - row_map, n_entries_per_row); + graph = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::GraphType>(row_map, n_entries_per_row); else - graph = - Utilities::Trilinos::internal::make_rcp>( - row_map, col_map, n_entries_per_row); + graph = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::GraphType>(row_map, + col_map, + n_entries_per_row); # else if (row_map->getComm()->getSize() > 1) graph = @@ -476,7 +470,7 @@ namespace LinearAlgebra { SparsityPatternBase::resize(parallel_partitioning.size(), parallel_partitioning.size()); - Teuchos::RCP map = + Teuchos::RCP> map = parallel_partitioning.make_tpetra_map_rcp(communicator, false); SparsityPatternImpl::reinit_sp( map, map, n_entries_per_row, column_space_map, graph, nonlocal_graph); @@ -493,7 +487,7 @@ namespace LinearAlgebra { SparsityPatternBase::resize(parallel_partitioning.size(), parallel_partitioning.size()); - Teuchos::RCP map = + Teuchos::RCP> map = parallel_partitioning.make_tpetra_map_rcp(communicator, false); SparsityPatternImpl::reinit_sp( map, map, n_entries_per_row, column_space_map, graph, nonlocal_graph); @@ -511,9 +505,9 @@ namespace LinearAlgebra { SparsityPatternBase::resize(row_parallel_partitioning.size(), col_parallel_partitioning.size()); - Teuchos::RCP row_map = + Teuchos::RCP> row_map = row_parallel_partitioning.make_tpetra_map_rcp(communicator, false); - Teuchos::RCP col_map = + Teuchos::RCP> col_map = col_parallel_partitioning.make_tpetra_map_rcp(communicator, false); SparsityPatternImpl::reinit_sp(row_map, col_map, @@ -535,9 +529,9 @@ namespace LinearAlgebra { SparsityPatternBase::resize(row_parallel_partitioning.size(), col_parallel_partitioning.size()); - Teuchos::RCP row_map = + Teuchos::RCP> row_map = row_parallel_partitioning.make_tpetra_map_rcp(communicator, false); - Teuchos::RCP col_map = + Teuchos::RCP> col_map = col_parallel_partitioning.make_tpetra_map_rcp(communicator, false); SparsityPatternImpl::reinit_sp(row_map, col_map, @@ -560,9 +554,9 @@ namespace LinearAlgebra { SparsityPatternBase::resize(row_parallel_partitioning.size(), col_parallel_partitioning.size()); - Teuchos::RCP row_map = + Teuchos::RCP> row_map = row_parallel_partitioning.make_tpetra_map_rcp(communicator, false); - Teuchos::RCP col_map = + Teuchos::RCP> col_map = col_parallel_partitioning.make_tpetra_map_rcp(communicator, false); SparsityPatternImpl::reinit_sp(row_map, col_map, @@ -586,12 +580,10 @@ namespace LinearAlgebra nonlocal_partitioner.subtract_set(row_parallel_partitioning); if (Utilities::MPI::n_mpi_processes(communicator) > 1) { - Teuchos::RCP nonlocal_map = + Teuchos::RCP> nonlocal_map = nonlocal_partitioner.make_tpetra_map_rcp(communicator, true); - nonlocal_graph = - Utilities::Trilinos::internal::make_rcp(nonlocal_map, - col_map, - 0); + nonlocal_graph = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::GraphType>(nonlocal_map, col_map, 0); } else Assert(nonlocal_partitioner.n_elements() == 0, ExcInternalError()); @@ -611,9 +603,9 @@ namespace LinearAlgebra { SparsityPatternBase::resize(row_parallel_partitioning.size(), col_parallel_partitioning.size()); - Teuchos::RCP row_map = + Teuchos::RCP> row_map = row_parallel_partitioning.make_tpetra_map_rcp(communicator, false); - Teuchos::RCP col_map = + Teuchos::RCP> col_map = col_parallel_partitioning.make_tpetra_map_rcp(communicator, false); SparsityPatternImpl::reinit_sp( row_map, @@ -642,7 +634,7 @@ namespace LinearAlgebra parallel_partitioning.size()); SparsityPatternBase::resize(parallel_partitioning.size(), parallel_partitioning.size()); - Teuchos::RCP map = + Teuchos::RCP> map = parallel_partitioning.make_tpetra_map_rcp(communicator, false); SparsityPatternImpl::reinit_sp( map, @@ -673,13 +665,14 @@ namespace LinearAlgebra const SparsityPattern &sp) { SparsityPatternBase::resize(sp.n_rows(), sp.n_cols()); - column_space_map = - Utilities::Trilinos::internal::make_rcp(*sp.column_space_map); - graph = Utilities::Trilinos::internal::make_rcp(*sp.graph); + column_space_map = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MapType>(*sp.column_space_map); + graph = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::GraphType>(*sp.graph); if (sp.nonlocal_graph.get() != nullptr) - nonlocal_graph = Utilities::Trilinos::internal::make_rcp( - *sp.nonlocal_graph); + nonlocal_graph = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::GraphType>(*sp.nonlocal_graph); else nonlocal_graph.reset(); } @@ -692,13 +685,15 @@ namespace LinearAlgebra SparsityPattern::copy_from(const SparsityPatternType &sp) { SparsityPatternBase::resize(sp.n_rows(), sp.n_cols()); - Teuchos::RCP rows = - Utilities::Trilinos::internal::make_rcp( + Teuchos::RCP> rows = + Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MapType>( TrilinosWrappers::types::int_type(sp.n_rows()), 0, Utilities::Trilinos::tpetra_comm_self()); - Teuchos::RCP columns = - Utilities::Trilinos::internal::make_rcp( + Teuchos::RCP> columns = + Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MapType>( TrilinosWrappers::types::int_type(sp.n_cols()), 0, Utilities::Trilinos::tpetra_comm_self()); @@ -717,14 +712,15 @@ namespace LinearAlgebra // When we clear the matrix, reset // the pointer and generate an // empty sparsity pattern. - column_space_map = Utilities::Trilinos::internal::make_rcp( + column_space_map = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::MapType>( TrilinosWrappers::types::int_type(0), TrilinosWrappers::types::int_type(0), Utilities::Trilinos::tpetra_comm_self()); - graph = - Utilities::Trilinos::internal::make_rcp(column_space_map, - column_space_map, - 0); + graph = Utilities::Trilinos::internal::make_rcp< + TpetraTypes::GraphType>(column_space_map, + column_space_map, + 0); graph->fillComplete(); nonlocal_graph.reset(); @@ -816,7 +812,8 @@ namespace LinearAlgebra const auto trilinos_i = graph->getRowMap()->getLocalElement(i); const auto trilinos_j = graph->getColMap()->getLocalElement(j); - typename GraphType::local_inds_host_view_type col_indices; + typename TpetraTypes::GraphType::local_inds_host_view_type + col_indices; // Generate the view. graph->getLocalRowView(trilinos_i, col_indices); @@ -847,7 +844,8 @@ namespace LinearAlgebra for (int i = 0; i < static_cast(local_size()); ++i) { # if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0) - typename GraphType::local_inds_host_view_type indices; + typename TpetraTypes::GraphType< + MemorySpace>::local_inds_host_view_type indices; # else Teuchos::ArrayView indices; # endif @@ -953,7 +951,7 @@ namespace LinearAlgebra template - Teuchos::RCP::MapType> + Teuchos::RCP> SparsityPattern::domain_partitioner() const { return graph->getDomainMap(); @@ -962,7 +960,7 @@ namespace LinearAlgebra template - Teuchos::RCP::MapType> + Teuchos::RCP> SparsityPattern::range_partitioner() const { return graph->getRangeMap(); @@ -1009,7 +1007,8 @@ namespace LinearAlgebra # endif { # if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0) - typename GraphType::local_inds_host_view_type indices; + typename TpetraTypes::GraphType< + MemorySpace>::local_inds_host_view_type indices; # else Teuchos::ArrayView indices; # endif @@ -1036,7 +1035,8 @@ namespace LinearAlgebra for (unsigned int row = 0; row < local_size(); ++row) { # if DEAL_II_TRILINOS_VERSION_GTE(13, 2, 0) - typename GraphType::local_inds_host_view_type indices; + typename TpetraTypes::GraphType< + MemorySpace>::local_inds_host_view_type indices; # else Teuchos::ArrayView indices; # endif