Actual source code: ex40.c

petsc-3.12.2 2019-11-22
Report Typos and Errors

  2: static char help[] = "Tests taking part of existing array to create a new vector.\n\n";

  4:  #include <petscvec.h>

  6: int main(int argc,char **argv)
  7: {
  9:   PetscMPIInt    size;
 10:   PetscInt       n = 10,i;
 11:   PetscScalar    array[10];
 12:   Vec            x;

 14:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
 15:   MPI_Comm_size(PETSC_COMM_WORLD,&size);
 16:   if (size != 1) SETERRQ(PETSC_COMM_SELF,1,"This is a uniprocessor example only!");

 18:   /* create vector */
 19:   for (i=0; i<n; i++) array[i] = i;
 20:   n = n-1;

 22:   VecCreateSeqWithArray(PETSC_COMM_SELF,1,n,array+1,&x);
 23:   VecView(x,PETSC_VIEWER_STDOUT_SELF);
 24:   VecDestroy(&x);
 25:   PetscFinalize();
 26:   return ierr;
 27: }