Actual source code: ex6.c

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

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

  9: int main(int argc,char **argv)
 10: {
 12:   PetscInt       n = 6,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(y,two);
 32:   VecScatterCreate(x,is1,y,is2,&ctx);
 33:   VecScatterBegin(ctx,x,y,INSERT_VALUES,SCATTER_FORWARD);
 34:   VecScatterEnd(ctx,x,y,INSERT_VALUES,SCATTER_FORWARD);
 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: