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

Avoid using two temporary vectors when not necessary. #16454

Merged
merged 1 commit into from
Jan 11, 2024
Merged
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
32 changes: 25 additions & 7 deletions include/deal.II/numerics/data_out_dof_data.templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -803,15 +803,33 @@ namespace internal
const VectorType &src,
LinearAlgebra::distributed::Vector<Number> &dst)
{
LinearAlgebra::ReadWriteVector<typename VectorType::value_type> 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<typename VectorType::value_type, Number>)
{
LinearAlgebra::ReadWriteVector<typename VectorType::value_type>
temp;
temp.reinit(src.locally_owned_elements());
temp.import_elements(src, VectorOperation::insert);

LinearAlgebra::ReadWriteVector<Number> 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<typename VectorType::value_type>
temp;
temp.reinit(src.locally_owned_elements());
temp.import_elements(src, VectorOperation::insert);

dst.import_elements(temp2, VectorOperation::insert);
LinearAlgebra::ReadWriteVector<Number> temp2;
temp2.reinit(temp, true);
temp2 = temp;

dst.import_elements(temp2, VectorOperation::insert);
}
}

#ifdef DEAL_II_WITH_TRILINOS
Expand Down