Actual source code: ex12.c
1: /*$Id: ex12.c,v 1.48 2001/03/23 23:21:30 balay 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 then
5: parallel vector.n";
7: #include "petscvec.h"
8: #include "petscsys.h"
10: int main(int argc,char **argv)
11: {
12: int n = 5,ierr,size,rank,i;
13: Scalar value;
14: Vec x,y;
15: IS is1,is2;
16: VecScatter ctx = 0;
18: PetscInitialize(&argc,&argv,(char*)0,help);
20: MPI_Comm_size(PETSC_COMM_WORLD,&size);
21: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
23: /* create two vectors */
24: VecCreateMPI(PETSC_COMM_WORLD,PETSC_DECIDE,size*n,&x);
25: VecCreateSeq(PETSC_COMM_SELF,n,&y);
27: /* create two index sets */
28: ISCreateStride(PETSC_COMM_SELF,n,n*rank,1,&is1);
29: ISCreateStride(PETSC_COMM_SELF,n,0,1,&is2);
31: /* each processor inserts the entire vector */
32: /* this is redundant but tests assembly */
33: for (i=0; i<n; i++) {
34: value = (Scalar) (i + 10*rank);
35: VecSetValues(y,1,&i,&value,INSERT_VALUES);
36: }
37: VecAssemblyBegin(y);
38: VecAssemblyEnd(y);
40: VecScatterCreate(y,is2,x,is1,&ctx);
41: VecScatterBegin(y,x,INSERT_VALUES,SCATTER_FORWARD,ctx);
42: VecScatterEnd(y,x,INSERT_VALUES,SCATTER_FORWARD,ctx);
43: VecScatterDestroy(ctx);
44:
45: VecView(x,PETSC_VIEWER_STDOUT_WORLD);
47: VecDestroy(x);
48: VecDestroy(y);
49: ISDestroy(is1);
50: ISDestroy(is2);
52: PetscFinalize();
53: return 0;
54: }
55: