From: David Wells Date: Sun, 11 Aug 2024 21:11:44 +0000 (-0600) Subject: PETScWrappers::MPI::Vector: add index conversion checks. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=430a59e0cec0d8a27dfda25cdaf9dfbbd69988bc;p=dealii.git PETScWrappers::MPI::Vector: add index conversion checks. --- diff --git a/source/lac/petsc_parallel_vector.cc b/source/lac/petsc_parallel_vector.cc index 06f20d348e..ff25f6cf9c 100644 --- a/source/lac/petsc_parallel_vector.cc +++ b/source/lac/petsc_parallel_vector.cc @@ -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(n), n); ghosted = true; ghost_indices = ghostnodes; - const std::vector ghostindices = ghostnodes.get_index_vector(); - - const PetscInt *ptr = - (ghostindices.size() > 0 ? - reinterpret_cast(ghostindices.data()) : - nullptr); + std::size_t i = 0; + std::vector petsc_ghost_indices(ghostnodes.n_elements()); + for (const auto &index : ghostnodes) + { + petsc_ghost_indices[i] = static_cast(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));