Actual source code: ex8.c
2: static char help[] = "Demonstrates scattering with strided index sets.\n\n";
4: #include petscvec.h
5: #include petscsys.h
9: int main(int argc,char **argv)
10: {
12: PetscInt n = 6,loc[6] = {0,1,2,3,4,5};
13: PetscScalar two = 2.0,vals[6] = {10,11,12,13,14,15};
14: Vec x,y;
15: IS is1,is2;
16: VecScatter ctx = 0;
18: PetscInitialize(&argc,&argv,(char*)0,help);
20: /* create two vectors */
21: VecCreateSeq(PETSC_COMM_SELF,n,&x);
22: VecDuplicate(x,&y);
24: /* create two index sets */
25: ISCreateStride(PETSC_COMM_SELF,3,0,2,&is1);
26: ISCreateStride(PETSC_COMM_SELF,3,1,2,&is2);
28: VecSetValues(x,6,loc,vals,INSERT_VALUES);
29: VecView(x,PETSC_VIEWER_STDOUT_SELF);
30: PetscPrintf(PETSC_COMM_SELF,"----\n");
31: VecSet(y,two);
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: VecScatterDestroy(ctx);
36:
37: VecView(y,PETSC_VIEWER_STDOUT_SELF);
39: ISDestroy(is1);
40: ISDestroy(is2);
41: VecDestroy(x);
42: VecDestroy(y);
44: PetscFinalize();
45: return 0;
46: }
47: