Actual source code: ex2.c

      1: static char help[] = "Demonstrates creating a stride index set.\n\n";

      3: /*
      4:   Include petscis.h so we can use PETSc IS objects. Note that this automatically
      5:   includes petscsys.h.
      6: */

      8: #include <petscis.h>
      9: #include <petscviewer.h>

     11: int main(int argc, char **argv)
     12: {
     13:   PetscInt        i, n, first, step;
     14:   IS              set;
     15:   const PetscInt *indices;

     17:   PetscFunctionBeginUser;
     18:   PetscCall(PetscInitialize(&argc, &argv, NULL, help));

     20:   n     = 10;
     21:   first = 3;
     22:   step  = 2;

     24:   /*
     25:     Create stride index set, starting at 3 with a stride of 2
     26:     Note each processor is generating its own index set
     27:     (in this case they are all identical)
     28:   */
     29:   PetscCall(ISCreateStride(PETSC_COMM_SELF, n, first, step, &set));
     30:   PetscCall(ISView(set, PETSC_VIEWER_STDOUT_SELF));

     32:   /*
     33:     Extract indices from set.
     34:   */
     35:   PetscCall(ISGetIndices(set, &indices));
     36:   PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Printing indices directly\n"));
     37:   for (i = 0; i < n; i++) PetscCall(PetscPrintf(PETSC_COMM_WORLD, "%" PetscInt_FMT "\n", indices[i]));

     39:   PetscCall(ISRestoreIndices(set, &indices));

     41:   /*
     42:       Determine information on stride
     43:   */
     44:   PetscCall(ISStrideGetInfo(set, &first, &step));
     45:   PetscCheck(first == 3 && step == 2, PETSC_COMM_SELF, PETSC_ERR_PLIB, "Stride info not correct!");
     46:   PetscCall(ISDestroy(&set));
     47:   PetscCall(PetscFinalize());
     48:   return 0;
     49: }

     51: /*TEST

     53:    test:

     55: TEST*/