Actual source code: ex16.c
petsc-3.8.3 2017-12-09
2: static char help[] = "Tests VecSetValuesBlocked() on MPI vectors.\n\n";
4: #include <petscvec.h>
6: int main(int argc,char **argv)
7: {
9: PetscMPIInt size,rank;
10: PetscInt i,n = 8,bs = 2,indices[2];
11: PetscScalar values[4];
12: Vec x;
14: PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
15: MPI_Comm_size(PETSC_COMM_WORLD,&size);
16: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
18: if (size != 2) SETERRQ(PETSC_COMM_SELF,1,"Must be run with two processors");
20: /* create vector */
21: VecCreate(PETSC_COMM_WORLD,&x);
22: VecSetSizes(x,PETSC_DECIDE,n);
23: VecSetBlockSize(x,bs);
24: VecSetFromOptions(x);
26: if (!rank) {
27: for (i=0; i<4; i++) values[i] = i+1;
28: indices[0] = 0;
29: indices[1] = 2;
30: VecSetValuesBlocked(x,2,indices,values,INSERT_VALUES);
31: }
32: VecAssemblyBegin(x);
33: VecAssemblyEnd(x);
35: /*
36: Resulting vector should be 1 2 0 0 3 4 0 0
37: */
38: VecView(x,PETSC_VIEWER_STDOUT_WORLD);
40: VecDestroy(&x);
42: PetscFinalize();
43: return ierr;
44: }