Date: 2013-07-02T14:40:15+00:00

Actual source code: ex40.c
petsc-3.4.2 2013-07-02

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

      4: #include <petscvec.h>

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

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

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

     24:   VecCreateSeqWithArray(PETSC_COMM_SELF,1,n,array+1,&x);
     25:   VecView(x,PETSC_VIEWER_STDOUT_SELF);
     26:   VecDestroy(&x);
     27:   PetscFinalize();
     28:   return 0;
     29: }