]> https://gitweb.dealii.org/ - dealii.git/commitdiff
PETScWrappers::MPI::Vector: add index conversion checks.
authorDavid Wells <drwells@email.unc.edu>
Sun, 11 Aug 2024 21:11:44 +0000 (15:11 -0600)
committerDavid Wells <drwells@email.unc.edu>
Mon, 12 Aug 2024 02:42:37 +0000 (20:42 -0600)
source/lac/petsc_parallel_vector.cc

index 06f20d348e5e074f18ae698b258a7592635d0bd8..ff25f6cf9cea3388d55a1872f88c81b3aa8d42b5 100644 (file)
@@ -293,21 +293,25 @@ namespace PETScWrappers
     {
       (void)n;
       AssertIndexRange(locally_owned_size, n + 1);
+      // If the size of the index set can be converted to a PetscInt then every
+      // index can also be converted
+      AssertThrowIntegerConversion(static_cast<PetscInt>(n), n);
       ghosted       = true;
       ghost_indices = ghostnodes;
 
-      const std::vector<size_type> ghostindices = ghostnodes.get_index_vector();
-
-      const PetscInt *ptr =
-        (ghostindices.size() > 0 ?
-           reinterpret_cast<const PetscInt *>(ghostindices.data()) :
-           nullptr);
+      std::size_t           i = 0;
+      std::vector<PetscInt> petsc_ghost_indices(ghostnodes.n_elements());
+      for (const auto &index : ghostnodes)
+        {
+          petsc_ghost_indices[i] = static_cast<PetscInt>(index);
+          ++i;
+        }
 
       PetscErrorCode ierr = VecCreateGhost(communicator,
                                            locally_owned_size,
                                            PETSC_DETERMINE,
-                                           ghostindices.size(),
-                                           ptr,
+                                           petsc_ghost_indices.size(),
+                                           petsc_ghost_indices.data(),
                                            &vector);
       AssertThrow(ierr == 0, ExcPETScError(ierr));
 

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.