Actual source code: ex1.c
1: /*$Id: ex1.c,v 1.27 2001/03/23 23:21:14 balay Exp $*/
3: static char help[] = "Creating a general index set.nn";
5: /*T
6: Concepts: index sets^manipulating a general index set;
7: Concepts: index sets^creating general;
8: Concepts: IS^creating a general index set;
9:
10: Comment: Creates an index set based on a set of integers. Views that index set
11: and then destroys it.
12: T*/
13:
14: /*
15: Include petscis.h so we can use PETSc IS objects. Note that this automatically
16: includes petsc.h.
17: */
18: #include "petscis.h"
20: int main(int argc,char **argv)
21: {
22: int ierr,*indices,rank,n;
23: IS is;
25: PetscInitialize(&argc,&argv,(char*)0,help);
26: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
28: /*
29: Create an index set with 5 entries. Each processor creates
30: its own index set with its own list of integers.
31: */
32: PetscMalloc(5*sizeof(int),&indices);
33: indices[0] = rank + 1;
34: indices[1] = rank + 2;
35: indices[2] = rank + 3;
36: indices[3] = rank + 4;
37: indices[4] = rank + 5;
38: ISCreateGeneral(PETSC_COMM_SELF,5,indices,&is);
39: /*
40: Note that ISCreateGeneral() has made a copy of the indices
41: so we may (and generally should) free indices[]
42: */
43: PetscFree(indices);
45: /*
46: Print the index set to stdout
47: */
48: ISView(is,PETSC_VIEWER_STDOUT_SELF);
50: /*
51: Get the number of indices in the set
52: */
53: ISGetLocalSize(is,&n);
55: /*
56: Get the indices in the index set
57: */
58: ISGetIndices(is,&indices);
59: /*
60: Now any code that needs access to the list of integers
61: has access to it here through indices[].
62: */
63: PetscPrintf(PETSC_COMM_SELF,"[%d] First index %dn",rank,indices[0]);
65: /*
66: Once we no longer need access to the indices they should
67: returned to the system
68: */
69: ISRestoreIndices(is,&indices);
71: /*
72: One should destroy any PETSc object once one is completely
73: done with it.
74: */
75: ISDestroy(is);
76: PetscFinalize();
77: return 0;
78: }
79: