Actual source code: ex6.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;
15: PetscInitialize(&argc, &argv, (char *)0, help);
17: /* create two vector */
18: VecCreateSeq(PETSC_COMM_SELF, n, &x);
19: VecDuplicate(x, &y);
21: /* create two index sets */
22: ISCreateGeneral(PETSC_COMM_SELF, 3, idx1, PETSC_COPY_VALUES, &is1);
23: ISCreateStride(PETSC_COMM_SELF, 3, 0, 2, &is2);
25: VecSetValues(x, 6, loc, vals, INSERT_VALUES);
26: VecView(x, PETSC_VIEWER_STDOUT_SELF);
27: PetscPrintf(PETSC_COMM_SELF, "----\n");
28: VecSet(y, two);
29: VecScatterCreate(x, is1, y, is2, &ctx);
30: VecScatterBegin(ctx, x, y, INSERT_VALUES, SCATTER_FORWARD);
31: VecScatterEnd(ctx, x, y, INSERT_VALUES, SCATTER_FORWARD);
32: VecScatterDestroy(&ctx);
34: VecView(y, PETSC_VIEWER_STDOUT_SELF);
36: ISDestroy(&is1);
37: ISDestroy(&is2);
38: VecDestroy(&x);
39: VecDestroy(&y);
41: PetscFinalize();
42: return 0;
43: }
45: /*TEST
47: test:
49: TEST*/