Actual source code: ex16.c

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

  3: #include <petscvec.h>

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

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


 18:   /* create vector */
 19:   VecCreate(PETSC_COMM_WORLD,&x);
 20:   VecSetSizes(x,PETSC_DECIDE,n);
 21:   VecSetBlockSize(x,bs);
 22:   VecSetFromOptions(x);

 24:   if (rank == 0) {
 25:     for (i=0; i<4; i++) values[i] = i+1;
 26:     indices[0] = 0;
 27:     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:   /* test insertion with negative indices */
 39:   VecSetOption(x,VEC_IGNORE_NEGATIVE_INDICES,PETSC_TRUE);
 40:   if (rank == 0) {
 41:     for (i=0; i<4; i++) values[i] = -(i+1);
 42:     indices[0] = -1;
 43:     indices[1] = 3;
 44:     VecSetValuesBlocked(x,2,indices,values,INSERT_VALUES);
 45:   }
 46:   VecAssemblyBegin(x);
 47:   VecAssemblyEnd(x);

 49:   /*
 50:       Resulting vector should be 1 2 0 0 3 4 -3 -4
 51:   */
 52:   VecView(x,PETSC_VIEWER_STDOUT_WORLD);

 54:   VecDestroy(&x);

 56:   PetscFinalize();
 57:   return 0;
 58: }

 60: /*TEST

 62:    test:
 63:       nsize: 2

 65: TEST*/