Actual source code: ex11.c
1: /*$Id: ex11.c,v 1.49 2001/03/23 23:21:30 balay Exp $*/
3: static char help[] = "Scatters from a parallel vector to a sequential vector.nn";
5: #include petscvec.h
6: #include petscsys.h
8: int main(int argc,char **argv)
9: {
10: int ierr,size,rank,i,N;
11: Scalar mone = -1.0,value;
12: Vec x,y;
13: IS is1,is2;
14: VecScatter ctx = 0;
16: PetscInitialize(&argc,&argv,(char*)0,help);
17: MPI_Comm_size(PETSC_COMM_WORLD,&size);
18: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
20: /* create two vectors */
21: VecCreateMPI(PETSC_COMM_WORLD,rank+1,PETSC_DECIDE,&x);
22: VecGetSize(x,&N);
23: VecCreateSeq(PETSC_COMM_SELF,N-rank,&y);
25: /* create two index sets */
26: ISCreateStride(PETSC_COMM_SELF,N-rank,rank,1,&is1);
27: ISCreateStride(PETSC_COMM_SELF,N-rank,0,1,&is2);
29: /* fill parallel vector: note this is not efficient way*/
30: for (i=0; i<N; i++) {
31: value = (Scalar) i;
32: VecSetValues(x,1,&i,&value,INSERT_VALUES);
33: }
34: VecAssemblyBegin(x);
35: VecAssemblyEnd(x);
36: VecSet(&mone,y);
38: VecView(x,PETSC_VIEWER_STDOUT_WORLD);
40: VecScatterCreate(x,is1,y,is2,&ctx);
41: VecScatterBegin(x,y,INSERT_VALUES,SCATTER_FORWARD,ctx);
42: VecScatterEnd(x,y,INSERT_VALUES,SCATTER_FORWARD,ctx);
43: VecScatterDestroy(ctx);
45: if (!rank)
46: {printf("----n"); VecView(y,PETSC_VIEWER_STDOUT_SELF);}
48: ISDestroy(is1);
49: ISDestroy(is2);
50: VecDestroy(x);
51: VecDestroy(y);
53: PetscFinalize();
54: return 0;
55: }
56: