Actual source code: ex15.c


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

  4: #include <petscvec.h>

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

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


 19:   /* create vector */
 20:   VecCreate(PETSC_COMM_SELF, &x);
 21:   VecSetSizes(x, n, n);
 22:   VecSetBlockSize(x, bs);
 23:   VecSetType(x, VECSEQ);

 25:   for (i = 0; i < 6; i++) values[i] = 4.0 * i;
 26:   indices[0] = 0;
 27:   indices[1] = 2;

 29:   VecSetValuesBlocked(x, 2, indices, values, INSERT_VALUES);
 30:   VecAssemblyBegin(x);
 31:   VecAssemblyEnd(x);

 33:   /*
 34:       Resulting vector should be 0 4 8  0 0 0 12 16 20
 35:   */
 36:   VecView(x, PETSC_VIEWER_STDOUT_WORLD);

 38:   /* test insertion with negative indices */
 39:   VecSetOption(x, VEC_IGNORE_NEGATIVE_INDICES, PETSC_TRUE);
 40:   for (i = 0; i < 6; i++) values[i] = -4.0 * i;
 41:   indices[0] = -1;
 42:   indices[1] = 2;

 44:   VecSetValuesBlocked(x, 2, indices, values, ADD_VALUES);
 45:   VecAssemblyBegin(x);
 46:   VecAssemblyEnd(x);

 48:   /*
 49:       Resulting vector should be 0 4 8  0 0 0 0 0 0
 50:   */
 51:   VecView(x, PETSC_VIEWER_STDOUT_WORLD);

 53:   VecDestroy(&x);

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

 59: /*TEST

 61:    test:

 63: TEST*/