Actual source code: ex7.c

petsc-3.9.1 2018-04-29
Report Typos and Errors

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

  4: /*T
  5:    requires: x
  6: T*/

  8:  #include <petscvec.h>

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

 19:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;

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

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

 29:   VecSetValues(x,6,loc,vals,INSERT_VALUES);
 30:   VecView(x,PETSC_VIEWER_STDOUT_SELF);
 31:   PetscPrintf(PETSC_COMM_SELF,"----\n");
 32:   VecSet(y,two);
 33:   VecScatterCreate(x,is1,y,is2,&ctx);
 34:   VecScatterBegin(ctx,x,y,INSERT_VALUES,SCATTER_FORWARD);
 35:   VecScatterEnd(ctx,x,y,INSERT_VALUES,SCATTER_FORWARD);
 36:   VecScatterDestroy(&ctx);

 38:   VecView(y,PETSC_VIEWER_STDOUT_SELF);

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

 45:   PetscFinalize();
 46:   return ierr;
 47: }



 51: /*TEST

 53:    test:

 55: TEST*/