Actual source code: vecs.c
1: #include <petscvec.h>
3: /*@
4: VecsDestroy - Destroys a `Vecs` collection of vectors
6: Collective
8: Input Parameter:
9: . x - the `Vecs` object to destroy
11: Level: advanced
13: .seealso: `Vecs`, `VecsCreateSeq()`, `VecsCreateSeqWithArray()`, `VecsDuplicate()`
14: @*/
15: PetscErrorCode VecsDestroy(Vecs x)
16: {
17: PetscFunctionBegin;
18: PetscCall(VecDestroy(&(x)->v));
19: PetscCall(PetscFree(x));
20: PetscFunctionReturn(PETSC_SUCCESS);
21: }
23: /*@
24: VecsCreateSeq - Creates a `Vecs` object holding `p` sequential `Vec`s of length `m`, all stored contiguously in a single underlying `Vec`
26: Collective
28: Input Parameters:
29: + comm - the MPI communicator (typically `PETSC_COMM_SELF`)
30: . p - the number of vectors
31: - m - the length of each vector
33: Output Parameter:
34: . x - the newly created `Vecs`
36: Level: advanced
38: .seealso: `Vecs`, `VecsCreateSeqWithArray()`, `VecsDuplicate()`, `VecsDestroy()`, `VecCreateSeq()`
39: @*/
40: PetscErrorCode VecsCreateSeq(MPI_Comm comm, PetscInt p, PetscInt m, Vecs *x)
41: {
42: PetscFunctionBegin;
43: PetscCall(PetscNew(x));
44: PetscCall(VecCreateSeq(comm, p * m, &(*x)->v));
45: (*x)->n = m;
46: PetscFunctionReturn(PETSC_SUCCESS);
47: }
49: /*@
50: VecsCreateSeqWithArray - Creates a `Vecs` object holding `p` sequential `Vec`s of length `m` that use a user-provided contiguous array as storage
52: Collective
54: Input Parameters:
55: + comm - the MPI communicator (typically `PETSC_COMM_SELF`)
56: . p - the number of vectors
57: . m - the length of each vector
58: - a - the array of length `p*m` used as storage for the vectors
60: Output Parameter:
61: . x - the newly created `Vecs`
63: Level: advanced
65: .seealso: `Vecs`, `VecsCreateSeq()`, `VecsDuplicate()`, `VecsDestroy()`, `VecCreateSeqWithArray()`
66: @*/
67: PetscErrorCode VecsCreateSeqWithArray(MPI_Comm comm, PetscInt p, PetscInt m, PetscScalar *a, Vecs *x)
68: {
69: PetscFunctionBegin;
70: PetscCall(PetscNew(x));
71: PetscCall(VecCreateSeqWithArray(comm, 1, p * m, a, &(*x)->v));
72: (*x)->n = m;
73: PetscFunctionReturn(PETSC_SUCCESS);
74: }
76: /*@
77: VecsDuplicate - Creates a new `Vecs` with the same size and layout as an existing `Vecs`, but does not copy the values
79: Collective
81: Input Parameter:
82: . x - the existing `Vecs`
84: Output Parameter:
85: . y - the newly created `Vecs`
87: Level: advanced
89: .seealso: `Vecs`, `VecsCreateSeq()`, `VecsCreateSeqWithArray()`, `VecsDestroy()`, `VecDuplicate()`
90: @*/
91: PetscErrorCode VecsDuplicate(Vecs x, Vecs *y)
92: {
93: PetscFunctionBegin;
94: PetscCall(PetscNew(y));
95: PetscCall(VecDuplicate(x->v, &(*y)->v));
96: (*y)->n = x->n;
97: PetscFunctionReturn(PETSC_SUCCESS);
98: }