1 2 static char help[] = "Demonstrates a scatter with a stride and general index set.\n\n"; 3 4 #include <petscvec.h> 5 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; 13 14 PetscFunctionBeginUser; 15 PetscCall(PetscInitialize(&argc, &argv, (char *)0, help)); 16 17 /* create two vectors */ 18 PetscCall(VecCreateSeq(PETSC_COMM_SELF, n, &x)); 19 PetscCall(VecDuplicate(x, &y)); 20 21 /* create two index sets */ 22 PetscCall(ISCreateStride(PETSC_COMM_SELF, 3, 0, 2, &is1)); 23 PetscCall(ISCreateGeneral(PETSC_COMM_SELF, 3, idx1, PETSC_COPY_VALUES, &is2)); 24 25 PetscCall(VecSetValues(x, 6, loc, vals, INSERT_VALUES)); 26 PetscCall(VecView(x, PETSC_VIEWER_STDOUT_SELF)); 27 PetscCall(PetscPrintf(PETSC_COMM_SELF, "----\n")); 28 PetscCall(VecSet(y, two)); 29 PetscCall(VecScatterCreate(x, is1, y, is2, &ctx)); 30 PetscCall(VecScatterBegin(ctx, x, y, INSERT_VALUES, SCATTER_FORWARD)); 31 PetscCall(VecScatterEnd(ctx, x, y, INSERT_VALUES, SCATTER_FORWARD)); 32 PetscCall(VecScatterDestroy(&ctx)); 33 34 PetscCall(VecView(y, PETSC_VIEWER_STDOUT_SELF)); 35 36 PetscCall(ISDestroy(&is1)); 37 PetscCall(ISDestroy(&is2)); 38 PetscCall(VecDestroy(&x)); 39 PetscCall(VecDestroy(&y)); 40 41 PetscCall(PetscFinalize()); 42 return 0; 43 } 44 45 /*TEST 46 47 test: 48 49 TEST*/ 50