Actual source code: ex16.c

  2: static char help[] = "Tests VecSetValuesBlocked() on MPI vectors.\n\n";

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

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

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

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

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

 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: