Actual source code: ex1.c
1: /*
2: Formatted test for ISGeneral routines.
3: */
5: static char help[] = "Tests IS general routines.\n\n";
7: #include <petscis.h>
8: #include <petscviewer.h>
10: int main(int argc, char **argv)
11: {
12: PetscMPIInt rank, size;
13: PetscInt i, n, *indices;
14: const PetscInt *ii;
15: IS is, newis;
16: PetscBool flg;
17: PetscBool permanent = PETSC_FALSE;
18: PetscBool compute = PETSC_TRUE;
21: PetscInitialize(&argc, &argv, (char *)0, help);
22: MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
23: MPI_Comm_size(PETSC_COMM_WORLD, &size);
25: /*
26: Test IS of size 0
27: */
28: ISCreateGeneral(PETSC_COMM_SELF, 0, &n, PETSC_COPY_VALUES, &is);
29: ISGetSize(is, &n);
31: ISDestroy(&is);
33: /*
34: Create large IS and test ISGetIndices()
35: */
36: n = 10000 + rank;
37: PetscMalloc1(n, &indices);
38: for (i = 0; i < n; i++) indices[i] = rank + i;
39: ISCreateGeneral(PETSC_COMM_SELF, n, indices, PETSC_COPY_VALUES, &is);
40: ISGetIndices(is, &ii);
42: ISRestoreIndices(is, &ii);
44: /*
45: Check identity and permutation
46: */
47: /* ISPermutation doesn't check if not set */
48: ISPermutation(is, &flg);
50: ISGetInfo(is, IS_PERMUTATION, IS_LOCAL, compute, &flg);
53: ISIdentity(is, &flg);
56: ISGetInfo(is, IS_IDENTITY, IS_LOCAL, compute, &flg);
59: /* we can override the computed values with ISSetInfo() */
60: ISSetInfo(is, IS_PERMUTATION, IS_LOCAL, permanent, PETSC_TRUE);
61: ISSetInfo(is, IS_IDENTITY, IS_LOCAL, permanent, PETSC_TRUE);
62: ISGetInfo(is, IS_PERMUTATION, IS_LOCAL, compute, &flg);
64: ISGetInfo(is, IS_IDENTITY, IS_LOCAL, compute, &flg);
67: ISClearInfoCache(is, PETSC_TRUE);
69: /*
70: Check equality of index sets
71: */
72: ISEqual(is, is, &flg);
75: /*
76: Sorting
77: */
78: ISSort(is);
79: ISSorted(is, &flg);
81: ISGetInfo(is, IS_SORTED, IS_LOCAL, compute, &flg);
83: ISSorted(is, &flg);
85: ISGetInfo(is, IS_SORTED, IS_LOCAL, compute, &flg);
88: /*
89: Thinks it is a different type?
90: */
91: PetscObjectTypeCompare((PetscObject)is, ISSTRIDE, &flg);
93: PetscObjectTypeCompare((PetscObject)is, ISBLOCK, &flg);
96: ISDestroy(&is);
98: /*
99: Inverting permutation
100: */
101: for (i = 0; i < n; i++) indices[i] = n - i - 1;
102: ISCreateGeneral(PETSC_COMM_SELF, n, indices, PETSC_COPY_VALUES, &is);
103: PetscFree(indices);
104: ISSetPermutation(is);
105: ISInvertPermutation(is, PETSC_DECIDE, &newis);
106: ISGetIndices(newis, &ii);
108: ISRestoreIndices(newis, &ii);
109: ISDestroy(&newis);
110: ISDestroy(&is);
111: PetscFinalize();
112: return 0;
113: }
115: /*TEST
117: test:
118: nsize: {{1 2 3 4 5}}
120: TEST*/