From 5683d8d42823da8ceb5b2e077a8eb6c9dfbf5558 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Fri, 24 Feb 2023 10:51:29 -0500 Subject: [PATCH] Only instantiate Tpetra wrapper types for number types Tpetra explicitly instantiated --- cmake/configure/configure_20_trilinos.cmake | 27 ++++++++++---- include/deal.II/lac/read_write_vector.h | 8 +++-- .../deal.II/lac/read_write_vector.templates.h | 8 +++-- include/deal.II/lac/trilinos_tpetra_vector.h | 35 +++++++++++++++++++ source/lac/affine_constraints.cc | 2 +- source/lac/read_write_vector.cc | 34 ++++++++++++++++++ source/lac/trilinos_sparse_matrix.cc | 16 +++++++++ source/lac/trilinos_tpetra_vector.cc | 8 +++++ 8 files changed, 126 insertions(+), 12 deletions(-) diff --git a/cmake/configure/configure_20_trilinos.cmake b/cmake/configure/configure_20_trilinos.cmake index b13a0a7224..a91ca1bf3c 100644 --- a/cmake/configure/configure_20_trilinos.cmake +++ b/cmake/configure/configure_20_trilinos.cmake @@ -264,15 +264,19 @@ macro(feature_trilinos_find_external var) TRILINOS_TPETRA_IS_FUNCTIONAL ) - reset_cmake_required() - - if(NOT TRILINOS_TPETRA_IS_FUNCTIONAL) + if(TRILINOS_TPETRA_IS_FUNCTIONAL) + check_cxx_symbol_exists(HAVE_TPETRA_INST_FLOAT "TpetraCore_config.h" DEAL_II_HAVE_TPETRA_INST_FLOAT) + check_cxx_symbol_exists(HAVE_TPETRA_INST_DOUBLE "TpetraCore_config.h" DEAL_II_HAVE_TPETRA_INST_DOUBLE) + check_cxx_symbol_exists(HAVE_TPETRA_INST_COMPLEX_FLOAT "TpetraCore_config.h" DEAL_II_HAVE_TPETRA_INST_COMPLEX_FLOAT) + check_cxx_symbol_exists(HAVE_TPETRA_INST_COMPLEX_DOUBLE "TpetraCore_config.h" DEAL_II_HAVE_TPETRA_INST_COMPLEX_DOUBLE) + else() message( STATUS "Tpetra was found but is not usable! Disabling Tpetra support." ) set(TRILINOS_WITH_TPETRA OFF) endif() + reset_cmake_required() endif() if(TRILINOS_WITH_MUELU) @@ -421,12 +425,21 @@ macro(feature_trilinos_configure_external) set(DEAL_II_EXPAND_TRILINOS_MPI_BLOCKVECTOR "TrilinosWrappers::MPI::BlockVector") set(DEAL_II_EXPAND_TRILINOS_MPI_VECTOR "TrilinosWrappers::MPI::Vector") set(DEAL_II_EXPAND_EPETRA_VECTOR "LinearAlgebra::EpetraWrappers::Vector") + if(${DEAL_II_TRILINOS_WITH_TPETRA}) - set(DEAL_II_EXPAND_TPETRA_VECTOR_DOUBLE "LinearAlgebra::TpetraWrappers::Vector") - set(DEAL_II_EXPAND_TPETRA_VECTOR_FLOAT "LinearAlgebra::TpetraWrappers::Vector") + if (DEAL_II_HAVE_TPETRA_INST_DOUBLE) + set(DEAL_II_EXPAND_TPETRA_VECTOR_DOUBLE "LinearAlgebra::TpetraWrappers::Vector") + endif() + if (DEAL_II_HAVE_TPETRA_INST_FLOAT) + set(DEAL_II_EXPAND_TPETRA_VECTOR_FLOAT "LinearAlgebra::TpetraWrappers::Vector") + endif() if(${DEAL_II_WITH_COMPLEX_NUMBERS}) - set(DEAL_II_EXPAND_TPETRA_VECTOR_COMPLEX_DOUBLE "LinearAlgebra::TpetraWrappers::Vector>") - set(DEAL_II_EXPAND_TPETRA_VECTOR_COMPLEX_FLOAT "LinearAlgebra::TpetraWrappers::Vector>") + if(DEAL_II_HAVE_TPETRA_INST_COMPLEX_DOUBLE) + set(DEAL_II_EXPAND_TPETRA_VECTOR_COMPLEX_DOUBLE "LinearAlgebra::TpetraWrappers::Vector>") + endif() + if(DEAL_II_HAVE_TPETRA_INST_COMPLEX_FLOAT) + set(DEAL_II_EXPAND_TPETRA_VECTOR_COMPLEX_FLOAT "LinearAlgebra::TpetraWrappers::Vector>") + endif() endif() endif() diff --git a/include/deal.II/lac/read_write_vector.h b/include/deal.II/lac/read_write_vector.h index 62358e0917..1e410eaa22 100644 --- a/include/deal.II/lac/read_write_vector.h +++ b/include/deal.II/lac/read_write_vector.h @@ -375,7 +375,9 @@ namespace LinearAlgebra * communication pattern is used multiple times. This can be used to improve * performance. */ - void + template + std::enable_if_t::value && + dealii::is_tpetra_type::value> import(const TpetraWrappers::Vector &tpetra_vec, VectorOperation::values operation, const std::shared_ptr @@ -656,7 +658,9 @@ namespace LinearAlgebra * vector @p tpetra_vector. This is an helper function and it should not be * used directly. */ - void + template + std::enable_if_t::value && + dealii::is_tpetra_type::value> import(const Tpetra::Vector & tpetra_vector, const IndexSet & locally_owned_elements, diff --git a/include/deal.II/lac/read_write_vector.templates.h b/include/deal.II/lac/read_write_vector.templates.h index 66e4f5a276..b4feeac417 100644 --- a/include/deal.II/lac/read_write_vector.templates.h +++ b/include/deal.II/lac/read_write_vector.templates.h @@ -575,7 +575,9 @@ namespace LinearAlgebra #ifdef DEAL_II_WITH_TRILINOS # ifdef DEAL_II_TRILINOS_WITH_TPETRA template - void + template + std::enable_if_t::value && + dealii::is_tpetra_type::value> ReadWriteVector::import( const Tpetra::Vector &vector, const IndexSet & source_elements, @@ -858,7 +860,9 @@ namespace LinearAlgebra # ifdef DEAL_II_TRILINOS_WITH_TPETRA template - void + template + std::enable_if_t::value && + dealii::is_tpetra_type::value> ReadWriteVector::import( const LinearAlgebra::TpetraWrappers::Vector &trilinos_vec, VectorOperation::values operation, diff --git a/include/deal.II/lac/trilinos_tpetra_vector.h b/include/deal.II/lac/trilinos_tpetra_vector.h index 6cf689122b..3fa6d81fdf 100644 --- a/include/deal.II/lac/trilinos_tpetra_vector.h +++ b/include/deal.II/lac/trilinos_tpetra_vector.h @@ -40,6 +40,41 @@ DEAL_II_NAMESPACE_OPEN +/** + * Type trait indicating if a certain number type has been explicitly + * instantiated in Tpetra. deal.II only supports those number types in Tpetra + * wrapper classes. + */ +template +struct is_tpetra_type : std::false_type +{}; + +# ifdef HAVE_TPETRA_INST_FLOAT +template <> +struct is_tpetra_type : std::true_type +{}; +# endif + +# ifdef HAVE_TPETRA_INST_DOUBLE +template <> +struct is_tpetra_type : std::true_type +{}; +# endif + +# ifdef DEAL_II_WITH_COMPLEX_VALUES +# ifdef HAVE_TPETRA_INST_COMPLEX_FLOAT +template <> +struct is_tpetra_type> : std::true_type +{}; +# endif + +# ifdef HAVE_TPETRA_INST_COMPLEX_DOUBLE +template <> +struct is_tpetra_type> : std::true_type +{}; +# endif +# endif + namespace LinearAlgebra { // Forward declaration diff --git a/source/lac/affine_constraints.cc b/source/lac/affine_constraints.cc index 41a823a536..021a4df960 100644 --- a/source/lac/affine_constraints.cc +++ b/source/lac/affine_constraints.cc @@ -140,7 +140,7 @@ INSTANTIATE_DLTG_MATRIX(TrilinosWrappers::SparseMatrix); INSTANTIATE_DLTG_MATRIX(TrilinosWrappers::BlockSparseMatrix); # ifndef DOXYGEN -# ifdef DEAL_II_TRILINOS_WITH_TPETRA +# if defined(DEAL_II_TRILINOS_WITH_TPETRA) && defined(HAVE_TPETRA_INST_FLOAT) // FIXME: This mixed variant is needed for multigrid and matrix free. template void dealii::AffineConstraints::distribute< diff --git a/source/lac/read_write_vector.cc b/source/lac/read_write_vector.cc index 23ced9c5bf..453ddd3da9 100644 --- a/source/lac/read_write_vector.cc +++ b/source/lac/read_write_vector.cc @@ -77,6 +77,40 @@ namespace LinearAlgebra VectorOperation::values, const std::shared_ptr &); # endif + + + +# ifdef HAVE_TPETRA_INST_FLOAT + template void + ReadWriteVector::import( + const LinearAlgebra::TpetraWrappers::Vector &, + VectorOperation::values, + const std::shared_ptr &); +# endif +# ifdef HAVE_TPETRA_INST_DOUBLE + template void + ReadWriteVector::import( + const LinearAlgebra::TpetraWrappers::Vector &, + VectorOperation::values, + const std::shared_ptr &); +# endif +# ifdef DEAL_II_WITH_COMPLEX_VALUES +# ifdef HAVE_TPETRA_INST_COMPLEX_FLOAT + template void + ReadWriteVector>::import( + const LinearAlgebra::TpetraWrappers::Vector> &, + VectorOperation::values, + const std::shared_ptr &); +# endif +# ifdef HAVE_TPETRA_INST_COMPLEX_DOUBLE + template void + ReadWriteVector>::import( + const LinearAlgebra::TpetraWrappers::Vector> &, + VectorOperation::values, + const std::shared_ptr &); +# endif +# endif + #endif } // namespace LinearAlgebra diff --git a/source/lac/trilinos_sparse_matrix.cc b/source/lac/trilinos_sparse_matrix.cc index d0d3c26374..7c5992f1e4 100644 --- a/source/lac/trilinos_sparse_matrix.cc +++ b/source/lac/trilinos_sparse_matrix.cc @@ -3046,15 +3046,19 @@ namespace TrilinosWrappers const dealii::LinearAlgebra::distributed::Vector &) const; # ifdef DEAL_II_TRILINOS_WITH_TPETRA +# if defined(HAVE_TPETRA_INST_DOUBLE) template void SparseMatrix::vmult( dealii::LinearAlgebra::TpetraWrappers::Vector &, const dealii::LinearAlgebra::TpetraWrappers::Vector &) const; +# endif +# if defined(HAVE_TPETRA_INST_FLOAT) template void SparseMatrix::vmult( dealii::LinearAlgebra::TpetraWrappers::Vector &, const dealii::LinearAlgebra::TpetraWrappers::Vector &) const; +# endif # endif template void @@ -3075,15 +3079,19 @@ namespace TrilinosWrappers const dealii::LinearAlgebra::distributed::Vector &) const; # ifdef DEAL_II_TRILINOS_WITH_TPETRA +# if defined(HAVE_TPETRA_INST_DOUBLE) template void SparseMatrix::Tvmult( dealii::LinearAlgebra::TpetraWrappers::Vector &, const dealii::LinearAlgebra::TpetraWrappers::Vector &) const; +# endif +# if defined(HAVE_TPETRA_INST_FLOAT) template void SparseMatrix::Tvmult( dealii::LinearAlgebra::TpetraWrappers::Vector &, const dealii::LinearAlgebra::TpetraWrappers::Vector &) const; +# endif # endif template void @@ -3104,15 +3112,19 @@ namespace TrilinosWrappers const dealii::LinearAlgebra::distributed::Vector &) const; # ifdef DEAL_II_TRILINOS_WITH_TPETRA +# if defined(HAVE_TPETRA_INST_DOUBLE) template void SparseMatrix::vmult_add( dealii::LinearAlgebra::TpetraWrappers::Vector &, const dealii::LinearAlgebra::TpetraWrappers::Vector &) const; +# endif +# if defined(HAVE_TPETRA_INST_FLOAT) template void SparseMatrix::vmult_add( dealii::LinearAlgebra::TpetraWrappers::Vector &, const dealii::LinearAlgebra::TpetraWrappers::Vector &) const; +# endif # endif template void @@ -3133,15 +3145,19 @@ namespace TrilinosWrappers const dealii::LinearAlgebra::distributed::Vector &) const; # ifdef DEAL_II_TRILINOS_WITH_TPETRA +# if defined(HAVE_TPETRA_INST_DOUBLE) template void SparseMatrix::Tvmult_add( dealii::LinearAlgebra::TpetraWrappers::Vector &, const dealii::LinearAlgebra::TpetraWrappers::Vector &) const; +# endif +# if defined(HAVE_TPETRA_INST_FLOAT) template void SparseMatrix::Tvmult_add( dealii::LinearAlgebra::TpetraWrappers::Vector &, const dealii::LinearAlgebra::TpetraWrappers::Vector &) const; +# endif # endif template void diff --git a/source/lac/trilinos_tpetra_vector.cc b/source/lac/trilinos_tpetra_vector.cc index 73a7621b95..91e0728178 100644 --- a/source/lac/trilinos_tpetra_vector.cc +++ b/source/lac/trilinos_tpetra_vector.cc @@ -23,11 +23,19 @@ namespace LinearAlgebra { namespace TpetraWrappers { +# ifdef HAVE_TPETRA_INST_FLOAT template class Vector; +# endif +# ifdef HAVE_TPETRA_INST_DOUBLE template class Vector; +# endif # ifdef DEAL_II_WITH_COMPLEX_VALUES +# ifdef HAVE_TPETRA_INST_COMPLEX_FLOAT template class Vector>; +# endif +# ifdef HAVE_TPETRA_INST_COMPLEX_DOUBLE template class Vector>; +# endif # endif } // namespace TpetraWrappers } // namespace LinearAlgebra -- 2.39.5