`VecCreateGhostWithArray` ownership layout vs application indices after migrate
Dear all, I am using "VecCreateGhostWithArray" to wrap particle fields (positions, densities, etc.) stored in a “DMSwarm" structure. On each rank the local array is packed as [owned particles | ghost particles]. My understanding from the implementation in pbvec.c is: 1. “PetscSplitOwnership" + "VecSetSizes(n, N)" assigns each rank a contiguous ownership range [rstart, rstart+n). 2. Local owned entry "I" therefore corresponds to global index "rstart + I". 3. The ghosts[] array in “ VecCreateGhostWithArray" must contain those PETSc global vector indices, because “VecGhostUpdate" scatters from the global vector into the local ghost padding. Is that correct? If so, after rebalancing particles with “DMSwarmMigrate", the application “AO" numbering attached to each particle is no longer the same as the contiguous ownership of a newly created ghosted Vec. In that case, should one always renumber the owned particle ids to "rstart + I" (and let ghosts inherit those ids) before calling “VecCreateGhostWithArray"? Thanks, Miguel Miguel Molinos Escuela de Ingenieros de Caminos, Canales y Puertos Dep. Mecánica Medios Continuos y Teoría de Estructuras Prof. Aranguren, 3 - Ciudad Universitaria. Planta 9. 28040, Madrid
On Fri, Jul 17, 2026 at 8:37 AM Miguel Molinos <[email protected]> wrote:
Dear all,
I am using "VecCreateGhostWithArray" to wrap particle fields (positions, densities, etc.) stored in a “DMSwarm" structure. On each rank the local array is packed as [owned particles | ghost particles].
My understanding from the implementation in pbvec.c is:
1. “PetscSplitOwnership" + "VecSetSizes(n, N)" assigns each rank a contiguous ownership range [rstart, rstart+n). 2. Local owned entry "I" therefore corresponds to global index "rstart + I". 3. The ghosts[] array in “ VecCreateGhostWithArray" must contain those PETSc global vector indices, because “VecGhostUpdate" scatters from the global vector into the local ghost padding.
Is that correct?
Yes.
If so, after rebalancing particles with “DMSwarmMigrate", the application “AO" numbering attached to each particle is no longer the same as the contiguous ownership of a newly created ghosted Vec. In that case, should one always renumber the owned particle ids to "rstart + I" (and let ghosts inherit those ids) before calling “VecCreateGhostWithArray"?
Ah, yes this is true. We had never used them in this way. A particle keeps its "id" field throughout its life, so maybe it would make sense to have a "local id" that changed after Migrate(). Thanks, Matt
Thanks, Miguel
Miguel Molinos
Escuela de Ingenieros de Caminos, Canales y Puertos Dep. Mecánica Medios Continuos y Teoría de Estructuras
Prof. Aranguren, 3 - Ciudad Universitaria. Planta 9. 28040, Madrid
-- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCf... <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfs... >
Thank you Matt, your answer helps a lot! Miguel
On 17 Jul 2026, at 14:41, Matthew Knepley <[email protected]> wrote:
On Fri, Jul 17, 2026 at 8:37 AM Miguel Molinos <[email protected] <mailto:[email protected]>> wrote:
Dear all,
I am using "VecCreateGhostWithArray" to wrap particle fields (positions, densities, etc.) stored in a “DMSwarm" structure. On each rank the local array is packed as [owned particles | ghost particles].
My understanding from the implementation in pbvec.c is:
1. “PetscSplitOwnership" + "VecSetSizes(n, N)" assigns each rank a contiguous ownership range [rstart, rstart+n). 2. Local owned entry "I" therefore corresponds to global index "rstart + I". 3. The ghosts[] array in “ VecCreateGhostWithArray" must contain those PETSc global vector indices, because “VecGhostUpdate" scatters from the global vector into the local ghost padding.
Is that correct?
Yes.
If so, after rebalancing particles with “DMSwarmMigrate", the application “AO" numbering attached to each particle is no longer the same as the contiguous ownership of a newly created ghosted Vec. In that case, should one always renumber the owned particle ids to "rstart + I" (and let ghosts inherit those ids) before calling “VecCreateGhostWithArray"?
Ah, yes this is true. We had never used them in this way. A particle keeps its "id" field throughout its life, so maybe it would make sense to have a "local id" that changed after Migrate().
Thanks,
Matt
Thanks, Miguel
Miguel Molinos
Escuela de Ingenieros de Caminos, Canales y Puertos Dep. Mecánica Medios Continuos y Teoría de Estructuras
Prof. Aranguren, 3 - Ciudad Universitaria. Planta 9. 28040, Madrid
-- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener
https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCf... <https://urldefense.com/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!D9dNQ... >
participants (2)
-
Matthew Knepley -
Miguel Molinos