Actual source code: ex15.c
2: static char help[] = "Tests VecSetValuesBlocked() on sequential vectors.\n\n";
4: #include <petscvec.h>
6: int main(int argc,char **argv)
7: {
8: PetscMPIInt size;
9: PetscInt n = 9,bs = 3,indices[2],i;
10: PetscScalar values[6];
11: Vec x;
13: PetscInitialize(&argc,&argv,(char*)0,help);
14: MPI_Comm_size(PETSC_COMM_WORLD,&size);
18: /* create vector */
19: VecCreate(PETSC_COMM_SELF,&x);
20: VecSetSizes(x,n,n);
21: VecSetBlockSize(x,bs);
22: VecSetType(x,VECSEQ);
24: for (i=0; i<6; i++) values[i] = 4.0*i;
25: indices[0] = 0;
26: indices[1] = 2;
28: VecSetValuesBlocked(x,2,indices,values,INSERT_VALUES);
29: VecAssemblyBegin(x);
30: VecAssemblyEnd(x);
32: /*
33: Resulting vector should be 0 4 8 0 0 0 12 16 20
34: */
35: VecView(x,PETSC_VIEWER_STDOUT_WORLD);
37: /* test insertion with negative indices */
38: VecSetOption(x,VEC_IGNORE_NEGATIVE_INDICES,PETSC_TRUE);
39: for (i=0; i<6; i++) values[i] = -4.0*i;
40: indices[0] = -1;
41: indices[1] = 2;
43: VecSetValuesBlocked(x,2,indices,values,ADD_VALUES);
44: VecAssemblyBegin(x);
45: VecAssemblyEnd(x);
47: /*
48: Resulting vector should be 0 4 8 0 0 0 0 0 0
49: */
50: VecView(x,PETSC_VIEWER_STDOUT_WORLD);
52: VecDestroy(&x);
54: PetscFinalize();
55: return 0;
56: }
58: /*TEST
60: test:
62: TEST*/