Actual source code: ex16.c
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(1,"Must be run with two processors");
22: /* create vector */
23: VecCreateMPI(PETSC_COMM_WORLD,PETSC_DECIDE,n,&x);
24: VecSetFromOptions(x);
25: VecSetBlockSize(x,bs);
27: if (!rank) {
28: for (i=0; i<4; i++) values[i] = i+1;
29: indices[0] = 0; 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 0;
44: }
45: