From 4e27e9bf747d1009323731cf51b058eb8a641425 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Mon, 12 Jun 2023 10:57:12 -0600 Subject: [PATCH] Make sure a conversion is safe. --- source/lac/petsc_vector_base.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source/lac/petsc_vector_base.cc b/source/lac/petsc_vector_base.cc index a3280a8b24..7b762d875a 100644 --- a/source/lac/petsc_vector_base.cc +++ b/source/lac/petsc_vector_base.cc @@ -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(static_cast( + 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); -- 2.39.5