Actual source code: ex35.c

  1: static char help[] = "Tests PetscSortReal(), PetscSortRealWithArrayInt(), PetscFindReal\n\n";

  3: #include <petscsys.h>

  5: int main(int argc, char **argv)
  6: {
  7:   PetscInt  i, loc;
  8:   PetscReal val;
  9:   PetscReal x[]      = {39, 9, 19, -39, 29, 309, 209, 390, 12, 11};
 10:   PetscReal x2[]     = {39, 9, 19, -39, 29, 309, 209, 390, 12, 11};
 11:   PetscReal x3[]     = {39, 9, 19, -39, 29, 309, 209, 390, 12, 11};
 12:   PetscInt  index2[] = {1, -1, 4, 12, 13, 14, 0, 7, 9, 11};
 13:   PetscInt  index3[] = {1, -1, 4, 12, 13, 14, 0, 7, 9, 11};

 16:   PetscInitialize(&argc, &argv, (char *)0, help);
 17:   PetscPrintf(PETSC_COMM_SELF, "1st test\n");
 18:   for (i = 0; i < 5; i++) PetscPrintf(PETSC_COMM_SELF, " %g\n", (double)x[i]);
 19:   PetscPrintf(PETSC_COMM_SELF, "---------------\n");
 20:   PetscSortReal(5, x);
 21:   for (i = 0; i < 5; i++) PetscPrintf(PETSC_COMM_SELF, " %g\n", (double)x[i]);

 23:   PetscPrintf(PETSC_COMM_SELF, "\n2nd test\n");
 24:   for (i = 0; i < 10; i++) PetscPrintf(PETSC_COMM_SELF, " %g\n", (double)x[i]);
 25:   PetscPrintf(PETSC_COMM_SELF, "---------------\n");
 26:   PetscSortReal(10, x);
 27:   for (i = 0; i < 10; i++) PetscPrintf(PETSC_COMM_SELF, " %g\n", (double)x[i]);

 29:   PetscPrintf(PETSC_COMM_SELF, "\n3rd test\n");
 30:   for (i = 0; i < 5; i++) PetscPrintf(PETSC_COMM_SELF, " %2" PetscInt_FMT "     %g\n", index2[i], (double)x2[i]);
 31:   PetscPrintf(PETSC_COMM_SELF, "---------------\n");
 32:   PetscSortRealWithArrayInt(5, x2, index2);
 33:   for (i = 0; i < 5; i++) PetscPrintf(PETSC_COMM_SELF, " %2" PetscInt_FMT "     %g\n", index2[i], (double)x2[i]);

 35:   PetscPrintf(PETSC_COMM_SELF, "\n4th test\n");
 36:   for (i = 0; i < 10; i++) PetscPrintf(PETSC_COMM_SELF, " %2" PetscInt_FMT "     %g\n", index3[i], (double)x3[i]);
 37:   PetscPrintf(PETSC_COMM_SELF, "---------------\n");
 38:   PetscSortRealWithArrayInt(10, x3, index3);
 39:   for (i = 0; i < 10; i++) PetscPrintf(PETSC_COMM_SELF, " %2" PetscInt_FMT "     %g\n", index3[i], (double)x3[i]);

 41:   PetscPrintf(PETSC_COMM_SELF, "\n5th test\n");
 42:   val = 44;
 43:   PetscFindReal(val, 10, x3, PETSC_SMALL, &loc);
 44:   PetscPrintf(PETSC_COMM_SELF, " %g in array: loc %" PetscInt_FMT "\n", (double)val, loc);
 45:   val = 309.2;
 46:   PetscFindReal(val, 10, x3, PETSC_SMALL, &loc);
 47:   PetscPrintf(PETSC_COMM_SELF, " %g in array: loc %" PetscInt_FMT "\n", (double)val, loc);
 48:   val = 309.2;
 49:   PetscFindReal(val, 10, x3, 0.21, &loc);
 50:   PetscPrintf(PETSC_COMM_SELF, " %g in array: loc %" PetscInt_FMT "\n", (double)val, loc);

 52:   PetscFinalize();
 53:   return 0;
 54: }

 56: /*TEST

 58:    test:

 60: TEST*/