xref: /petsc/src/vec/vec/tests/ex40.c (revision b122ec5aa1bd4469eb4e0673542fb7de3f411254)
1 
2 static char help[] = "Tests taking part of existing array to create a new vector.\n\n";
3 
4 #include <petscvec.h>
5 
6 int main(int argc,char **argv)
7 {
8   PetscMPIInt    size;
9   PetscInt       n = 10,i;
10   PetscScalar    array[10];
11   Vec            x;
12 
13   CHKERRQ(PetscInitialize(&argc,&argv,(char*)0,help));
14   CHKERRMPI(MPI_Comm_size(PETSC_COMM_WORLD,&size));
15   PetscCheckFalse(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   CHKERRQ(VecCreateSeqWithArray(PETSC_COMM_SELF,1,n,array+1,&x));
22   CHKERRQ(VecView(x,PETSC_VIEWER_STDOUT_SELF));
23   CHKERRQ(VecDestroy(&x));
24   CHKERRQ(PetscFinalize());
25   return 0;
26 }
27