Actual source code: ex15.c
petsc-3.12.1 2019-10-22
2: static char help[] = "Tests VecSetValuesBlocked() on sequential vectors.\n\n";
4: #include <petscvec.h>
6: int main(int argc,char **argv)
7: {
9: PetscMPIInt size;
10: PetscInt n = 9,bs = 3,indices[2],i;
11: PetscScalar values[6];
12: Vec x;
14: PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
15: MPI_Comm_size(PETSC_COMM_WORLD,&size);
17: if (size != 1) SETERRQ(PETSC_COMM_SELF,1,"Must be run with one processor");
19: /* create vector */
20: VecCreate(PETSC_COMM_SELF,&x);
21: VecSetSizes(x,n,n);
22: VecSetBlockSize(x,bs);
23: VecSetType(x,VECSEQ);
25: for (i=0; i<6; i++) values[i] = 4.0*i;
26: indices[0] = 0;
27: indices[1] = 2;
29: VecSetValuesBlocked(x,2,indices,values,INSERT_VALUES);
30: VecAssemblyBegin(x);
31: VecAssemblyEnd(x);
33: /*
34: Resulting vector should be 0 4 8 0 0 0 12 16 20
35: */
36: VecView(x,PETSC_VIEWER_STDOUT_WORLD);
38: /* test insertion with negative indices */
39: VecSetOption(x,VEC_IGNORE_NEGATIVE_INDICES,PETSC_TRUE);
40: for (i=0; i<6; i++) values[i] = -4.0*i;
41: indices[0] = -1;
42: indices[1] = 2;
44: VecSetValuesBlocked(x,2,indices,values,ADD_VALUES);
45: VecAssemblyBegin(x);
46: VecAssemblyEnd(x);
48: /*
49: Resulting vector should be 0 4 8 0 0 0 0 0 0
50: */
51: VecView(x,PETSC_VIEWER_STDOUT_WORLD);
53: VecDestroy(&x);
55: PetscFinalize();
56: return ierr;
57: }
61: /*TEST
63: test:
65: TEST*/