1 static char help[] = "Tests taking part of existing array to create a new vector.\n\n";
2
3 #include <petscvec.h>
4
main(int argc,char ** argv)5 int main(int argc, char **argv)
6 {
7 PetscMPIInt size;
8 PetscInt n = 10, i;
9 PetscScalar array[10];
10 Vec x;
11
12 PetscFunctionBeginUser;
13 PetscCall(PetscInitialize(&argc, &argv, NULL, help));
14 PetscCallMPI(MPI_Comm_size(PETSC_COMM_WORLD, &size));
15 PetscCheck(size == 1, PETSC_COMM_WORLD, PETSC_ERR_WRONG_MPI_SIZE, "This is a uniprocessor example only!");
16
17 /* create vector */
18 for (i = 0; i < n; i++) array[i] = i;
19 n = n - 1;
20
21 PetscCall(VecCreateSeqWithArray(PETSC_COMM_SELF, 1, n, array + 1, &x));
22 PetscCall(VecView(x, PETSC_VIEWER_STDOUT_SELF));
23 PetscCall(VecDestroy(&x));
24 PetscCall(PetscFinalize());
25 return 0;
26 }
27