Actual source code: ex7.c

petsc-3.6.1 2015-08-06
Report Typos and Errors
  2: static char help[] = "Tests PetscSortIntWithPermutation().\n\n";

  4: #include <petscsys.h>

  8: int main(int argc,char **argv)
  9: {
 10:   PetscInt       i;
 11:   PetscInt       x[]  = {39, 9, 39, 39, 29},index[5];
 12:   PetscInt       x2[] = {39, 9, 19, 39, 29, 39, 29, 39},index2[8];

 15:   PetscInitialize(&argc,&argv,(char*)0,help);
 16:   printf("1st test\n");
 17:   for (i=0; i<5; i++) index[i] = i;
 18:   PetscSortIntWithPermutation(5, x, index);
 19:   for (i=0; i<5; i++) printf(" %d     %d     %d\n",x[i], index[i],x[index[i]]);

 21:   printf("\n2nd test\n");
 22:   for (i=0; i<8; i++) index2[i] = i;
 23:   PetscSortIntWithPermutation(8, x2, index2);
 24:   for (i=0; i<8; i++) printf(" %d     %d     %d\n",x2[i], index2[i],x2[index2[i]]);
 25:   PetscFinalize();
 26:   return 0;
 27: }