Actual source code: ex16.c

  1: /*$Id: ex16.c,v 1.17 2001/09/11 16:32:10 bsmith Exp $*/

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

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

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

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

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

 20:   /* create vector */
 21:   VecCreateMPI(PETSC_COMM_WORLD,PETSC_DECIDE,n,&x);
 22:   VecSetFromOptions(x);
 23:   VecSetBlockSize(x,bs);

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

 33:   /* 
 34:       Resulting vector should be 1 2 0 0 3 4 0 0
 35:   */
 36:   VecView(x,PETSC_VIEWER_STDOUT_WORLD);

 38:   VecDestroy(x);

 40:   PetscFinalize();
 41:   return 0;
 42: }
 43: