perfmodel_nan.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #include <ctype.h>
  26. #ifdef STARPU_HAVE_WINDOWS
  27. static
  28. void _starpu_read_spaces(FILE *f)
  29. {
  30. int c = getc(f);
  31. if (isspace(c))
  32. {
  33. while (isspace(c)) c = getc(f);
  34. ungetc(c, f);
  35. }
  36. else
  37. {
  38. ungetc(c, f);
  39. }
  40. }
  41. #endif /* STARPU_HAVE_WINDOWS */
  42. int _starpu_read_double(FILE *f, char *format, double *val)
  43. {
  44. #ifdef STARPU_HAVE_WINDOWS
  45. /** Windows cannot read NAN values, yes, it is really bad ... */
  46. int x1 = getc(f);
  47. if (x1 == 'n')
  48. {
  49. int x2 = getc(f);
  50. int x3 = getc(f);
  51. if (x2 == 'a' && x3 == 'n')
  52. {
  53. _starpu_read_spaces(f);
  54. *val = NAN;
  55. return 1;
  56. }
  57. else
  58. {
  59. return 0;
  60. }
  61. }
  62. else
  63. {
  64. ungetc(x1, f);
  65. return fscanf(f, format, val);
  66. }
  67. #else
  68. return fscanf(f, format, val);
  69. #endif
  70. }