Actual source code: ex16.c
1: static char help[] = "Tests VecSetValuesBlocked() on MPI vectors.\n\n";
3: #include <petscvec.h>
5: int main(int argc, char **argv)
6: {
7: PetscMPIInt size, rank;
8: PetscInt i, n = 8, bs = 2, indices[2];
9: PetscScalar values[4];
10: Vec x;
13: PetscInitialize(&argc, &argv, (char *)0, help);
14: MPI_Comm_size(PETSC_COMM_WORLD, &size);
15: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
19: /* create vector */
20: VecCreate(PETSC_COMM_WORLD, &x);
21: VecSetSizes(x, PETSC_DECIDE, n);
22: VecSetBlockSize(x, bs);
23: VecSetFromOptions(x);
25: if (rank == 0) {
26: for (i = 0; i < 4; i++) values[i] = i + 1;
27: indices[0] = 0;
28: indices[1] = 2;
29: VecSetValuesBlocked(x, 2, indices, values, INSERT_VALUES);
30: }
31: VecAssemblyBegin(x);
32: VecAssemblyEnd(x);
34: /*
35: Resulting vector should be 1 2 0 0 3 4 0 0
36: */
37: VecView(x, PETSC_VIEWER_STDOUT_WORLD);
39: /* test insertion with negative indices */
40: VecSetOption(x, VEC_IGNORE_NEGATIVE_INDICES, PETSC_TRUE);
41: if (rank == 0) {
42: for (i = 0; i < 4; i++) values[i] = -(i + 1);
43: indices[0] = -1;
44: indices[1] = 3;
45: VecSetValuesBlocked(x, 2, indices, values, INSERT_VALUES);
46: }
47: VecAssemblyBegin(x);
48: VecAssemblyEnd(x);
50: /*
51: Resulting vector should be 1 2 0 0 3 4 -3 -4
52: */
53: VecView(x, PETSC_VIEWER_STDOUT_WORLD);
55: VecDestroy(&x);
57: PetscFinalize();
58: return 0;
59: }
61: /*TEST
63: test:
64: nsize: 2
66: TEST*/