From: Daniel Arndt Date: Mon, 18 Feb 2019 13:59:28 +0000 (+0100) Subject: Generalize template specialization X-Git-Tag: v9.1.0-rc1~309^2~12 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=27dc7590f990ba94cded274218e89315869c5dbf;p=dealii.git Generalize template specialization --- diff --git a/include/deal.II/lac/vector_element_access.h b/include/deal.II/lac/vector_element_access.h index 236203e198..9e00b8de58 100644 --- a/include/deal.II/lac/vector_element_access.h +++ b/include/deal.II/lac/vector_element_access.h @@ -126,147 +126,96 @@ namespace internal # ifdef DEAL_II_TRILINOS_WITH_TPETRA - template <> - inline void - ElementAccess>::add( - const double value, - const types::global_dof_index i, - LinearAlgebra::TpetraWrappers::Vector &V) + template + struct ElementAccess> { - // Extract local indices in the vector. - Tpetra::Vector vector = - V.trilinos_vector(); - TrilinosWrappers::types::int_type trilinos_i = - vector.getMap()->getLocalElement( - static_cast(i)); - - vector.sync(); - auto vector_2d = vector.getLocalView(); - auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0); - // We're going to modify the data on host. - vector.modify(); - vector_1d(trilinos_i) += value; - vector.sync:: - device_type::memory_space>(); - } - - + public: + using VectorType = LinearAlgebra::TpetraWrappers::Vector; + static void + add(const typename VectorType::value_type value, + const types::global_dof_index i, + VectorType & V); - template <> - inline void - ElementAccess>::add( - const float value, - const types::global_dof_index i, - LinearAlgebra::TpetraWrappers::Vector &V) - { - // Extract local indices in the vector. - Tpetra::Vector vector = - V.trilinos_vector(); - TrilinosWrappers::types::int_type trilinos_i = - vector.getMap()->getLocalElement( - static_cast(i)); + static void + set(typename VectorType::value_type value, + const types::global_dof_index i, + VectorType & V); - vector.sync(); - auto vector_2d = vector.getLocalView(); - auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0); - // We're going to modify the data on host. - vector.modify(); - vector_1d(trilinos_i) += value; - vector.sync:: - device_type::memory_space>(); - } + static typename VectorType::value_type + get(const VectorType &V, const types::global_dof_index i); + }; - template <> + template inline void - ElementAccess>::set( - const double value, - const types::global_dof_index i, - LinearAlgebra::TpetraWrappers::Vector &V) + ElementAccess>::add( + const typename VectorType::value_type value, + const types::global_dof_index i, + LinearAlgebra::TpetraWrappers::Vector &V) { // Extract local indices in the vector. - Tpetra::Vector vector = + Tpetra::Vector vector = V.trilinos_vector(); TrilinosWrappers::types::int_type trilinos_i = vector.getMap()->getLocalElement( static_cast(i)); - vector.sync(); - auto vector_2d = vector.getLocalView(); + vector.template sync(); + auto vector_2d = vector.template getLocalView(); auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0); // We're going to modify the data on host. - vector.modify(); - vector_1d(trilinos_i) = value; - vector.sync:: - device_type::memory_space>(); + vector.template modify(); + vector_1d(trilinos_i) += value; + vector.template sync< + typename Tpetra::Vector:: + device_type::memory_space>(); } - template <> + template inline void - ElementAccess>::set( - const float value, - const types::global_dof_index i, - LinearAlgebra::TpetraWrappers::Vector &V) + ElementAccess>::set( + const typename VectorType::value_type value, + const types::global_dof_index i, + LinearAlgebra::TpetraWrappers::Vector &V) { // Extract local indices in the vector. - Tpetra::Vector vector = + Tpetra::Vector vector = V.trilinos_vector(); TrilinosWrappers::types::int_type trilinos_i = vector.getMap()->getLocalElement( static_cast(i)); - vector.sync(); - auto vector_2d = vector.getLocalView(); + vector.template sync(); + auto vector_2d = vector.template getLocalView(); auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0); // We're going to modify the data on host. - vector.modify(); + vector.template modify(); vector_1d(trilinos_i) = value; - vector.sync:: - device_type::memory_space>(); + vector.template sync< + typename Tpetra::Vector:: + device_type::memory_space>(); } - template <> - inline double - ElementAccess>::get( - const LinearAlgebra::TpetraWrappers::Vector &V, - const types::global_dof_index i) - { - // Extract local indices in the vector. - Tpetra::Vector vector = - V.trilinos_vector(); - TrilinosWrappers::types::int_type trilinos_i = - vector.getMap()->getLocalElement( - static_cast(i)); - - vector.sync(); - auto vector_2d = vector.getLocalView(); - auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0); - // We're going to modify the data on host. - return vector_1d(trilinos_i); - } - - - - template <> - inline float - ElementAccess>::get( - const LinearAlgebra::TpetraWrappers::Vector &V, - const types::global_dof_index i) + template + inline typename LinearAlgebra::TpetraWrappers::Vector::value_type + ElementAccess>::get( + const LinearAlgebra::TpetraWrappers::Vector &V, + const types::global_dof_index i) { // Extract local indices in the vector. - Tpetra::Vector vector = + Tpetra::Vector vector = V.trilinos_vector(); TrilinosWrappers::types::int_type trilinos_i = vector.getMap()->getLocalElement( static_cast(i)); - vector.sync(); - auto vector_2d = vector.getLocalView(); + vector.template sync(); + auto vector_2d = vector.template getLocalView(); auto vector_1d = Kokkos::subview(vector_2d, Kokkos::ALL(), 0); // We're going to modify the data on host. return vector_1d(trilinos_i);