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;
10: Description: Creates an index set based on a set of integers. Views that index set
11: and then destroys it.
12:
13: T*/
14:
15: /*
16: Include petscis.h so we can use PETSc IS objects. Note that this automatically
17: includes petsc.h.
18: */
19: #include petscis.h
21: int main(int argc,char **argv)
22: {
23: int ierr,*indices,rank,n;
24: IS is;
26: PetscInitialize(&argc,&argv,(char*)0,help);
27: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
29: /*
30: Create an index set with 5 entries. Each processor creates
31: its own index set with its own list of integers.
32: */
33: PetscMalloc(5*sizeof(int),&indices);
34: indices[0] = rank + 1;
35: indices[1] = rank + 2;
36: indices[2] = rank + 3;
37: indices[3] = rank + 4;
38: indices[4] = rank + 5;
39: ISCreateGeneral(PETSC_COMM_SELF,5,indices,&is);
40: /*
41: Note that ISCreateGeneral() has made a copy of the indices
42: so we may (and generally should) free indices[]
43: */
44: PetscFree(indices);
46: /*
47: Print the index set to stdout
48: */
49: ISView(is,PETSC_VIEWER_STDOUT_SELF);
51: /*
52: Get the number of indices in the set
53: */
54: ISGetLocalSize(is,&n);
56: /*
57: Get the indices in the index set
58: */
59: ISGetIndices(is,&indices);
60: /*
61: Now any code that needs access to the list of integers
62: has access to it here through indices[].
63: */
64: PetscPrintf(PETSC_COMM_SELF,"[%d] First index %dn",rank,indices[0]);
66: /*
67: Once we no longer need access to the indices they should
68: returned to the system
69: */
70: ISRestoreIndices(is,&indices);
72: /*
73: One should destroy any PETSc object once one is completely
74: done with it.
75: */
76: ISDestroy(is);
77: PetscFinalize();
78: return 0;
79: }
80: