Actual source code: ex15.c

  1: /*$Id: ex15.c,v 1.18 2001/08/07 03:02:26 balay Exp $*/

  3: static char help[] = "Tests VecSetValuesBlocked() on sequential vectors.nn";

 5:  #include petscvec.h
 6:  #include petscsys.h

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

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

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

 19:   /* create vector */
 20:   VecCreateSeq(PETSC_COMM_SELF,n,&x);
 21:   VecSetBlockSize(x,bs);

 23:   for (i=0; i<6; i++) values[i] = 4.0*i;
 24:   indices[0] = 0; indices[1] = 2;
 25:   VecSetValuesBlocked(x,2,indices,values,INSERT_VALUES);

 27:   VecAssemblyBegin(x);
 28:   VecAssemblyEnd(x);

 30:   /* 
 31:       Resulting vector should be 0 4 8  0 0 0 12 16 20
 32:   */
 33:   VecView(x,PETSC_VIEWER_STDOUT_WORLD);

 35:   VecDestroy(x);

 37:   PetscFinalize();
 38:   return 0;
 39: }
 40: