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.nn";

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

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

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

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

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

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

 37:   ISDestroy(is1);
 38:   ISDestroy(is2);
 39:   VecDestroy(x);
 40:   VecDestroy(y);

 42:   PetscFinalize();
 43:   return 0;
 44: }
 45: