Actual source code: ex14.c

  1: /*$Id: ex14.c,v 1.47 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 the tricky case.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;
 13:   Scalar        value,zero = 0.0;
 14:   Vec           x,y;
 15:   IS            is1,is2;
 16:   VecScatter    ctx = 0;

 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:   VecCreateMPI(PETSC_COMM_WORLD,PETSC_DECIDE,N,&y);
 25:   VecCreateSeq(PETSC_COMM_SELF,N,&x);

 27:   /* create two index sets */
 28:   ISCreateStride(PETSC_COMM_SELF,n,0,1,&is1);
 29:   ISCreateStride(PETSC_COMM_SELF,n,rank,1,&is2);

 31:   value = rank+1;
 32:   VecSet(&value,x);
 33:   VecSet(&zero,y);

 35:   VecScatterCreate(x,is1,y,is2,&ctx);
 36:   VecScatterBegin(x,y,ADD_VALUES,SCATTER_FORWARD,ctx);
 37:   VecScatterEnd(x,y,ADD_VALUES,SCATTER_FORWARD,ctx);
 38:   VecScatterDestroy(ctx);
 39: 
 40:   VecView(y,PETSC_VIEWER_STDOUT_WORLD);

 42:   VecDestroy(x);
 43:   VecDestroy(y);
 44:   ISDestroy(is1);
 45:   ISDestroy(is2);

 47:   PetscFinalize();
 48:   return 0;
 49: }
 50: