Actual source code: ex2.c

  2: /*      "$Id: ex2.c,v 1.20 2001/03/23 23:21:14 balay Exp $"; */

  4: static char help[] = "Demonstrates creating a stride index set.nn";

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

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

 20:  #include petscis.h

 22: #undef __FUNCT__
 24: int main(int argc,char **argv)
 25: {
 26:   int i,n,ierr, *indices,first,step;
 27:   IS  set;

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

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

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

 52:   ISRestoreIndices(set,&indices);

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