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 aren
4: -n <length> : vector lengthnn";
6: #include petscvec.h
7: #include petscsys.h
9: int main(int argc,char **argv)
10: {
11: int n = 5,ierr,idx1[2] = {0,3},idx2[2] = {1,4};
12: PetscScalar one = 1.0,two = 2.0;
13: Vec x,y;
14: IS is1,is2;
15: VecScatter ctx = 0;
17: PetscInitialize(&argc,&argv,(char*)0,help);
18: PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
20: /* create two vector */
21: VecCreateSeq(PETSC_COMM_SELF,n,&x);
22: VecDuplicate(x,&y);
24: /* create two index sets */
25: ISCreateGeneral(PETSC_COMM_SELF,2,idx1,&is1);
26: ISCreateGeneral(PETSC_COMM_SELF,2,idx2,&is2);
28: VecSet(&one,x);
29: VecSet(&two,y);
30: VecScatterCreate(x,is1,y,is2,&ctx);
31: VecScatterBegin(x,y,INSERT_VALUES,SCATTER_FORWARD,ctx);
32: VecScatterEnd(x,y,INSERT_VALUES,SCATTER_FORWARD,ctx);
33:
34: VecView(y,PETSC_VIEWER_STDOUT_SELF);
36: VecScatterBegin(y,x,INSERT_VALUES,SCATTER_FORWARD,ctx);
37: VecScatterEnd(y,x,INSERT_VALUES,SCATTER_FORWARD,ctx);
38: VecScatterDestroy(ctx);
40: PetscPrintf(PETSC_COMM_SELF,"-------n");
41: VecView(x,PETSC_VIEWER_STDOUT_SELF);
43: ISDestroy(is1);
44: ISDestroy(is2);
46: VecDestroy(x);
47: VecDestroy(y);
49: PetscFinalize();
50: return 0;
51: }
52: