From: Qingyuan Shi Date: Thu, 1 Aug 2024 15:37:37 +0000 (+0800) Subject: fix pointer traversal range of PETSc vectors on each process X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e13d1822126bd9a68288834af494cacace53d30c;p=dealii.git fix pointer traversal range of PETSc vectors on each process --- diff --git a/source/lac/petsc_vector_base.cc b/source/lac/petsc_vector_base.cc index 2b46418dc1..01dc56bdda 100644 --- a/source/lac/petsc_vector_base.cc +++ b/source/lac/petsc_vector_base.cc @@ -636,7 +636,7 @@ namespace PETScWrappers // allowing pipelined commands to be // executed in parallel const PetscScalar *ptr = start_ptr; - const PetscScalar *eptr = ptr + (size() / 4) * 4; + const PetscScalar *eptr = ptr + (locally_owned_size() / 4) * 4; while (ptr != eptr) { sum0 += *ptr++; @@ -645,10 +645,12 @@ namespace PETScWrappers sum3 += *ptr++; } // add up remaining elements - while (ptr != start_ptr + size()) + while (ptr != start_ptr + locally_owned_size()) sum0 += *ptr++; - mean = (sum0 + sum1 + sum2 + sum3) / static_cast(size()); + mean = + Utilities::MPI::sum(sum0 + sum1 + sum2 + sum3, get_mpi_communicator()) / + static_cast(size()); } // restore the representation of the @@ -703,7 +705,7 @@ namespace PETScWrappers // allowing pipelined commands to be // executed in parallel const PetscScalar *ptr = start_ptr; - const PetscScalar *eptr = ptr + (size() / 4) * 4; + const PetscScalar *eptr = ptr + (locally_owned_size() / 4) * 4; while (ptr != eptr) { sum0 += std::pow(numbers::NumberTraits::abs(*ptr++), p); @@ -712,10 +714,12 @@ namespace PETScWrappers sum3 += std::pow(numbers::NumberTraits::abs(*ptr++), p); } // add up remaining elements - while (ptr != start_ptr + size()) + while (ptr != start_ptr + locally_owned_size()) sum0 += std::pow(numbers::NumberTraits::abs(*ptr++), p); - norm = std::pow(sum0 + sum1 + sum2 + sum3, 1. / p); + norm = std::pow(Utilities::MPI::sum(sum0 + sum1 + sum2 + sum3, + get_mpi_communicator()), + 1. / p); } // restore the representation of the