]> https://gitweb.dealii.org/ - dealii.git/commitdiff
fix pointer traversal range of PETSc vectors on each process
authorQingyuan Shi <shiqy21@mails.tsinghua.edu.cn>
Thu, 1 Aug 2024 15:37:37 +0000 (23:37 +0800)
committerQingyuan Shi <shiqy21@mails.tsinghua.edu.cn>
Thu, 1 Aug 2024 18:07:20 +0000 (02:07 +0800)
source/lac/petsc_vector_base.cc

index 2b46418dc140042de301b751680aa7b9a36df7f9..01dc56bdda86dff660b7d81a17ca4595c2816159 100644 (file)
@@ -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<PetscReal>(size());
+      mean =
+        Utilities::MPI::sum(sum0 + sum1 + sum2 + sum3, get_mpi_communicator()) /
+        static_cast<PetscReal>(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<value_type>::abs(*ptr++), p);
@@ -712,10 +714,12 @@ namespace PETScWrappers
           sum3 += std::pow(numbers::NumberTraits<value_type>::abs(*ptr++), p);
         }
       // add up remaining elements
-      while (ptr != start_ptr + size())
+      while (ptr != start_ptr + locally_owned_size())
         sum0 += std::pow(numbers::NumberTraits<value_type>::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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.