From: Wolfgang Bangerth Date: Wed, 10 Jan 2024 22:21:28 +0000 (-0700) Subject: Avoid using two temporary vectors when not necessary. X-Git-Tag: relicensing~179^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F16454%2Fhead;p=dealii.git Avoid using two temporary vectors when not necessary. --- diff --git a/include/deal.II/numerics/data_out_dof_data.templates.h b/include/deal.II/numerics/data_out_dof_data.templates.h index 32ce2c2212..92e019b511 100644 --- a/include/deal.II/numerics/data_out_dof_data.templates.h +++ b/include/deal.II/numerics/data_out_dof_data.templates.h @@ -803,15 +803,33 @@ namespace internal const VectorType &src, LinearAlgebra::distributed::Vector &dst) { - LinearAlgebra::ReadWriteVector temp; - temp.reinit(src.locally_owned_elements()); - temp.import_elements(src, VectorOperation::insert); + // If source and destination vector have the same underlying scalar, + // we can directly import elements by using only one temporary vector: + if constexpr (std::is_same_v) + { + LinearAlgebra::ReadWriteVector + temp; + temp.reinit(src.locally_owned_elements()); + temp.import_elements(src, VectorOperation::insert); - LinearAlgebra::ReadWriteVector temp2; - temp2.reinit(temp, true); - temp2 = temp; + dst.import_elements(temp, VectorOperation::insert); + } + else + // The source and destination vector have different scalar types. We + // need to split the parallel import and local copy operations into + // two phases + { + LinearAlgebra::ReadWriteVector + temp; + temp.reinit(src.locally_owned_elements()); + temp.import_elements(src, VectorOperation::insert); - dst.import_elements(temp2, VectorOperation::insert); + LinearAlgebra::ReadWriteVector temp2; + temp2.reinit(temp, true); + temp2 = temp; + + dst.import_elements(temp2, VectorOperation::insert); + } } #ifdef DEAL_II_WITH_TRILINOS