Actual source code: ex9.c
1: /*$Id: ex9.c,v 1.53 2001/09/11 16:32:10 bsmith 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 n = 5,ierr,idx2[3] = {0,2,3},idx1[3] = {0,1,2};
11: int size,rank,i;
12: PetscScalar mone = -1.0,value;
13: Vec x,y;
14: IS is1,is2;
15: VecScatter ctx = 0;
17: PetscInitialize(&argc,&argv,(char*)0,help);
18: MPI_Comm_size(PETSC_COMM_WORLD,&size);
19: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
21: /* create two vectors */
22: VecCreate(PETSC_COMM_WORLD,&x);
23: VecSetSizes(x,PETSC_DECIDE,size*n);
24: VecSetFromOptions(x);
25: VecCreateSeq(PETSC_COMM_SELF,n,&y);
27: /* create two index sets */
28: ISCreateGeneral(PETSC_COMM_SELF,3,idx1,&is1);
29: ISCreateGeneral(PETSC_COMM_SELF,3,idx2,&is2);
31: /* fill local part of parallel vector */
32: for (i=n*rank; i<n*(rank+1); i++) {
33: value = (PetscScalar) i;
34: VecSetValues(x,1,&i,&value,INSERT_VALUES);
35: }
36: VecAssemblyBegin(x);
37: VecAssemblyEnd(x);
39: VecView(x,PETSC_VIEWER_STDOUT_WORLD);
41: VecSet(&mone,y);
43: VecScatterCreate(x,is1,y,is2,&ctx);
44: VecScatterBegin(x,y,INSERT_VALUES,SCATTER_FORWARD,ctx);
45: VecScatterEnd(x,y,INSERT_VALUES,SCATTER_FORWARD,ctx);
46: VecScatterDestroy(ctx);
48: if (!rank) {
49: PetscPrintf(PETSC_COMM_SELF,"scattered vectorn");
50: VecView(y,PETSC_VIEWER_STDOUT_SELF);
51: }
52: ISDestroy(is1);
53: ISDestroy(is2);
54: VecDestroy(x);
55: VecDestroy(y);
57: PetscFinalize();
58: return 0;
59: }
60: