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.  Inn
  4: this case each local vector is as long as the entire parallel vector.n";

 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,i,N;
 13:   PetscScalar   value;
 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:   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:   for (i=0; i<N; i++) {
 34:     value = (PetscScalar) i;
 35:     VecSetValues(x,1,&i,&value,INSERT_VALUES);
 36:   }
 37:   VecAssemblyBegin(x);
 38:   VecAssemblyEnd(x);

 40:   VecScatterCreate(x,is2,y,is1,&ctx);
 41:   VecScatterBegin(x,y,INSERT_VALUES,SCATTER_FORWARD,ctx);
 42:   VecScatterEnd(x,y,INSERT_VALUES,SCATTER_FORWARD,ctx);
 43:   VecScatterDestroy(ctx);
 44: 
 45:   VecView(y,PETSC_VIEWER_STDOUT_WORLD);

 47:   VecDestroy(x);
 48:   VecDestroy(y);
 49:   ISDestroy(is1);
 50:   ISDestroy(is2);

 52:   PetscFinalize();
 53:   return 0;
 54: }
 55: