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 PetscCall(PetscInitialize(&argc,&argv,(char*)0,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