# VecScatterCreate
Creates a vector scatter context. 
## Synopsis
```
#include "petscsf.h" 
PetscErrorCode VecScatterCreate(Vec x, IS ix, Vec y, IS iy, VecScatter *newsf)
```
Collective


## Input Parameters

- ***xin -*** a vector that defines the shape (parallel data layout of the vector)
of vectors from which we scatter
- ***yin -*** a vector that defines the shape (parallel data layout of the vector)
of vectors to which we scatter
- ***ix -*** the indices of xin to scatter (if NULL scatters all values)
- ***iy -*** the indices of yin to hold results (if NULL fills entire vector yin)



## Output Parameter

- ***newsf -*** location to store the new scatter context



## Options Database Keys

- ***-vecscatter_view         -*** Prints detail of communications
- ***-vecscatter_view ::ascii_info    -*** Print less details about communication
- ***-vecscatter_merge        -*** `VecScatterBegin()` handles all of the communication, `VecScatterEnd()` is a nop
eliminates the chance for overlap of computation and communication





## Notes
If both xin and yin are parallel, their communicator must be on the same
set of processes, but their process order can be different.
In calls to the scatter options you can use different vectors than the xin and
yin you used above; BUT they must have the same parallel data layout, for example,
they could be obtained from `VecDuplicate()`.
A VecScatter context CANNOT be used in two or more simultaneous scatters;
that is you cannot call a second `VecScatterBegin()` with the same scatter
context until the `VecScatterEnd()` has been called on the first `VecScatterBegin()`.
In this case a separate `VecScatter` is needed for each concurrent scatter.

Both ix and iy cannot be NULL at the same time.

Use `VecScatterCreateToAll()` to create a vecscatter that copies an MPI vector to sequential vectors on all MPI ranks.
Use `VecScatterCreateToZero()` to create a vecscatter that copies an MPI vector to a sequential vector on MPI rank 0.
These special vecscatters have better performance than general ones.


## See Also
 [](sec_scatter), `VecScatter`, `VecScatterDestroy()`, `VecScatterCreateToAll()`, `VecScatterCreateToZero()`, `PetscSFCreate()`

## Level
intermediate

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

## Examples
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/utils/tagger/tutorials/ex1.c.html">src/vec/vec/utils/tagger/tutorials/ex1.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/vec/vec/tutorials/ex44.c.html">src/vec/vec/tutorials/ex44.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex14.c.html">src/dm/tutorials/ex14.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex22.c.html">src/dm/tutorials/ex22.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/dm/tutorials/ex6.c.html">src/dm/tutorials/ex6.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex49.c.html">src/ksp/ksp/tutorials/ex49.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/ksp/ksp/tutorials/ex73.c.html">src/ksp/ksp/tutorials/ex73.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/tao/pde_constrained/tutorials/elliptic.c.html">src/tao/pde_constrained/tutorials/elliptic.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/tao/pde_constrained/tutorials/hyperbolic.c.html">src/tao/pde_constrained/tutorials/hyperbolic.c.html</A><BR>
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/src/tao/pde_constrained/tutorials/parabolic.c.html">src/tao/pde_constrained/tutorials/parabolic.c.html</A><BR>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/src/vec/is/sf/interface/vscat.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)  
