Actual source code: ex4.c


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

  4: #include <petscvec.h>

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

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

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

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

 31:   VecSet(x,one);
 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:   if (rank == 0) VecView(y,PETSC_VIEWER_STDOUT_SELF);

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

 43:   VecDestroy(&x);
 44:   VecDestroy(&y);
 45:   PetscFinalize();
 46:   return 0;
 47: }

 49: /*TEST

 51:    test:
 52:       nsize: 2
 53:       filter: grep -v type
 54:       diff_args: -j

 56:    test:
 57:       diff_args: -j
 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:       diff_args: -j
 66:       suffix: cuda2
 67:       nsize: 2
 68:       args: -vec_type cuda
 69:       output_file: output/ex4_1.out
 70:       filter: grep -v type
 71:       requires: cuda

 73:    test:
 74:       diff_args: -j
 75:       suffix: kokkos
 76:       args: -vec_type kokkos
 77:       output_file: output/ex4_1.out
 78:       filter: grep -v type
 79:       requires: kokkos_kernels

 81:    test:
 82:       diff_args: -j
 83:       suffix: kokkos2
 84:       nsize: 2
 85:       args: -vec_type kokkos
 86:       output_file: output/ex4_1.out
 87:       filter: grep -v type
 88:       requires: !sycl kokkos_kernels

 90:    testset:
 91:       diff_args: -j
 92:       requires: hip
 93:       filter: grep -v type
 94:       args: -vec_type hip
 95:       output_file: output/ex4_1.out
 96:       test:
 97:         suffix: hip
 98:       test:
 99:         suffix: hip2
100:         nsize: 2
101: TEST*/