Actual source code: ex3.c
2: static char help[] = "Tests parallel vector assembly. Input arguments are\n\
3: -n <length> : local vector length\n\n";
5: #include <petscvec.h>
7: int main(int argc, char **argv)
8: {
9: PetscMPIInt size, rank;
10: PetscInt n = 5, idx;
11: PetscScalar one = 1.0, two = 2.0, three = 3.0;
12: Vec x, y;
15: PetscInitialize(&argc, &argv, (char *)0, help);
16: PetscOptionsGetInt(NULL, NULL, "-n", &n, NULL);
17: if (n < 5) n = 5;
18: MPI_Comm_size(PETSC_COMM_WORLD, &size);
19: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
23: /* create two vector */
24: VecCreateSeq(PETSC_COMM_SELF, n, &x);
25: VecCreate(PETSC_COMM_WORLD, &y);
26: VecSetSizes(y, n, PETSC_DECIDE);
27: VecSetFromOptions(y);
28: VecSet(x, one);
29: VecSet(y, two);
31: if (rank == 1) {
32: idx = 2;
33: VecSetValues(y, 1, &idx, &three, INSERT_VALUES);
34: idx = 0;
35: VecSetValues(y, 1, &idx, &two, INSERT_VALUES);
36: idx = 0;
37: VecSetValues(y, 1, &idx, &one, INSERT_VALUES);
38: } else {
39: idx = 7;
40: VecSetValues(y, 1, &idx, &three, INSERT_VALUES);
41: }
42: VecAssemblyBegin(y);
43: VecAssemblyEnd(y);
45: VecView(y, PETSC_VIEWER_STDOUT_WORLD);
47: VecDestroy(&x);
48: VecDestroy(&y);
50: PetscFinalize();
51: return 0;
52: }
54: /*TEST
56: test:
57: nsize: 2
59: test:
60: suffix: 2
61: nsize: 2
62: args: -vec_view ascii::ascii_info
64: TEST*/