starpu-util.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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 __STARPU_UTIL_H__
  17. #define __STARPU_UTIL_H__
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <assert.h>
  22. #include <starpu_config.h>
  23. #define STARPU_MIN(a,b) ((a)<(b)?(a):(b))
  24. #define STARPU_MAX(a,b) ((a)<(b)?(b):(a))
  25. #define STARPU_ASSERT(x) assert(x)
  26. #define STARPU_UNLIKELY(expr) (__builtin_expect(!!(expr),0))
  27. #define STARPU_LIKELY(expr) (__builtin_expect(!!(expr),1))
  28. #ifdef HAVE_SYNC_BUILTINS
  29. #define STARPU_ATOMIC_ADD(ptr, value) (__sync_fetch_and_add ((ptr), (value)) + (value))
  30. #define STARPU_ATOMIC_OR(ptr, value) (__sync_fetch_and_or ((ptr), (value)))
  31. #else
  32. #error __sync_fetch_and_add is not available
  33. #endif
  34. #define STARPU_SUCCESS 0
  35. #define STARPU_TRYAGAIN 1
  36. #define STARPU_FATAL 2
  37. static int __attribute__ ((unused)) starpu_get_env_number(const char *str)
  38. {
  39. char *strval;
  40. strval = getenv(str);
  41. if (strval) {
  42. /* the env variable was actually set */
  43. unsigned val;
  44. char *check;
  45. val = (int)strtol(strval, &check, 10);
  46. STARPU_ASSERT(strcmp(check, "\0") == 0);
  47. //fprintf(stderr, "ENV %s WAS %d\n", str, val);
  48. return val;
  49. }
  50. else {
  51. /* there is no such env variable */
  52. //fprintf("There was no %s ENV\n", str);
  53. return -1;
  54. }
  55. }
  56. #endif // __STARPU_UTIL_H__