From: Martin Kronbichler Date: Fri, 27 Sep 2019 14:10:52 +0000 (+0200) Subject: Bypass vector copies if partitioners match X-Git-Tag: v9.2.0-rc1~1001^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=30a4b87d03ba0b36a87633cafbab19003d590b3c;p=dealii.git Bypass vector copies if partitioners match --- diff --git a/include/deal.II/matrix_free/cuda_matrix_free.templates.h b/include/deal.II/matrix_free/cuda_matrix_free.templates.h index cca2c7e758..ddadb0654b 100644 --- a/include/deal.II/matrix_free/cuda_matrix_free.templates.h +++ b/include/deal.II/matrix_free/cuda_matrix_free.templates.h @@ -1027,24 +1027,44 @@ namespace CUDAWrappers const LinearAlgebra::distributed::Vector &src, LinearAlgebra::distributed::Vector &dst) const { - // Create the ghosted source and the ghosted destination - LinearAlgebra::distributed::Vector ghosted_src( - partitioner); - LinearAlgebra::distributed::Vector ghosted_dst( - ghosted_src); - ghosted_src = src; - - // Execute the loop on the cells - for (unsigned int i = 0; i < n_colors; ++i) - internal::apply_kernel_shmem - <<>>(func, - get_data(i), - ghosted_src.get_values(), - ghosted_dst.get_values()); - - // Add the ghosted values - ghosted_dst.compress(VectorOperation::add); - dst = ghosted_dst; + // in case we have compatible partitioners, we can simply use the provided + // vectors + if (src.get_partitioner().get() == partitioner.get() && + dst.get_partitioner().get() == partitioner.get()) + { + src.update_ghost_values(); + + // Execute the loop on the cells + for (unsigned int i = 0; i < n_colors; ++i) + internal::apply_kernel_shmem + <<>>(func, + get_data(i), + src.get_values(), + dst.get_values()); + dst.compress(VectorOperation::add); + src.zero_out_ghosts(); + } + else + { + // Create the ghosted source and the ghosted destination + LinearAlgebra::distributed::Vector + ghosted_src(partitioner); + LinearAlgebra::distributed::Vector + ghosted_dst(ghosted_src); + ghosted_src = src; + + // Execute the loop on the cells + for (unsigned int i = 0; i < n_colors; ++i) + internal::apply_kernel_shmem + <<>>(func, + get_data(i), + ghosted_src.get_values(), + ghosted_dst.get_values()); + + // Add the ghosted values + ghosted_dst.compress(VectorOperation::add); + dst = ghosted_dst; + } }