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.\n\n";

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

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

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

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

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

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

 41:   ISDestroy(is1);
 42:   ISDestroy(is2);

 44:   VecDestroy(x);
 45:   VecDestroy(y);
 46:   PetscFinalize();

 48:   return 0;
 49: }