Actual source code: ex4.c

  1: /*$Id: ex4.c,v 1.55 2001/09/08 03:20:21 bsmith Exp $*/

  3: static char help[] = "Scatters from a parallel vector into seqential vectors.nn";

 5:  #include petscvec.h
 6:  #include petscsys.h

  8: int main(int argc,char **argv)
  9: {
 10:   int           n = 5,ierr,idx1[2] = {0,3},idx2[2] = {1,4},rank;
 11:   PetscScalar   one = 1.0,two = 2.0;
 12:   Vec           x,y;
 13:   IS            is1,is2;
 14:   VecScatter    ctx = 0;

 16:   PetscInitialize(&argc,&argv,(char*)0,help);
 17:   PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);
 18:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);

 20:   /* create two vectors */
 21:   VecCreate(PETSC_COMM_WORLD,&x);
 22:   VecSetSizes(x,n,PETSC_DECIDE);
 23:   VecSetFromOptions(x);
 24:   VecCreateSeq(PETSC_COMM_SELF,n,&y);

 26:   /* create two index sets */
 27:   ISCreateGeneral(PETSC_COMM_SELF,2,idx1,&is1);
 28:   ISCreateGeneral(PETSC_COMM_SELF,2,idx2,&is2);

 30:   VecSet(&one,x);
 31:   VecSet(&two,y);
 32:   VecScatterCreate(x,is1,y,is2,&ctx);
 33:   VecScatterBegin(x,y,INSERT_VALUES,SCATTER_FORWARD,ctx);
 34:   VecScatterEnd(x,y,INSERT_VALUES,SCATTER_FORWARD,ctx);
 35:   VecScatterDestroy(ctx);
 36: 
 37:   if (!rank) {VecView(y,PETSC_VIEWER_STDOUT_SELF);}

 39:   ISDestroy(is1);
 40:   ISDestroy(is2);

 42:   VecDestroy(x);
 43:   VecDestroy(y);
 44:   PetscFinalize();

 46:   return 0;
 47: }