Actual source code: ex2.c
2: static char help[] = "Tests vector scatter-gather operations. Input arguments are\n\
3: -n <length> : vector length\n\n";
5: #include <petscvec.h>
7: int main(int argc, char **argv)
8: {
9: PetscInt n = 5, idx1[2] = {0, 3}, idx2[2] = {1, 4};
10: PetscScalar one = 1.0, two = 2.0;
11: Vec x, y;
12: IS is1, is2;
13: VecScatter ctx = 0;
16: PetscInitialize(&argc, &argv, (char *)0, help);
17: PetscOptionsGetInt(NULL, NULL, "-n", &n, NULL);
19: /* create two vector */
20: VecCreateSeq(PETSC_COMM_SELF, n, &x);
21: VecDuplicate(x, &y);
23: /* create two index sets */
24: ISCreateGeneral(PETSC_COMM_SELF, 2, idx1, PETSC_COPY_VALUES, &is1);
25: ISCreateGeneral(PETSC_COMM_SELF, 2, idx2, PETSC_COPY_VALUES, &is2);
27: VecSet(x, one);
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);
33: VecView(y, PETSC_VIEWER_STDOUT_SELF);
35: VecScatterBegin(ctx, y, x, INSERT_VALUES, SCATTER_FORWARD);
36: VecScatterEnd(ctx, y, x, INSERT_VALUES, SCATTER_FORWARD);
37: VecScatterDestroy(&ctx);
39: PetscPrintf(PETSC_COMM_SELF, "-------\n");
40: VecView(x, PETSC_VIEWER_STDOUT_SELF);
42: ISDestroy(&is1);
43: ISDestroy(&is2);
45: VecDestroy(&x);
46: VecDestroy(&y);
48: PetscFinalize();
49: return 0;
50: }
52: /*TEST
54: test:
56: TEST*/