Actual source code: ex2.c

  2: static char help[] = "Tests vector scatter-gather operations.  Input arguments are\n\
  3:   -n <length> : vector length\n\n";

 5:  #include petscvec.h

  9: int main(int argc,char **argv)
 10: {
 12:   PetscInt       n = 5,idx1[2] = {0,3},idx2[2] = {1,4};
 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);

 21:   /* create two vector */
 22:   VecCreateSeq(PETSC_COMM_SELF,n,&x);
 23:   VecDuplicate(x,&y);

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

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

 37:   VecScatterBegin(ctx,y,x,INSERT_VALUES,SCATTER_FORWARD);
 38:   VecScatterEnd(ctx,y,x,INSERT_VALUES,SCATTER_FORWARD);
 39:   VecScatterDestroy(ctx);

 41:   PetscPrintf(PETSC_COMM_SELF,"-------\n");
 42:   VecView(x,PETSC_VIEWER_STDOUT_SELF);

 44:   ISDestroy(is1);
 45:   ISDestroy(is2);

 47:   VecDestroy(x);
 48:   VecDestroy(y);

 50:   PetscFinalize();
 51:   return 0;
 52: }
 53: