Actual source code: ex4.c
petsc-3.12.4 2020-02-04
Report Typos and Errors

      2: static char help[] = "Scatters from a parallel vector into seqential vectors.\n\n";

      4:  #include <petscvec.h>

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

     16:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
     17:   PetscOptionsGetInt(NULL,NULL,"-n",&n,NULL);
     18:   MPI_Comm_rank(PETSC_COMM_WORLD,&rank);

     20:   /* create two vectors */
     21:   VecCreate(PETSC_COMM_WORLD,&x);
     22:   VecSetSizes(x,n,PETSC_DECIDE);
     23:   VecSetFromOptions(x);
     24:   VecCreate(PETSC_COMM_SELF,&y);
     25:   VecSetSizes(y,n,PETSC_DECIDE);
     26:   VecSetFromOptions(y);

     28:   /* create two index sets */
     29:   ISCreateGeneral(PETSC_COMM_SELF,2,idx1,PETSC_COPY_VALUES,&is1);
     30:   ISCreateGeneral(PETSC_COMM_SELF,2,idx2,PETSC_COPY_VALUES,&is2);

     32:   VecSet(x,one);
     33:   VecSet(y,two);
     34:   VecScatterCreate(x,is1,y,is2,&ctx);
     35:   VecScatterBegin(ctx,x,y,INSERT_VALUES,SCATTER_FORWARD);
     36:   VecScatterEnd(ctx,x,y,INSERT_VALUES,SCATTER_FORWARD);
     37:   VecScatterDestroy(&ctx);

     39:   if (!rank) {VecView(y,PETSC_VIEWER_STDOUT_SELF);}

     41:   ISDestroy(&is1);
     42:   ISDestroy(&is2);

     44:   VecDestroy(&x);
     45:   VecDestroy(&y);
     46:   PetscFinalize();
     47:   return ierr;
     48: }

     51: /*TEST

     53:    test:
     54:       nsize: 2
     55:       filter: grep -v type

     57:    test:
     58:       suffix: cuda
     59:       args: -vec_type cuda
     60:       output_file: output/ex4_1.out
     61:       filter: grep -v type
     62:       requires: cuda

     64:    test:
     65:       suffix: cuda2
     66:       nsize: 2
     67:       args: -vec_type cuda
     68:       output_file: output/ex4_1.out
     69:       filter: grep -v type
     70:       requires: cuda

     72: TEST*/