Actual source code: ex13.c
1: /*$Id: ex13.c,v 1.51 2001/09/11 16:32:10 bsmith Exp $*/
3: static char help[] = "Scatters from a sequential vector to a parallel vector. In\n\
4: this case each local vector is as long as the entire parallel vector.\n";
6: #include petscvec.h
7: #include petscsys.h
11: int main(int argc,char **argv)
12: {
13: int n = 5,ierr;
14: int size,rank,i,N;
15: PetscScalar value;
16: Vec x,y;
17: IS is1,is2;
18: VecScatter ctx = 0;
20: PetscInitialize(&argc,&argv,(char*)0,help);
21: MPI_Comm_size(PETSC_COMM_WORLD,&size);
22: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
24: /* create two vectors */
25: N = size*n;
26: VecCreate(PETSC_COMM_WORLD,&y);
27: VecSetSizes(y,PETSC_DECIDE,N);
28: VecSetFromOptions(y);
29: VecCreateSeq(PETSC_COMM_SELF,N,&x);
31: /* create two index sets */
32: ISCreateStride(PETSC_COMM_SELF,N,0,1,&is1);
33: ISCreateStride(PETSC_COMM_SELF,N,0,1,&is2);
35: for (i=0; i<N; i++) {
36: value = (PetscScalar) i;
37: VecSetValues(x,1,&i,&value,INSERT_VALUES);
38: }
39: VecAssemblyBegin(x);
40: VecAssemblyEnd(x);
42: VecScatterCreate(x,is2,y,is1,&ctx);
43: VecScatterBegin(x,y,INSERT_VALUES,SCATTER_FORWARD,ctx);
44: VecScatterEnd(x,y,INSERT_VALUES,SCATTER_FORWARD,ctx);
45: VecScatterDestroy(ctx);
46:
47: VecView(y,PETSC_VIEWER_STDOUT_WORLD);
49: VecDestroy(x);
50: VecDestroy(y);
51: ISDestroy(is1);
52: ISDestroy(is2);
54: PetscFinalize();
55: return 0;
56: }
57: