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};

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

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

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

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

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

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

 55: /*TEST

 57:    test:

 59: TEST*/