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: #undef __FUNCT__
23: int main(int argc,char **argv)
24: {
25: int ierr,*indices,rank,n;
26: IS is;
28: PetscInitialize(&argc,&argv,(char*)0,help);
29: MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
31: /*
32: Create an index set with 5 entries. Each processor creates
33: its own index set with its own list of integers.
34: */
35: PetscMalloc(5*sizeof(int),&indices);
36: indices[0] = rank + 1;
37: indices[1] = rank + 2;
38: indices[2] = rank + 3;
39: indices[3] = rank + 4;
40: indices[4] = rank + 5;
41: ISCreateGeneral(PETSC_COMM_SELF,5,indices,&is);
42: /*
43: Note that ISCreateGeneral() has made a copy of the indices
44: so we may (and generally should) free indices[]
45: */
46: PetscFree(indices);
48: /*
49: Print the index set to stdout
50: */
51: ISView(is,PETSC_VIEWER_STDOUT_SELF);
53: /*
54: Get the number of indices in the set
55: */
56: ISGetLocalSize(is,&n);
58: /*
59: Get the indices in the index set
60: */
61: ISGetIndices(is,&indices);
62: /*
63: Now any code that needs access to the list of integers
64: has access to it here through indices[].
65: */
66: PetscPrintf(PETSC_COMM_SELF,"[%d] First index %dn",rank,indices[0]);
68: /*
69: Once we no longer need access to the indices they should
70: returned to the system
71: */
72: ISRestoreIndices(is,&indices);
74: /*
75: One should destroy any PETSc object once one is completely
76: done with it.
77: */
78: ISDestroy(is);
79: PetscFinalize();
80: return 0;
81: }
82: