Actual source code: ex7.c


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

  4: #include <petscvec.h>

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

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

 16:   /* create two vectors */
 17:   VecCreateSeq(PETSC_COMM_SELF,n,&x);
 18:   VecDuplicate(x,&y);

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

 24:   VecSetValues(x,6,loc,vals,INSERT_VALUES);
 25:   VecView(x,PETSC_VIEWER_STDOUT_SELF);
 26:   PetscPrintf(PETSC_COMM_SELF,"----\n");
 27:   VecSet(y,two);
 28:   VecScatterCreate(x,is1,y,is2,&ctx);
 29:   VecScatterBegin(ctx,x,y,INSERT_VALUES,SCATTER_FORWARD);
 30:   VecScatterEnd(ctx,x,y,INSERT_VALUES,SCATTER_FORWARD);
 31:   VecScatterDestroy(&ctx);

 33:   VecView(y,PETSC_VIEWER_STDOUT_SELF);

 35:   ISDestroy(&is1);
 36:   ISDestroy(&is2);
 37:   VecDestroy(&x);
 38:   VecDestroy(&y);

 40:   PetscFinalize();
 41:   return 0;
 42: }

 44: /*TEST

 46:    test:

 48: TEST*/