From: Martin Kronbichler Date: Fri, 8 Nov 2024 11:29:02 +0000 (+0100) Subject: Preconditioners: Make access to vector pointers more uniform X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=643e4a8bbb585f876d34a04bdddd79ab28448c3f;p=dealii.git Preconditioners: Make access to vector pointers more uniform --- diff --git a/include/deal.II/lac/precondition.h b/include/deal.II/lac/precondition.h index 6682077948..5555defa38 100644 --- a/include/deal.II/lac/precondition.h +++ b/include/deal.II/lac/precondition.h @@ -1291,20 +1291,19 @@ namespace internal const bool transposed) { (void)transposed; - using Number = typename VectorType::value_type; + using Number = typename VectorType::value_type; + Number *dst_ptr = dst.begin(); + const Number *src_ptr = src.begin(); if (i == 0) { - Number *dst_ptr = dst.begin(); - const Number *src_ptr = src.begin(); - preconditioner.vmult( dst, src, [&](const unsigned int start_range, const unsigned int end_range) { // zero 'dst' before running the vmult operation if (end_range > start_range) - std::memset(dst.begin() + start_range, + std::memset(dst_ptr + start_range, 0, sizeof(Number) * (end_range - start_range)); }, @@ -1312,9 +1311,6 @@ namespace internal if (relaxation == 1.0) return; // nothing to do - const auto src_ptr = src.begin(); - const auto dst_ptr = dst.begin(); - DEAL_II_OPENMP_SIMD_PRAGMA for (std::size_t i = start_range; i < end_range; ++i) dst_ptr[i] *= relaxation; @@ -1332,7 +1328,6 @@ namespace internal dst, tmp, [&](const unsigned int start_range, const unsigned int end_range) { - const auto src_ptr = src.begin(); const auto tmp_ptr = tmp.begin(); if (relaxation == 1.0) @@ -1383,18 +1378,18 @@ namespace internal (void)transposed; using Number = typename VectorType::value_type; + Number *dst_ptr = dst.begin(); + const Number *src_ptr = src.begin(); + if (i == 0) { - Number *dst_ptr = dst.begin(); - const Number *src_ptr = src.begin(); - preconditioner.vmult( dst, src, [&](const unsigned int start_range, const unsigned int end_range) { // zero 'dst' before running the vmult operation if (end_range > start_range) - std::memset(dst.begin() + start_range, + std::memset(dst_ptr + start_range, 0, sizeof(Number) * (end_range - start_range)); }, @@ -1402,9 +1397,6 @@ namespace internal if (relaxation == 1.0) return; // nothing to do - const auto src_ptr = src.begin(); - const auto dst_ptr = dst.begin(); - DEAL_II_OPENMP_SIMD_PRAGMA for (std::size_t i = start_range; i < end_range; ++i) dst_ptr[i] *= relaxation; @@ -1413,6 +1405,7 @@ namespace internal else { tmp.reinit(src, true); + const auto tmp_ptr = tmp.begin(); Assert(transposed == false, ExcNotImplemented()); @@ -1423,14 +1416,11 @@ namespace internal // zero 'tmp' before running the vmult // operation if (end_range > start_range) - std::memset(tmp.begin() + start_range, + std::memset(tmp_ptr + start_range, 0, sizeof(Number) * (end_range - start_range)); }, [&](const unsigned int start_range, const unsigned int end_range) { - const auto src_ptr = src.begin(); - const auto tmp_ptr = tmp.begin(); - if (relaxation == 1.0) { DEAL_II_OPENMP_SIMD_PRAGMA @@ -1500,16 +1490,16 @@ namespace internal { tmp.reinit(src, true); - Number *dst_ptr = dst.begin(); - const Number *src_ptr = src.begin(); - const Number *tmp_ptr = tmp.begin(); - const Number *diag_ptr = preconditioner.get_vector().begin(); - if (transposed) Tvmult(A, tmp, dst); else A.vmult(tmp, dst); + Number *dst_ptr = dst.begin(); + const Number *src_ptr = src.begin(); + const Number *tmp_ptr = tmp.begin(); + const Number *diag_ptr = preconditioner.get_vector().begin(); + if (relaxation == 1.0) { DEAL_II_OPENMP_SIMD_PRAGMA @@ -3157,27 +3147,25 @@ namespace internal if (iteration_index == 0) { - const auto solution_old_ptr = solution_old.begin(); - // compute t = P^{-1} * (b) preconditioner.vmult(solution_old, rhs); // compute x^{n+1} = f_2 * t + const auto solution_old_ptr = solution_old.begin(); DEAL_II_OPENMP_SIMD_PRAGMA for (unsigned int i = 0; i < solution_old.locally_owned_size(); ++i) solution_old_ptr[i] = solution_old_ptr[i] * factor2; } else if (iteration_index == 1) { - const auto solution_ptr = solution.begin(); - const auto solution_old_ptr = solution_old.begin(); - // compute t = P^{-1} * (b-A*x^{n}) temp_vector1.sadd(-1.0, 1.0, rhs); preconditioner.vmult(solution_old, temp_vector1); // compute x^{n+1} = x^{n} + f_1 * x^{n} + f_2 * t + const auto solution_ptr = solution.begin(); + const auto solution_old_ptr = solution_old.begin(); DEAL_II_OPENMP_SIMD_PRAGMA for (unsigned int i = 0; i < solution_old.locally_owned_size(); ++i) solution_old_ptr[i] = @@ -3185,16 +3173,15 @@ namespace internal } else { - const auto solution_ptr = solution.begin(); - const auto solution_old_ptr = solution_old.begin(); - const auto temp_vector2_ptr = temp_vector2.begin(); - // compute t = P^{-1} * (b-A*x^{n}) temp_vector1.sadd(-1.0, 1.0, rhs); preconditioner.vmult(temp_vector2, temp_vector1); // compute x^{n+1} = x^{n} + f_1 * (x^{n}-x^{n-1}) + f_2 * t + const auto solution_ptr = solution.begin(); + const auto solution_old_ptr = solution_old.begin(); + const auto temp_vector2_ptr = temp_vector2.begin(); DEAL_II_OPENMP_SIMD_PRAGMA for (unsigned int i = 0; i < solution_old.locally_owned_size(); ++i) solution_old_ptr[i] = factor1_plus_1 * solution_ptr[i] - @@ -3245,7 +3232,7 @@ namespace internal rhs, [&](const auto start_range, const auto end_range) { if (end_range > start_range) - std::memset(solution.begin() + start_range, + std::memset(solution_ptr + start_range, 0, sizeof(Number) * (end_range - start_range)); }, @@ -3262,7 +3249,7 @@ namespace internal temp_vector1, [&](const auto begin, const auto end) { if (end > begin) - std::memset(temp_vector2.begin() + begin, + std::memset(temp_vector2_ptr + begin, 0, sizeof(Number) * (end - begin));