xref: /petsc/src/vec/vec/impls/mpi/vmpicr.c (revision c74fe4ad55794f2229f685f3bf7ba9fdc9763619)
1 /*
2    This file contains routines for Parallel vector operations.
3  */
4 
5 #include <petscvec.h> /*I  "petscvec.h"   I*/
6 
7 /*@
8   VecCreateMPI - Creates a parallel vector.
9 
10   Collective
11 
12   Input Parameters:
13 + comm - the MPI communicator to use
14 . n    - local vector length (or `PETSC_DECIDE` to have calculated if `N` is given)
15 - N    - global vector length (or `PETSC_DETERMINE` to have calculated if `n` is given)
16 
17   Output Parameter:
18 . v - the vector
19 
20   Level: intermediate
21 
22   Notes:
23   It is recommended to use `VecCreateFromOptions()` instead of this routine
24 
25   Use `VecDuplicate()` or `VecDuplicateVecs()` to form additional vectors of the
26   same type as an existing vector.
27 
28   If `n` is not `PETSC_DECIDE`, then the value determines the `PetscLayout` of the vector and the ranges returned by
29   `VecGetOwnershipRange()` and `VecGetOwnershipRanges()`
30 
31 .seealso: [](ch_vectors), `Vec`, `VecType`, `VecCreateSeq()`, `VecCreate()`, `VecDuplicate()`, `VecDuplicateVecs()`, `VecCreateGhost()`,
32           `VecCreateMPIWithArray()`, `VecCreateGhostWithArray()`, `VecMPISetGhost()`, `PetscLayout`,
33           `VecGetOwnershipRange()`, `VecGetOwnershipRanges()`
34 @*/
VecCreateMPI(MPI_Comm comm,PetscInt n,PetscInt N,Vec * v)35 PetscErrorCode VecCreateMPI(MPI_Comm comm, PetscInt n, PetscInt N, Vec *v)
36 {
37   PetscFunctionBegin;
38   PetscCall(VecCreate(comm, v));
39   PetscCall(VecSetSizes(*v, n, N));
40   PetscCall(VecSetType(*v, VECMPI));
41   PetscFunctionReturn(PETSC_SUCCESS);
42 }
43