Actual source code: ex6.c

petsc-3.4.2 2013-07-02
  2: static char help[] = "Demonstrates a scatter with a stride and general index set.\n\n";

  4: #include <petscvec.h>

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

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

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

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

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

 36:   VecView(y,PETSC_VIEWER_STDOUT_SELF);

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

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