Actual source code: ex4.c
2: static char help[] = "Scatters from a parallel vector into seqential vectors.\n\n";
4: #include petscvec.h
5: #include petscsys.h
9: int main(int argc,char **argv)
10: {
12: PetscMPIInt rank;
13: PetscInt n = 5,idx1[2] = {0,3},idx2[2] = {1,4};
14: PetscScalar one = 1.0,two = 2.0;
15: Vec x,y;
16: IS is1,is2;
17: VecScatter ctx = 0;
19: PetscInitialize(&argc,&argv,(char*)0,help);
20: PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
21: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
23: /* create two vectors */
24: VecCreate(PETSC_COMM_WORLD,&x);
25: VecSetSizes(x,n,PETSC_DECIDE);
26: VecSetFromOptions(x);
27: VecCreateSeq(PETSC_COMM_SELF,n,&y);
29: /* create two index sets */
30: ISCreateGeneral(PETSC_COMM_SELF,2,idx1,&is1);
31: ISCreateGeneral(PETSC_COMM_SELF,2,idx2,&is2);
33: VecSet(x,one);
34: VecSet(y,two);
35: VecScatterCreate(x,is1,y,is2,&ctx);
36: VecScatterBegin(x,y,INSERT_VALUES,SCATTER_FORWARD,ctx);
37: VecScatterEnd(x,y,INSERT_VALUES,SCATTER_FORWARD,ctx);
38: VecScatterDestroy(ctx);
39:
40: if (!rank) {VecView(y,PETSC_VIEWER_STDOUT_SELF);}
42: ISDestroy(is1);
43: ISDestroy(is2);
45: VecDestroy(x);
46: VecDestroy(y);
47: PetscFinalize();
49: return 0;
50: }