Actual source code: ex2.c
2: static char help[] = "Demonstrates creating a stride index set.\n\n";
4: /*
5: Include petscis.h so we can use PETSc IS objects. Note that this automatically
6: includes petscsys.h.
7: */
9: #include <petscis.h>
10: #include <petscviewer.h>
12: int main(int argc,char **argv)
13: {
14: PetscInt i,n,first,step;
15: IS set;
16: const PetscInt *indices;
18: PetscInitialize(&argc,&argv,(char*)0,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: ISCreateStride(PETSC_COMM_SELF,n,first,step,&set);
30: ISView(set,PETSC_VIEWER_STDOUT_SELF);
32: /*
33: Extract indices from set.
34: */
35: ISGetIndices(set,&indices);
36: PetscPrintf(PETSC_COMM_WORLD,"Printing indices directly\n");
37: for (i=0; i<n; i++) {
38: PetscPrintf(PETSC_COMM_WORLD,"%" PetscInt_FMT "\n",indices[i]);
39: }
41: ISRestoreIndices(set,&indices);
43: /*
44: Determine information on stride
45: */
46: ISStrideGetInfo(set,&first,&step);
48: ISDestroy(&set);
49: PetscFinalize();
50: return 0;
51: }
53: /*TEST
55: test:
57: TEST*/