Actual source code: ex23.c
1: /*$Id: ex23.c,v 1.18 2001/04/10 19:35:02 bsmith Exp $*/
3: static char help[] = "Scatters from a parallel vector to a sequential vector.n
4: Using a blocked send and a strided receive.nn";
6: /*
7: 0 1 2 3 | 4 5 6 7 || 8 9 10 11
9: Scatter first and third block to first processor and
10: second and third block to second processor
11: */
12: #include petscvec.h
13: #include petscsys.h
15: int main(int argc,char **argv)
16: {
17: int ierr,i;
18: int size,rank,blocks[2],nlocal;
19: Scalar value;
20: Vec x,y;
21: IS is1,is2;
22: VecScatter ctx = 0;
24: PetscInitialize(&argc,&argv,(char*)0,help);
25: MPI_Comm_size(PETSC_COMM_WORLD,&size);
26: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
28: if (size != 2) SETERRQ(1,"Must run with 2 processors");
30: /* create two vectors */
31: if (!rank) nlocal = 8;
32: else nlocal = 4;
33: VecCreateMPI(PETSC_COMM_WORLD,nlocal,12,&x);
34: VecCreateSeq(PETSC_COMM_SELF,8,&y);
36: /* create two index sets */
37: if (!rank) {
38: blocks[0] = 0; blocks[1] = 8;
39: } else {
40: blocks[0] = 4; blocks[1] = 8;
41: }
42: ISCreateBlock(PETSC_COMM_SELF,4,2,blocks,&is1);
43: ISCreateStride(PETSC_COMM_SELF,8,0,1,&is2);
45: for (i=0; i<12; i++) {
46: value = i;
47: VecSetValues(x,1,&i,&value,INSERT_VALUES);
48: }
49: VecAssemblyBegin(x);
50: VecAssemblyEnd(x);
52: VecScatterCreate(x,is1,y,is2,&ctx);
53: VecScatterBegin(x,y,INSERT_VALUES,SCATTER_FORWARD,ctx);
54: VecScatterEnd(x,y,INSERT_VALUES,SCATTER_FORWARD,ctx);
55: VecScatterDestroy(ctx);
56:
57: PetscSleep(2*rank);
58: VecView(y,PETSC_VIEWER_STDOUT_SELF);
60: VecDestroy(x);
61: VecDestroy(y);
62: ISDestroy(is1);
63: ISDestroy(is2);
65: PetscFinalize();
66: return 0;
67: }
68: