Actual source code: ex7.c
1: static char help[] = "Tests PetscSortIntWithPermutation().\n\n";
3: #include <petscsys.h>
5: int main(int argc, char **argv)
6: {
7: PetscInt x[] = {39, 9, 39, 39, 29}, index[5];
8: PetscInt x2[] = {39, 9, 19, 39, 29, 39, 29, 39}, index2[8];
10: PetscFunctionBeginUser;
11: PetscCall(PetscInitialize(&argc, &argv, NULL, help));
12: PetscCall(PetscPrintf(PETSC_COMM_SELF, "1st test\n"));
13: for (PetscInt i = 0; i < 5; i++) index[i] = i;
14: PetscCall(PetscSortIntWithPermutation(5, x, index));
15: for (PetscInt i = 0; i < 5; i++) PetscCall(PetscPrintf(PETSC_COMM_SELF, " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT "\n", x[i], index[i], x[index[i]]));
17: PetscCall(PetscPrintf(PETSC_COMM_SELF, "\n2nd test\n"));
18: for (PetscInt i = 0; i < 8; i++) index2[i] = i;
19: PetscCall(PetscSortIntWithPermutation(8, x2, index2));
20: for (PetscInt i = 0; i < 8; i++) PetscCall(PetscPrintf(PETSC_COMM_SELF, " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT "\n", x2[i], index2[i], x2[index2[i]]));
21: PetscCall(PetscFinalize());
22: return 0;
23: }
25: /*TEST
27: test:
29: TEST*/