# DMGetNeighbors
Gets an array containing the MPI ranks of all the processes neighbors 
## Synopsis
```
#include "petscdm.h"          
#include "petscdmlabel.h"     
#include "petscds.h"     
PetscErrorCode DMGetNeighbors(DM dm, PetscInt *nranks, const PetscMPIInt *ranks[])
```
Not Collective


## Input Parameter

- ***dm    -*** The `DM`



## Output Parameters

- ***nranks -*** the number of neighbours
- ***ranks -*** the neighbors ranks



## Note
Do not free the array, it is freed when the `DM` is destroyed.



.seealso: `DMDAGetNeighbors()`, `PetscSFGetRootRanks()`

## Level
beginner

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/interface/dm.c.html#DMGetNeighbors">src/dm/interface/dm.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/swarm_ex3.c.html">src/dm/tutorials/swarm_ex3.c.html</A><BR>

## Implementations

<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/da/dacreate.c.html#DMGetNeighbors_DA">DMGetNeighbors_DA in src/dm/impls/da/dacreate.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/plex/plexcreate.c.html#DMGetNeighbors_Plex">DMGetNeighbors_Plex in src/dm/impls/plex/plexcreate.c</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/impls/stag/stag.c.html#DMGetNeighbors_Stag">DMGetNeighbors_Stag in src/dm/impls/stag/stag.c</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/dm/interface/dm.c)


[Index of all DM routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
