Actual source code: ex17.c
1: /*$Id: ex17.c,v 1.38 2001/09/11 16:32:10 bsmith Exp $*/
3: static char help[] = "Scatters from a parallel vector to a sequential vector. Inn
4: this case each local vector is as long as the entire parallel vector.nn";
6: #include petscvec.h
7: #include petscsys.h
9: int main(int argc,char **argv)
10: {
11: int n = 5,ierr;
12: int size,rank,N,low,high,iglobal,i;
13: PetscScalar value,zero = 0.0;
14: Vec x,y;
15: IS is1,is2;
16: VecScatter ctx;
18: PetscInitialize(&argc,&argv,(char*)0,help);
19: MPI_Comm_size(PETSC_COMM_WORLD,&size);
20: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
22: /* create two vectors */
23: N = size*n;
24: VecCreate(PETSC_COMM_WORLD,&y);
25: VecSetSizes(y,PETSC_DECIDE,N);
26: VecSetFromOptions(y);
27: VecCreateSeq(PETSC_COMM_SELF,N,&x);
29: /* create two index sets */
30: ISCreateStride(PETSC_COMM_SELF,N,0,1,&is1);
31: ISCreateStride(PETSC_COMM_SELF,N,0,1,&is2);
33: VecSet(&zero,x);
34: VecGetOwnershipRange(y,&low,&high);
35: for (i=0; i<n; i++) {
36: iglobal = i + low; value = (PetscScalar) (i + 10*rank);
37: VecSetValues(y,1,&iglobal,&value,INSERT_VALUES);
38: }
39: VecAssemblyBegin(y);
40: VecAssemblyEnd(y);
41: VecView(y,PETSC_VIEWER_STDOUT_WORLD);
43: VecScatterCreate(y,is2,x,is1,&ctx);
44: VecScatterBegin(y,x,ADD_VALUES,SCATTER_FORWARD,ctx);
45: VecScatterEnd(y,x,ADD_VALUES,SCATTER_FORWARD,ctx);
46: VecScatterDestroy(ctx);
47:
48: if (!rank)
49: {printf("----n"); VecView(x,PETSC_VIEWER_STDOUT_SELF);}
51: VecDestroy(x);
52: VecDestroy(y);
53: ISDestroy(is1);
54: ISDestroy(is2);
56: PetscFinalize();
57: return 0;
58: }
59: