]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Only instantiate Tpetra wrapper types for number types Tpetra explicitly instantiated
authorDaniel Arndt <arndtd@ornl.gov>
Fri, 24 Feb 2023 15:51:29 +0000 (10:51 -0500)
committerDaniel Arndt <arndtd@ornl.gov>
Fri, 24 Feb 2023 15:51:29 +0000 (10:51 -0500)
cmake/configure/configure_20_trilinos.cmake
include/deal.II/lac/read_write_vector.h
include/deal.II/lac/read_write_vector.templates.h
include/deal.II/lac/trilinos_tpetra_vector.h
source/lac/affine_constraints.cc
source/lac/read_write_vector.cc
source/lac/trilinos_sparse_matrix.cc
source/lac/trilinos_tpetra_vector.cc

index b13a0a72243c94e3ffb7b09b25b74d72cae46473..a91ca1bf3c8e5d3a3e668c8711ed6950ebb14cd3 100644 (file)
@@ -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<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()
 
index 62358e09177bb6e0cf8d92aaa59faf4ae2b5b583..1e410eaa225382c548c58d12424bae32f0e31465 100644 (file)
@@ -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>
@@ -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,
index 66e4f5a276e4b77ff52d1dd38a91a3e543e3c3b0..b4feeac4178f43c8fe61e468e071024808b4c3a2 100644 (file)
@@ -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,
@@ -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,
index 6cf689122b56cfb923a54559c1a11d11841385f5..3fa6d81fdf78fe1611db971c875b159bf337ae6a 100644 (file)
 
 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
index 41a823a53668dd166445a020daf907a10a255946..021a4df960b1128a27721f40a7a303e65e580696 100644 (file)
@@ -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<
index 23ced9c5bf7cfd126c0d147f822e08adb65505a7..453ddd3da9f5b60e2f92fffab6681792f22a6aea 100644 (file)
@@ -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
 
index d0d3c26374e05b25e41898ad9383e249836febe7..7c5992f1e425f15c5f66f1470262361d6fd9c5e3 100644 (file)
@@ -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
@@ -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
@@ -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
@@ -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
index 73a7621b95c2ce9095a897a2e68e410266857e56..91e07281789ac9759184480dd6b7b6491f346bb9 100644 (file)
@@ -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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.