Actual source code: ex7.c


  2: static char help[] = "Demonstrates a scatter with a stride and general index set.\n\n";

  4: #include <petscvec.h>

  6: int main(int argc, char **argv)
  7: {
  8:   PetscInt    n = 6, idx1[3] = {0, 1, 2}, loc[6] = {0, 1, 2, 3, 4, 5};
  9:   PetscScalar two = 2.0, vals[6] = {10, 11, 12, 13, 14, 15};
 10:   Vec         x, y;
 11:   IS          is1, is2;
 12:   VecScatter  ctx = 0;

 14:   PetscFunctionBeginUser;
 15:   PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));

 17:   /* create two vectors */
 18:   PetscCall(VecCreateSeq(PETSC_COMM_SELF, n, &x));
 19:   PetscCall(VecDuplicate(x, &y));

 21:   /* create two index sets */
 22:   PetscCall(ISCreateStride(PETSC_COMM_SELF, 3, 0, 2, &is1));
 23:   PetscCall(ISCreateGeneral(PETSC_COMM_SELF, 3, idx1, PETSC_COPY_VALUES, &is2));

 25:   PetscCall(VecSetValues(x, 6, loc, vals, INSERT_VALUES));
 26:   PetscCall(VecView(x, PETSC_VIEWER_STDOUT_SELF));
 27:   PetscCall(PetscPrintf(PETSC_COMM_SELF, "----\n"));
 28:   PetscCall(VecSet(y, two));
 29:   PetscCall(VecScatterCreate(x, is1, y, is2, &ctx));
 30:   PetscCall(VecScatterBegin(ctx, x, y, INSERT_VALUES, SCATTER_FORWARD));
 31:   PetscCall(VecScatterEnd(ctx, x, y, INSERT_VALUES, SCATTER_FORWARD));
 32:   PetscCall(VecScatterDestroy(&ctx));

 34:   PetscCall(VecView(y, PETSC_VIEWER_STDOUT_SELF));

 36:   PetscCall(ISDestroy(&is1));
 37:   PetscCall(ISDestroy(&is2));
 38:   PetscCall(VecDestroy(&x));
 39:   PetscCall(VecDestroy(&y));

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

 45: /*TEST

 47:    test:

 49: TEST*/