Actual source code: ex6.c

  1: /*$Id: ex6.c,v 1.48 2001/08/07 03:02:26 balay Exp $*/

  3: static char help[] = "Demonstrates a scatter with a stride and general index set.\n\n";

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

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

 18:   PetscInitialize(&argc,&argv,(char*)0,help);

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

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

 28:   VecSetValues(x,6,loc,vals,INSERT_VALUES);
 29:   VecView(x,PETSC_VIEWER_STDOUT_SELF);
 30:   PetscPrintf(PETSC_COMM_SELF,"----\n");
 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:   VecView(y,PETSC_VIEWER_STDOUT_SELF);

 39:   ISDestroy(is1);
 40:   ISDestroy(is2);
 41:   VecDestroy(x);
 42:   VecDestroy(y);

 44:   PetscFinalize();
 45:   return 0;
 46: }
 47: