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