Actual source code: ex4.c
2: static char help[] = "Scatters from a parallel vector into sequential vectors.\n\n";
4: #include <petscvec.h>
6: int main(int argc, char **argv)
7: {
8: PetscMPIInt rank;
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);
18: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
20: /* create two vectors */
21: VecCreate(PETSC_COMM_WORLD, &x);
22: VecSetSizes(x, n, PETSC_DECIDE);
23: VecSetFromOptions(x);
24: VecCreate(PETSC_COMM_SELF, &y);
25: VecSetSizes(y, n, PETSC_DECIDE);
26: VecSetFromOptions(y);
28: /* create two index sets */
29: ISCreateGeneral(PETSC_COMM_SELF, 2, idx1, PETSC_COPY_VALUES, &is1);
30: ISCreateGeneral(PETSC_COMM_SELF, 2, idx2, PETSC_COPY_VALUES, &is2);
32: VecSet(x, one);
33: VecSet(y, two);
34: VecScatterCreate(x, is1, y, is2, &ctx);
35: VecScatterBegin(ctx, x, y, INSERT_VALUES, SCATTER_FORWARD);
36: VecScatterEnd(ctx, x, y, INSERT_VALUES, SCATTER_FORWARD);
37: VecScatterDestroy(&ctx);
39: if (rank == 0) VecView(y, PETSC_VIEWER_STDOUT_SELF);
41: ISDestroy(&is1);
42: ISDestroy(&is2);
44: VecDestroy(&x);
45: VecDestroy(&y);
46: PetscFinalize();
47: return 0;
48: }
50: /*TEST
52: test:
53: nsize: 2
54: filter: grep -v type
55: diff_args: -j
57: test:
58: diff_args: -j
59: suffix: cuda
60: args: -vec_type cuda
61: output_file: output/ex4_1.out
62: filter: grep -v type
63: requires: cuda
65: test:
66: diff_args: -j
67: suffix: cuda2
68: nsize: 2
69: args: -vec_type cuda
70: output_file: output/ex4_1.out
71: filter: grep -v type
72: requires: cuda
74: test:
75: diff_args: -j
76: suffix: kokkos
77: args: -vec_type kokkos
78: output_file: output/ex4_1.out
79: filter: grep -v type
80: requires: kokkos_kernels
82: test:
83: diff_args: -j
84: suffix: kokkos2
85: nsize: 2
86: args: -vec_type kokkos
87: output_file: output/ex4_1.out
88: filter: grep -v type
89: requires: kokkos_kernels
91: testset:
92: diff_args: -j
93: requires: hip
94: filter: grep -v type
95: args: -vec_type hip
96: output_file: output/ex4_1.out
97: test:
98: suffix: hip
99: test:
100: suffix: hip2
101: nsize: 2
102: TEST*/