Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only instantiate TpetraWrappers::Vector for types that have explicit instantiations in Tpetra #14824

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 20 additions & 7 deletions cmake/configure/configure_20_trilinos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<double>")
set(DEAL_II_EXPAND_TPETRA_VECTOR_FLOAT "LinearAlgebra::TpetraWrappers::Vector<float>")
if (DEAL_II_HAVE_TPETRA_INST_DOUBLE)
set(DEAL_II_EXPAND_TPETRA_VECTOR_DOUBLE "LinearAlgebra::TpetraWrappers::Vector<double>")
endif()
if (DEAL_II_HAVE_TPETRA_INST_FLOAT)
set(DEAL_II_EXPAND_TPETRA_VECTOR_FLOAT "LinearAlgebra::TpetraWrappers::Vector<float>")
endif()
if(${DEAL_II_WITH_COMPLEX_NUMBERS})
set(DEAL_II_EXPAND_TPETRA_VECTOR_COMPLEX_DOUBLE "LinearAlgebra::TpetraWrappers::Vector<std::complex<double>>")
set(DEAL_II_EXPAND_TPETRA_VECTOR_COMPLEX_FLOAT "LinearAlgebra::TpetraWrappers::Vector<std::complex<float>>")
if(DEAL_II_HAVE_TPETRA_INST_COMPLEX_DOUBLE)
set(DEAL_II_EXPAND_TPETRA_VECTOR_COMPLEX_DOUBLE "LinearAlgebra::TpetraWrappers::Vector<std::complex<double>>")
endif()
if(DEAL_II_HAVE_TPETRA_INST_COMPLEX_FLOAT)
set(DEAL_II_EXPAND_TPETRA_VECTOR_COMPLEX_FLOAT "LinearAlgebra::TpetraWrappers::Vector<std::complex<float>>")
endif()
endif()
endif()

Expand Down
8 changes: 6 additions & 2 deletions include/deal.II/lac/read_write_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ namespace LinearAlgebra
* communication pattern is used multiple times. This can be used to improve
* performance.
*/
void
template <typename Dummy = Number>
std::enable_if_t<std::is_same<Dummy, Number>::value &&
dealii::is_tpetra_type<Number>::value>
import(const TpetraWrappers::Vector<Number> &tpetra_vec,
VectorOperation::values operation,
const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase>
Expand Down Expand Up @@ -656,7 +658,9 @@ namespace LinearAlgebra
* vector @p tpetra_vector. This is an helper function and it should not be
* used directly.
*/
void
template <typename Dummy = Number>
std::enable_if_t<std::is_same<Dummy, Number>::value &&
dealii::is_tpetra_type<Number>::value>
import(const Tpetra::Vector<Number, int, types::signed_global_dof_index>
& tpetra_vector,
const IndexSet & locally_owned_elements,
Expand Down
8 changes: 6 additions & 2 deletions include/deal.II/lac/read_write_vector.templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,9 @@ namespace LinearAlgebra
#ifdef DEAL_II_WITH_TRILINOS
# ifdef DEAL_II_TRILINOS_WITH_TPETRA
template <typename Number>
void
template <typename Dummy>
std::enable_if_t<std::is_same<Dummy, Number>::value &&
dealii::is_tpetra_type<Number>::value>
ReadWriteVector<Number>::import(
const Tpetra::Vector<Number, int, types::signed_global_dof_index> &vector,
const IndexSet & source_elements,
Expand Down Expand Up @@ -858,7 +860,9 @@ namespace LinearAlgebra

# ifdef DEAL_II_TRILINOS_WITH_TPETRA
template <typename Number>
void
template <typename Dummy>
std::enable_if_t<std::is_same<Dummy, Number>::value &&
dealii::is_tpetra_type<Number>::value>
ReadWriteVector<Number>::import(
const LinearAlgebra::TpetraWrappers::Vector<Number> &trilinos_vec,
VectorOperation::values operation,
Expand Down
35 changes: 35 additions & 0 deletions include/deal.II/lac/trilinos_tpetra_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename Number>
struct is_tpetra_type : std::false_type
{};

# ifdef HAVE_TPETRA_INST_FLOAT
template <>
struct is_tpetra_type<float> : std::true_type
{};
# endif

# ifdef HAVE_TPETRA_INST_DOUBLE
template <>
struct is_tpetra_type<double> : std::true_type
{};
# endif

# ifdef DEAL_II_WITH_COMPLEX_VALUES
# ifdef HAVE_TPETRA_INST_COMPLEX_FLOAT
template <>
struct is_tpetra_type<std::complex<float>> : std::true_type
{};
# endif

# ifdef HAVE_TPETRA_INST_COMPLEX_DOUBLE
template <>
struct is_tpetra_type<std::complex<double>> : std::true_type
{};
# endif
# endif

namespace LinearAlgebra
{
// Forward declaration
Expand Down
15 changes: 15 additions & 0 deletions include/deal.II/numerics/vector_tools_mean_value.templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,21 @@ namespace VectorTools
// TODO: no vector access using operator()
AssertThrow(false, ExcNotImplemented());
}



# ifdef DEAL_II_TRILINOS_WITH_TPETRA
template <int dim, int spacedim, typename ValueType>
void
add_constant(LinearAlgebra::TpetraWrappers::Vector<ValueType> &,
const DoFHandler<dim, spacedim> &,
const unsigned int,
const ValueType)
{
// TODO: no vector access using operator()
AssertThrow(false, ExcNotImplemented());
}
# endif
#endif


Expand Down
2 changes: 1 addition & 1 deletion source/lac/affine_constraints.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>::distribute<
Expand Down
34 changes: 34 additions & 0 deletions source/lac/read_write_vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,40 @@ namespace LinearAlgebra
VectorOperation::values,
const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase> &);
# endif



# ifdef HAVE_TPETRA_INST_FLOAT
template void
ReadWriteVector<float>::import(
const LinearAlgebra::TpetraWrappers::Vector<float> &,
VectorOperation::values,
const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase> &);
# endif
# ifdef HAVE_TPETRA_INST_DOUBLE
template void
ReadWriteVector<double>::import(
const LinearAlgebra::TpetraWrappers::Vector<double> &,
VectorOperation::values,
const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase> &);
# endif
# ifdef DEAL_II_WITH_COMPLEX_VALUES
# ifdef HAVE_TPETRA_INST_COMPLEX_FLOAT
template void
ReadWriteVector<std::complex<float>>::import(
const LinearAlgebra::TpetraWrappers::Vector<std::complex<float>> &,
VectorOperation::values,
const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase> &);
# endif
# ifdef HAVE_TPETRA_INST_COMPLEX_DOUBLE
template void
ReadWriteVector<std::complex<double>>::import(
const LinearAlgebra::TpetraWrappers::Vector<std::complex<double>> &,
VectorOperation::values,
const std::shared_ptr<const Utilities::MPI::CommunicationPatternBase> &);
# endif
# endif

#endif
} // namespace LinearAlgebra

Expand Down
16 changes: 16 additions & 0 deletions source/lac/trilinos_sparse_matrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3046,15 +3046,19 @@ namespace TrilinosWrappers
const dealii::LinearAlgebra::distributed::Vector<double> &) const;

# ifdef DEAL_II_TRILINOS_WITH_TPETRA
# if defined(HAVE_TPETRA_INST_DOUBLE)
template void
SparseMatrix::vmult(
dealii::LinearAlgebra::TpetraWrappers::Vector<double> &,
const dealii::LinearAlgebra::TpetraWrappers::Vector<double> &) const;
# endif

# if defined(HAVE_TPETRA_INST_FLOAT)
template void
SparseMatrix::vmult(
dealii::LinearAlgebra::TpetraWrappers::Vector<float> &,
const dealii::LinearAlgebra::TpetraWrappers::Vector<float> &) const;
# endif
# endif

template void
Expand All @@ -3075,15 +3079,19 @@ namespace TrilinosWrappers
const dealii::LinearAlgebra::distributed::Vector<double> &) const;

# ifdef DEAL_II_TRILINOS_WITH_TPETRA
# if defined(HAVE_TPETRA_INST_DOUBLE)
template void
SparseMatrix::Tvmult(
dealii::LinearAlgebra::TpetraWrappers::Vector<double> &,
const dealii::LinearAlgebra::TpetraWrappers::Vector<double> &) const;
# endif

# if defined(HAVE_TPETRA_INST_FLOAT)
template void
SparseMatrix::Tvmult(
dealii::LinearAlgebra::TpetraWrappers::Vector<float> &,
const dealii::LinearAlgebra::TpetraWrappers::Vector<float> &) const;
# endif
# endif

template void
Expand All @@ -3104,15 +3112,19 @@ namespace TrilinosWrappers
const dealii::LinearAlgebra::distributed::Vector<double> &) const;

# ifdef DEAL_II_TRILINOS_WITH_TPETRA
# if defined(HAVE_TPETRA_INST_DOUBLE)
template void
SparseMatrix::vmult_add(
dealii::LinearAlgebra::TpetraWrappers::Vector<double> &,
const dealii::LinearAlgebra::TpetraWrappers::Vector<double> &) const;
# endif

# if defined(HAVE_TPETRA_INST_FLOAT)
template void
SparseMatrix::vmult_add(
dealii::LinearAlgebra::TpetraWrappers::Vector<float> &,
const dealii::LinearAlgebra::TpetraWrappers::Vector<float> &) const;
# endif
# endif

template void
Expand All @@ -3133,15 +3145,19 @@ namespace TrilinosWrappers
const dealii::LinearAlgebra::distributed::Vector<double> &) const;

# ifdef DEAL_II_TRILINOS_WITH_TPETRA
# if defined(HAVE_TPETRA_INST_DOUBLE)
template void
SparseMatrix::Tvmult_add(
dealii::LinearAlgebra::TpetraWrappers::Vector<double> &,
const dealii::LinearAlgebra::TpetraWrappers::Vector<double> &) const;
# endif

# if defined(HAVE_TPETRA_INST_FLOAT)
template void
SparseMatrix::Tvmult_add(
dealii::LinearAlgebra::TpetraWrappers::Vector<float> &,
const dealii::LinearAlgebra::TpetraWrappers::Vector<float> &) const;
# endif
# endif

template void
Expand Down
8 changes: 8 additions & 0 deletions source/lac/trilinos_tpetra_vector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@ namespace LinearAlgebra
{
namespace TpetraWrappers
{
# ifdef HAVE_TPETRA_INST_FLOAT
template class Vector<float>;
# endif
# ifdef HAVE_TPETRA_INST_DOUBLE
template class Vector<double>;
# endif
# ifdef DEAL_II_WITH_COMPLEX_VALUES
# ifdef HAVE_TPETRA_INST_COMPLEX_FLOAT
template class Vector<std::complex<float>>;
# endif
# ifdef HAVE_TPETRA_INST_COMPLEX_DOUBLE
template class Vector<std::complex<double>>;
# endif
# endif
} // namespace TpetraWrappers
} // namespace LinearAlgebra
Expand Down
5 changes: 0 additions & 5 deletions tests/trilinos/tpetra_vector_01.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,6 @@ main(int argc, char **argv)
Utilities::MPI::MPI_InitFinalize mpi_init(argc, argv, 1);

test<double>();
test<float>();
#ifdef DEAL_II_WITH_COMPLEX_VALUES
test<std::complex<float>>();
test<std::complex<double>>();
#endif

deallog << "OK" << std::endl;

Expand Down
5 changes: 0 additions & 5 deletions tests/trilinos/tpetra_vector_02.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,6 @@ main(int argc, char **argv)
Utilities::MPI::MPI_InitFinalize mpi_init(argc, argv, 1);

test<double>();
test<float>();
#ifdef DEAL_II_WITH_COMPLEX_VALUES
test<std::complex<double>>();
test<std::complex<float>>();
#endif

deallog << "OK" << std::endl;

Expand Down
5 changes: 0 additions & 5 deletions tests/trilinos/tpetra_vector_03.cc
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,4 @@ main(int argc, char **argv)

MPILogInitAll log;
test<double>();
test<float>();
#ifdef DEAL_II_WITH_COMPLEX_VALUES
test<std::complex<double>>();
test<std::complex<float>>();
#endif
}