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