Actual source code: ex15.c

petsc-3.7.5 2017-01-01
Report Typos and Errors
  2: static char help[] = "Tests VecSetValuesBlocked() on sequential vectors.\n\n";

  4: #include <petscvec.h>

  8: int main(int argc,char **argv)
  9: {
 11:   PetscMPIInt    size;
 12:   PetscInt       n = 9,bs = 3,indices[2],i;
 13:   PetscScalar    values[6];
 14:   Vec            x;

 16:   PetscInitialize(&argc,&argv,(char*)0,help);
 17:   MPI_Comm_size(PETSC_COMM_WORLD,&size);

 19:   if (size != 1) SETERRQ(PETSC_COMM_SELF,1,"Must be run with one processor");

 21:   /* create vector */
 22:   VecCreate(PETSC_COMM_SELF,&x);
 23:   VecSetSizes(x,n,n);
 24:   VecSetBlockSize(x,bs);
 25:   VecSetType(x,VECSEQ);

 27:   for (i=0; i<6; i++) values[i] = 4.0*i;
 28:   indices[0] = 0;
 29:   indices[1] = 2;

 31:   VecSetValuesBlocked(x,2,indices,values,INSERT_VALUES);
 32:   VecAssemblyBegin(x);
 33:   VecAssemblyEnd(x);

 35:   /*
 36:       Resulting vector should be 0 4 8  0 0 0 12 16 20
 37:   */
 38:   VecView(x,PETSC_VIEWER_STDOUT_WORLD);

 40:   VecDestroy(&x);

 42:   PetscFinalize();
 43:   return 0;
 44: }