Actual source code: ex2.c
2: static char help[] = "Tests vector scatter-gather operations. Input arguments are\n\
3: -n <length> : vector length\n\n";
5: #include petscvec.h
6: #include petscsys.h
10: int main(int argc,char **argv)
11: {
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);
22: /* create two vector */
23: VecCreateSeq(PETSC_COMM_SELF,n,&x);
24: VecDuplicate(x,&y);
26: /* create two index sets */
27: ISCreateGeneral(PETSC_COMM_SELF,2,idx1,&is1);
28: ISCreateGeneral(PETSC_COMM_SELF,2,idx2,&is2);
30: VecSet(x,one);
31: VecSet(y,two);
32: VecScatterCreate(x,is1,y,is2,&ctx);
33: VecScatterBegin(ctx,x,y,INSERT_VALUES,SCATTER_FORWARD);
34: VecScatterEnd(ctx,x,y,INSERT_VALUES,SCATTER_FORWARD);
35:
36: VecView(y,PETSC_VIEWER_STDOUT_SELF);
38: VecScatterBegin(ctx,y,x,INSERT_VALUES,SCATTER_FORWARD);
39: VecScatterEnd(ctx,y,x,INSERT_VALUES,SCATTER_FORWARD);
40: VecScatterDestroy(ctx);
42: PetscPrintf(PETSC_COMM_SELF,"-------\n");
43: VecView(x,PETSC_VIEWER_STDOUT_SELF);
45: ISDestroy(is1);
46: ISDestroy(is2);
48: VecDestroy(x);
49: VecDestroy(y);
51: PetscFinalize();
52: return 0;
53: }
54: