Actual source code: ex2.c

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

      4: /*T
      5:     Concepts: index sets^creating a stride index set;
      6:     Concepts: stride^creating a stride index set;
      7:     Concepts: IS^creating a stride index set;
      8:
      9:     Description: Creates an index set based on a stride. Views that index set
     10:     and then destroys it.
     11: T*/

     13: /*
     14:   Include petscis.h so we can use PETSc IS objects. Note that this automatically
     15:   includes petsc.h.
     16: */

     18:  #include petscis.h

     22: int main(int argc,char **argv)
     23: {
     25:   PetscInt       i,n,*indices,first,step;
     26:   IS             set;

     28:   PetscInitialize(&argc,&argv,(char*)0,help);
     29:
     30:   n     = 10;
     31:   first = 3;
     32:   step  = 2;

     34:   /*
     35:     Create stride index set, starting at 3 with a stride of 2
     36:     Note each processor is generating its own index set
     37:     (in this case they are all identical)
     38:   */
     39:   ISCreateStride(PETSC_COMM_SELF,n,first,step,&set);
     40:   ISView(set,PETSC_VIEWER_STDOUT_SELF);

     42:   /*
     43:     Extract indices from set.
     44:   */
     45:   ISGetIndices(set,&indices);
     46:   PetscPrintf(PETSC_COMM_WORLD,"Printing indices directly\n");
     47:   for (i=0; i<n; i++) {
     48:     PetscPrintf(PETSC_COMM_WORLD,"%D\n",indices[i]);
     49:   }

     51:   ISRestoreIndices(set,&indices);

     53:   /*
     54:       Determine information on stride
     55:   */
     56:   ISStrideGetInfo(set,&first,&step);
     57:   if (first != 3 || step != 2) SETERRQ(1,"Stride info not correct!\n");
     58:   ISDestroy(set);
     59:   PetscFinalize();
     60:   return 0;
     61: }