From b2542679cb528ab6ef892df0e16c3bb3162d41fc Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Sun, 4 Apr 2021 21:24:21 +0200 Subject: [PATCH] Performance improvement of MGTwoLevelTransfer --- .../mg_transfer_global_coarsening.templates.h | 71 ++++++++++++------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h b/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h index 139a6a303e..af7b5e691c 100644 --- a/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h +++ b/include/deal.II/multigrid/mg_transfer_global_coarsening.templates.h @@ -1213,7 +1213,7 @@ namespace internal } }; - // set up two mg-schesmes + // set up two mg-schemes // (0) no refinement -> identity // (1) h-refinement transfer.schemes.resize(2); @@ -2155,7 +2155,8 @@ MGTwoLevelTransfer>::prolongate( this->vec_coarse .update_ghost_values(); // note: make sure that ghost values are set - this->vec_fine = Number(0.); + if (schemes.size() > 0 && schemes.front().fine_element_is_continuous) + this->vec_fine = Number(0.); AlignedVector evaluation_data_fine; AlignedVector evaluation_data_coarse; @@ -2176,10 +2177,15 @@ MGTwoLevelTransfer>::prolongate( for (unsigned int cell = 0; cell < scheme.n_coarse_cells; ++cell) { - for (unsigned int i = 0; i < scheme.dofs_per_cell_fine; ++i) - this->vec_fine.local_element(indices_fine[i]) += - this->vec_coarse.local_element(indices_coarse[i]) * - (scheme.fine_element_is_continuous ? weights[i] : 1.0); + if (scheme.fine_element_is_continuous) + for (unsigned int i = 0; i < scheme.dofs_per_cell_fine; ++i) + this->vec_fine.local_element(indices_fine[i]) += + this->vec_coarse.local_element(indices_coarse[i]) * + weights[i]; + else + for (unsigned int i = 0; i < scheme.dofs_per_cell_fine; ++i) + dst.local_element(indices_fine[i]) = + this->vec_coarse.local_element(indices_coarse[i]); indices_fine += scheme.dofs_per_cell_fine; indices_coarse += scheme.dofs_per_cell_coarse; @@ -2252,10 +2258,13 @@ MGTwoLevelTransfer>::prolongate( for (unsigned int v = 0; v < n_lanes_filled; ++v) { - for (unsigned int i = 0; i < scheme.dofs_per_cell_fine; ++i) - this->vec_fine.local_element(indices[i]) += - evaluation_data_fine[i][v] * - (scheme.fine_element_is_continuous ? weights[i] : 1.0); + if (scheme.fine_element_is_continuous) + for (unsigned int i = 0; i < scheme.dofs_per_cell_fine; ++i) + this->vec_fine.local_element(indices[i]) += + evaluation_data_fine[i][v] * weights[i]; + else + for (unsigned int i = 0; i < scheme.dofs_per_cell_fine; ++i) + dst.local_element(indices[i]) = evaluation_data_fine[i][v]; indices += scheme.dofs_per_cell_fine; @@ -2270,9 +2279,10 @@ MGTwoLevelTransfer>::prolongate( // in do_restrict_add does not work if (schemes.size() > 0 && schemes.front().fine_element_is_continuous) - this->vec_fine.compress(VectorOperation::add); - - dst.copy_locally_owned_data_from(this->vec_fine); + { + this->vec_fine.compress(VectorOperation::add); + dst.copy_locally_owned_data_from(this->vec_fine); + } } @@ -2287,8 +2297,11 @@ MGTwoLevelTransfer>:: const unsigned int n_lanes = VectorizedArrayType::size(); - this->vec_fine.copy_locally_owned_data_from(src); - this->vec_fine.update_ghost_values(); + if (schemes.front().fine_element_is_continuous) + { + this->vec_fine.copy_locally_owned_data_from(src); + this->vec_fine.update_ghost_values(); + } this->vec_coarse.copy_locally_owned_data_from(dst); @@ -2330,12 +2343,17 @@ MGTwoLevelTransfer>:: for (unsigned int cell = 0; cell < scheme.n_coarse_cells; ++cell) { - for (unsigned int i = 0; i < scheme.dofs_per_cell_fine; ++i) - distribute_local_to_global( - indices_coarse[i], - this->vec_fine.local_element(indices_fine[i]) * - (scheme.fine_element_is_continuous ? weights[i] : 1.0), - this->vec_coarse); + if (scheme.fine_element_is_continuous) + for (unsigned int i = 0; i < scheme.dofs_per_cell_fine; ++i) + distribute_local_to_global( + indices_coarse[i], + this->vec_fine.local_element(indices_fine[i]) * weights[i], + this->vec_coarse); + else + for (unsigned int i = 0; i < scheme.dofs_per_cell_fine; ++i) + distribute_local_to_global(indices_coarse[i], + src.local_element(indices_fine[i]), + this->vec_coarse); indices_fine += scheme.dofs_per_cell_fine; indices_coarse += scheme.dofs_per_cell_coarse; @@ -2377,10 +2395,13 @@ MGTwoLevelTransfer>:: for (unsigned int v = 0; v < n_lanes_filled; ++v) { - for (unsigned int i = 0; i < scheme.dofs_per_cell_fine; ++i) - evaluation_data_fine[i][v] = - this->vec_fine.local_element(indices[i]) * - (scheme.fine_element_is_continuous ? weights[i] : 1.0); + if (scheme.fine_element_is_continuous) + for (unsigned int i = 0; i < scheme.dofs_per_cell_fine; ++i) + evaluation_data_fine[i][v] = + this->vec_fine.local_element(indices[i]) * weights[i]; + else + for (unsigned int i = 0; i < scheme.dofs_per_cell_fine; ++i) + evaluation_data_fine[i][v] = src.local_element(indices[i]); indices += scheme.dofs_per_cell_fine; -- 2.39.5