perfmodel_nan.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 Centre National de la Recherche Scientifique
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #ifndef _GNU_SOURCE
  17. #define _GNU_SOURCE
  18. #endif
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <math.h>
  22. #include <string.h>
  23. #include <config.h>
  24. #include <core/perfmodel/perfmodel.h>
  25. #ifdef STARPU_HAVE_WINDOWS
  26. static
  27. void _starpu_read_spaces(FILE *f)
  28. {
  29. int c = getc(f);
  30. if (c == ' ')
  31. {
  32. while (c == ' ') c = getc(f);
  33. }
  34. else
  35. {
  36. ungetc(c, f);
  37. }
  38. }
  39. #endif /* STARPU_HAVE_WINDOWS */
  40. int _starpu_read_double(FILE *f, char *format, double *val)
  41. {
  42. #ifdef STARPU_HAVE_WINDOWS
  43. /** Windows cannot read NAN values, yes, it is really bad ... */
  44. int x1 = getc(f);
  45. if (x1 == 'n')
  46. {
  47. int x2 = getc(f);
  48. int x3 = getc(f);
  49. if (x2 == 'a' && x3 == 'n')
  50. {
  51. _starpu_read_spaces(f);
  52. *val = NAN;
  53. return 1;
  54. }
  55. else
  56. {
  57. return 0;
  58. }
  59. }
  60. else
  61. {
  62. ungetc(x1, f);
  63. return fscanf(f, format, val);
  64. }
  65. #else
  66. return fscanf(f, format, val);
  67. #endif
  68. }