Actual source code: ex12.c
1: /*$Id: ex12.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.\n\
4: This does case when we are merely selecting the local part of the\n\
5: parallel vector.\n";
7: #include petscvec.h
8: #include petscsys.h
12: int main(int argc,char **argv)
13: {
14: int n = 5,ierr,size,rank,i;
15: PetscScalar value;
16: Vec x,y;
17: IS is1,is2;
18: VecScatter ctx = 0;
20: PetscInitialize(&argc,&argv,(char*)0,help);
22: MPI_Comm_size(PETSC_COMM_WORLD,&size);
23: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
25: /* create two vectors */
26: VecCreate(PETSC_COMM_WORLD,&x);
27: VecSetSizes(x,PETSC_DECIDE,size*n);
28: VecSetFromOptions(x);
29: VecCreateSeq(PETSC_COMM_SELF,n,&y);
31: /* create two index sets */
32: ISCreateStride(PETSC_COMM_SELF,n,n*rank,1,&is1);
33: ISCreateStride(PETSC_COMM_SELF,n,0,1,&is2);
35: /* each processor inserts the entire vector */
36: /* this is redundant but tests assembly */
37: for (i=0; i<n; i++) {
38: value = (PetscScalar) (i + 10*rank);
39: VecSetValues(y,1,&i,&value,INSERT_VALUES);
40: }
41: VecAssemblyBegin(y);
42: VecAssemblyEnd(y);
44: VecScatterCreate(y,is2,x,is1,&ctx);
45: VecScatterBegin(y,x,INSERT_VALUES,SCATTER_FORWARD,ctx);
46: VecScatterEnd(y,x,INSERT_VALUES,SCATTER_FORWARD,ctx);
47: VecScatterDestroy(ctx);
48:
49: VecView(x,PETSC_VIEWER_STDOUT_WORLD);
51: VecDestroy(x);
52: VecDestroy(y);
53: ISDestroy(is1);
54: ISDestroy(is2);
56: PetscFinalize();
57: return 0;
58: }
59: