Actual source code: ex16.c
1: /*$Id: ex16.c,v 1.15 2001/04/10 19:35:02 bsmith Exp $*/
3: static char help[] = "Tests VecSetValuesBlocked() on MPI vectors.nn";
5: #include petscvec.h
6: #include petscsys.h
8: int main(int argc,char **argv)
9: {
10: int i,n = 8,ierr,size,rank,bs = 2,indices[2];
11: Scalar values[4];
12: Vec x;
14: PetscInitialize(&argc,&argv,(char*)0,help);
15: MPI_Comm_size(PETSC_COMM_WORLD,&size);
16: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
18: if (size != 2) SETERRQ(1,"Must be run with two processors");
20: /* create vector */
21: VecCreateMPI(PETSC_COMM_WORLD,PETSC_DECIDE,n,&x);
22: VecSetBlockSize(x,bs);
24: if (!rank) {
25: for (i=0; i<4; i++) values[i] = i+1;
26: indices[0] = 0; indices[1] = 2;
27: VecSetValuesBlocked(x,2,indices,values,INSERT_VALUES);
28: }
29: VecAssemblyBegin(x);
30: VecAssemblyEnd(x);
32: /*
33: Resulting vector should be 1 2 0 0 3 4 0 0
34: */
35: VecView(x,PETSC_VIEWER_STDOUT_WORLD);
37: VecDestroy(x);
39: PetscFinalize();
40: return 0;
41: }
42: