Actual source code: ex16.c

petsc-3.3-p6 2013-02-11
  2: static char help[] = "Tests VecSetValuesBlocked() on MPI vectors.\n\n";

  4: #include <petscvec.h>

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

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

 20:   if (size != 2) SETERRQ(PETSC_COMM_SELF,1,"Must be run with two processors");

 22:   /* create vector */
 23:   VecCreate(PETSC_COMM_WORLD,&x);
 24:   VecSetSizes(x,PETSC_DECIDE,n);
 25:   VecSetBlockSize(x,bs);
 26:   VecSetFromOptions(x);

 28:   if (!rank) {
 29:     for (i=0; i<4; i++) values[i] = i+1;
 30:     indices[0] = 0; indices[1] = 2;
 31:     VecSetValuesBlocked(x,2,indices,values,INSERT_VALUES);
 32:   }
 33:   VecAssemblyBegin(x);
 34:   VecAssemblyEnd(x);

 36:   /* 
 37:       Resulting vector should be 1 2 0 0 3 4 0 0
 38:   */
 39:   VecView(x,PETSC_VIEWER_STDOUT_WORLD);

 41:   VecDestroy(&x);

 43:   PetscFinalize();
 44:   return 0;
 45: }
 46: