Actual source code: ex4.c

  1: /*$Id: ex4.c,v 1.53 2001/03/23 23:21:30 balay 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:   Scalar        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:   VecCreateMPI(PETSC_COMM_WORLD,n,PETSC_DECIDE,&x);
 22:   VecCreateSeq(PETSC_COMM_SELF,n,&y);

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

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

 37:   ISDestroy(is1);
 38:   ISDestroy(is2);

 40:   VecDestroy(x);
 41:   VecDestroy(y);
 42:   PetscFinalize();

 44:   return 0;
 45: }