# PetscSFSetGraph
Set a parallel star forest 
## Synopsis
```
#include "petscsf.h" 
PetscErrorCode PetscSFSetGraph(PetscSF sf, PetscInt nroots, PetscInt nleaves, PetscInt *ilocal, PetscCopyMode localmode, PetscSFNode *iremote, PetscCopyMode remotemode)
```
Collective


## Input Parameters

- ***sf -*** star forest
- ***nroots -*** number of root vertices on the current process (these are possible targets for other process to attach leaves)
- ***nleaves -*** number of leaf vertices on the current process, each of these references a root on any process
- ***ilocal -*** locations of leaves in leafdata buffers, pass NULL for contiguous storage (locations must be >= 0, enforced
during setup in debug mode)
- ***localmode -*** copy mode for ilocal
- ***iremote -*** remote locations of root vertices for each leaf on the current process (locations must be >= 0, enforced
during setup in debug mode)
- ***remotemode -*** copy mode for iremote





## Notes
Leaf indices in ilocal must be unique, otherwise an error occurs.

Input arrays ilocal and iremote follow the PetscCopyMode semantics.
In particular, if localmode/remotemode is `PETSC_OWN_POINTER` or `PETSC_USE_POINTER`,
PETSc might modify the respective array;
if `PETSC_USE_POINTER`, the user must delete the array after PetscSFDestroy().
Only if `PETSC_COPY_VALUES` is used, the respective array is guaranteed to stay intact and a const array can be passed (but a cast to non-const is needed).


## Fortran Note
In Fortran you must use PETSC_COPY_VALUES for localmode and remotemode.


## Developer Note
We sort leaves to check for duplicates and contiguousness and to find minleaf/maxleaf.
This also allows to compare leaf sets of two SFs easily.


## See Also
 `PetscSFType`, `PetscSFCreate()`, `PetscSFView()`, `PetscSFGetGraph()`

## Level
intermediate

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/is/sf/interface/sf.c.html#PetscSFSetGraph">src/vec/is/sf/interface/sf.c</A>

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/is/sf/tutorials/ex1.c.html">src/vec/is/sf/tutorials/ex1.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/is/sf/tutorials/ex1f.F90.html">src/vec/is/sf/tutorials/ex1f.F90.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/is/sf/tutorials/ex2.c.html">src/vec/is/sf/tutorials/ex2.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/is/sf/tutorials/ex3.c.html">src/vec/is/sf/tutorials/ex3.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/swarm_ex3.c.html">src/dm/tutorials/swarm_ex3.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ts/tutorials/ex11_sa.c.html">src/ts/tutorials/ex11_sa.c.html</A><BR>


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


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