]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make sure a conversion is safe. 15348/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Mon, 12 Jun 2023 16:57:12 +0000 (10:57 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Mon, 12 Jun 2023 18:54:56 +0000 (12:54 -0600)
source/lac/petsc_vector_base.cc

index a3280a8b247402b1b32d407e08861fd944641ca9..7b762d875afc1f0e8c3edd4f4365dbd48d47ca8e 100644 (file)
@@ -259,8 +259,20 @@ namespace PETScWrappers
         AssertThrow(ierr == 0, ExcPETScError(ierr));
         ierr = VecGetArray(tvector, &array);
         AssertThrow(ierr == 0, ExcPETScError(ierr));
+
+        // Store the indices we care about in the vector, so that we can then
+        // exchange this information between processes. It is unfortunate that
+        // we have to store integers in floating point numbers. Let's at least
+        // make sure we do that in a way that ensures that when we get these
+        // numbers back as integers later on, we get the same thing.
         for (PetscInt i = 0; i < end_index - ghost_start_index; i++)
-          array[i] = ghost_start_index + i;
+          {
+            Assert(static_cast<PetscInt>(static_cast<PetscScalar>(
+                     ghost_start_index + i)) == (ghost_start_index + i),
+                   ExcInternalError());
+            array[i] = ghost_start_index + i;
+          }
+
         ierr = VecRestoreArray(tvector, &array);
         AssertThrow(ierr == 0, ExcPETScError(ierr));
         ierr = VecGhostUpdateBegin(tvector, INSERT_VALUES, SCATTER_FORWARD);

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.