Actual source code: ex2.c
1: /*$Id: ex2.c,v 1.54 2001/08/07 03:02:26 balay Exp $*/
3: static char help[] = "Tests vector scatter-gather operations. Input arguments are\n\
4: -n <length> : vector length\n\n";
6: #include petscvec.h
7: #include petscsys.h
11: int main(int argc,char **argv)
12: {
13: int n = 5,ierr,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(&one,x);
31: VecSet(&two,y);
32: VecScatterCreate(x,is1,y,is2,&ctx);
33: VecScatterBegin(x,y,INSERT_VALUES,SCATTER_FORWARD,ctx);
34: VecScatterEnd(x,y,INSERT_VALUES,SCATTER_FORWARD,ctx);
35:
36: VecView(y,PETSC_VIEWER_STDOUT_SELF);
38: VecScatterBegin(y,x,INSERT_VALUES,SCATTER_FORWARD,ctx);
39: VecScatterEnd(y,x,INSERT_VALUES,SCATTER_FORWARD,ctx);
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: