utils.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2012-2014 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #ifndef __COMMON_UTILS_H__
  18. #define __COMMON_UTILS_H__
  19. #include <starpu.h>
  20. #include <common/config.h>
  21. #include <sys/stat.h>
  22. #include <string.h>
  23. #include <stdlib.h>
  24. #include <math.h>
  25. #include <pthread.h>
  26. #ifdef STARPU_HAVE_SCHED_YIELD
  27. #include <sched.h>
  28. #endif
  29. #ifdef STARPU_HAVE_HELGRIND_H
  30. #include <valgrind/helgrind.h>
  31. #endif
  32. #ifndef DO_CREQ_v_WW
  33. #define DO_CREQ_v_WW(_creqF, _ty1F, _arg1F, _ty2F, _arg2F) ((void)0)
  34. #endif
  35. #ifndef DO_CREQ_v_W
  36. #define DO_CREQ_v_W(_creqF, _ty1F, _arg1F) ((void)0)
  37. #endif
  38. #ifndef ANNOTATE_HAPPENS_BEFORE
  39. #define ANNOTATE_HAPPENS_BEFORE(obj) ((void)0)
  40. #endif
  41. #ifndef ANNOTATE_HAPPENS_AFTER
  42. #define ANNOTATE_HAPPENS_AFTER(obj) ((void)0)
  43. #endif
  44. #ifndef VALGRIND_HG_DISABLE_CHECKING
  45. #define VALGRIND_HG_DISABLE_CHECKING(start, len) ((void)0)
  46. #endif
  47. #ifndef VALGRIND_HG_ENABLE_CHECKING
  48. #define VALGRIND_HG_ENABLE_CHECKING(start, len) ((void)0)
  49. #endif
  50. #ifndef RUNNING_ON_VALGRIND
  51. #define RUNNING_ON_VALGRIND 0
  52. #endif
  53. #define STARPU_HG_DISABLE_CHECKING(variable) VALGRIND_HG_DISABLE_CHECKING(&(variable), sizeof(variable))
  54. #define STARPU_HG_ENABLE_CHECKING(variable) VALGRIND_HG_ENABLE_CHECKING(&(variable), sizeof(variable))
  55. #if defined(__KNC__) || defined(__KNF__)
  56. #define STARPU_DEBUG_PREFIX "[starpu-mic]"
  57. #else
  58. #define STARPU_DEBUG_PREFIX "[starpu]"
  59. #endif
  60. /* This is needed in some places to make valgrind yield to another thread to be
  61. * able to progress. */
  62. #if defined(__i386__) || defined(__x86_64__)
  63. #define _STARPU_UYIELD() __asm__ __volatile("rep; nop")
  64. #else
  65. #define _STARPU_UYIELD() ((void)0)
  66. #endif
  67. #if defined(STARPU_HAVE_SCHED_YIELD) && defined(STARPU_HAVE_HELGRIND_H)
  68. #define STARPU_UYIELD() do { if (RUNNING_ON_VALGRIND) sched_yield(); else _STARPU_UYIELD(); } while (0)
  69. #else
  70. #define STARPU_UYIELD() _STARPU_UYIELD()
  71. #endif
  72. #ifdef STARPU_VERBOSE
  73. # define _STARPU_DEBUG(fmt, ...) do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%s] " fmt ,__starpu_func__ ,## __VA_ARGS__); fflush(stderr); }} while(0)
  74. #else
  75. # define _STARPU_DEBUG(fmt, ...) do { } while (0)
  76. #endif
  77. #ifdef STARPU_EXTRA_VERBOSE
  78. # define _STARPU_LOG_IN() do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%ld][%s:%s@%d] -->\n", pthread_self(), __starpu_func__,__FILE__, __LINE__); }} while(0)
  79. # define _STARPU_LOG_OUT() do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%ld][%s:%s@%d] <--\n", pthread_self(), __starpu_func__, __FILE__, __LINE__); }} while(0)
  80. # define _STARPU_LOG_OUT_TAG(outtag) do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%ld][%s:%s@%d] <-- (%s)\n", pthread_self(), __starpu_func__, __FILE__, __LINE__, outtag); }} while(0)
  81. #else
  82. # define _STARPU_LOG_IN()
  83. # define _STARPU_LOG_OUT()
  84. # define _STARPU_LOG_OUT_TAG(outtag)
  85. #endif
  86. #define _STARPU_DISP(fmt, ...) do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%s] " fmt ,__starpu_func__ ,## __VA_ARGS__); }} while(0)
  87. #define _STARPU_ERROR(fmt, ...) \
  88. do { \
  89. fprintf(stderr, "\n\n[starpu][%s] Error: " fmt ,__starpu_func__ ,## __VA_ARGS__); \
  90. fprintf(stderr, "\n\n"); \
  91. STARPU_ABORT(); \
  92. } while (0)
  93. #ifdef _MSC_VER
  94. #define _STARPU_IS_ZERO(a) (a == 0.0)
  95. #else
  96. #define _STARPU_IS_ZERO(a) (fpclassify(a) == FP_ZERO)
  97. #endif
  98. int _starpu_mkpath(const char *s, mode_t mode);
  99. void _starpu_mkpath_and_check(const char *s, mode_t mode);
  100. int _starpu_ftruncate(FILE *file);
  101. int _starpu_frdlock(FILE *file);
  102. int _starpu_frdunlock(FILE *file);
  103. int _starpu_fwrlock(FILE *file);
  104. int _starpu_fwrunlock(FILE *file);
  105. char *_starpu_get_home_path(void);
  106. void _starpu_gethostname(char *hostname, size_t size);
  107. /* If FILE is currently on a comment line, eat it. */
  108. void _starpu_drop_comments(FILE *f);
  109. struct _starpu_job;
  110. /* Returns the symbol associated to that job if any. */
  111. const char *_starpu_job_get_model_name(struct _starpu_job *j);
  112. struct starpu_codelet;
  113. /* Returns the symbol associated to that job if any. */
  114. const char *_starpu_codelet_get_model_name(struct starpu_codelet *cl);
  115. int _starpu_check_mutex_deadlock(starpu_pthread_mutex_t *mutex);
  116. void _starpu_sleep(struct timespec ts);
  117. #endif // __COMMON_UTILS_H__