utils.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2012-2013 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_HELGRIND_H
  27. #include <valgrind/helgrind.h>
  28. #endif
  29. #ifndef VALGRIND_HG_MUTEX_LOCK_PRE
  30. #define VALGRIND_HG_MUTEX_LOCK_PRE(mutex, istrylock) ((void)0)
  31. #endif
  32. #ifndef VALGRIND_HG_MUTEX_LOCK_POST
  33. #define VALGRIND_HG_MUTEX_LOCK_POST(mutex) ((void)0)
  34. #endif
  35. #ifndef VALGRIND_HG_MUTEX_UNLOCK_PRE
  36. #define VALGRIND_HG_MUTEX_UNLOCK_PRE(mutex) ((void)0)
  37. #endif
  38. #ifndef VALGRIND_HG_MUTEX_UNLOCK_POST
  39. #define VALGRIND_HG_MUTEX_UNLOCK_POST(mutex) ((void)0)
  40. #endif
  41. #ifndef DO_CREQ_v_WW
  42. #define DO_CREQ_v_WW(_creqF, _ty1F, _arg1F, _ty2F, _arg2F) ((void)0)
  43. #endif
  44. #ifndef DO_CREQ_v_W
  45. #define DO_CREQ_v_W(_creqF, _ty1F, _arg1F) ((void)0)
  46. #endif
  47. #ifndef ANNOTATE_HAPPENS_BEFORE
  48. #define ANNOTATE_HAPPENS_BEFORE(obj) ((void)0)
  49. #endif
  50. #ifndef ANNOTATE_HAPPENS_AFTER
  51. #define ANNOTATE_HAPPENS_AFTER(obj) ((void)0)
  52. #endif
  53. #ifndef ANNOTATE_RWLOCK_ACQUIRED
  54. #define ANNOTATE_RWLOCK_ACQUIRED(lock, is_w) ((void)0)
  55. #endif
  56. #ifndef ANNOTATE_RWLOCK_RELEASED
  57. #define ANNOTATE_RWLOCK_RELEASED(lock, is_w) ((void)0)
  58. #endif
  59. #define _STARPU_VALGRIND_HG_SPIN_LOCK_PRE(lock) \
  60. DO_CREQ_v_WW(_VG_USERREQ__HG_PTHREAD_SPIN_LOCK_PRE, \
  61. struct _starpu_spinlock *, lock, long, 0)
  62. #define _STARPU_VALGRIND_HG_SPIN_LOCK_POST(lock) \
  63. DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_SPIN_LOCK_POST, \
  64. struct _starpu_spinlock *, lock)
  65. #define _STARPU_VALGRIND_HG_SPIN_UNLOCK_PRE(lock) \
  66. DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_SPIN_INIT_OR_UNLOCK_PRE, \
  67. struct _starpu_spinlock *, lock)
  68. #define _STARPU_VALGRIND_HG_SPIN_UNLOCK_POST(lock) \
  69. DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_SPIN_INIT_OR_UNLOCK_POST, \
  70. struct _starpu_spinlock *, lock)
  71. #if defined(__KNC__) || defined(__KNF__)
  72. #define STARPU_DEBUG_PREFIX "[starpu-mic]"
  73. #else
  74. #define STARPU_DEBUG_PREFIX "[starpu]"
  75. #endif
  76. #ifdef STARPU_VERBOSE
  77. # define _STARPU_DEBUG(fmt, args ...) do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%s] " fmt ,__starpu_func__ ,##args); fflush(stderr); }} while(0)
  78. #else
  79. # define _STARPU_DEBUG(fmt, args ...) do { } while (0)
  80. #endif
  81. #ifdef STARPU_VERBOSE0
  82. # define _STARPU_LOG_IN() do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%ld][%s] -->\n", pthread_self(), __starpu_func__ ); }} while(0)
  83. # define _STARPU_LOG_OUT() do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%ld][%s] <--\n", pthread_self(), __starpu_func__ ); }} while(0)
  84. # define _STARPU_LOG_OUT_TAG(outtag) do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%ld][%s] <-- (%s)\n", pthread_self(), __starpu_func__, outtag); }} while(0)
  85. #else
  86. # define _STARPU_LOG_IN()
  87. # define _STARPU_LOG_OUT()
  88. # define _STARPU_LOG_OUT_TAG(outtag)
  89. #endif
  90. #define _STARPU_DISP(fmt, args ...) do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%s] " fmt ,__starpu_func__ ,##args); }} while(0)
  91. #define _STARPU_ERROR(fmt, args ...) \
  92. do { \
  93. fprintf(stderr, "\n\n[starpu][%s] Error: " fmt ,__starpu_func__ ,##args); \
  94. fprintf(stderr, "\n\n"); \
  95. STARPU_ABORT(); \
  96. } while (0)
  97. #define _STARPU_IS_ZERO(a) (fpclassify(a) == FP_ZERO)
  98. int _starpu_mkpath(const char *s, mode_t mode);
  99. void _starpu_mkpath_and_check(const char *s, mode_t mode);
  100. char *_starpu_get_home_path(void);
  101. void _starpu_gethostname(char *hostname, size_t size);
  102. /* If FILE is currently on a comment line, eat it. */
  103. void _starpu_drop_comments(FILE *f);
  104. struct _starpu_job;
  105. /* Returns the symbol associated to that job if any. */
  106. const char *_starpu_job_get_model_name(struct _starpu_job *j);
  107. struct starpu_codelet;
  108. /* Returns the symbol associated to that job if any. */
  109. const char *_starpu_codelet_get_model_name(struct starpu_codelet *cl);
  110. int _starpu_check_mutex_deadlock(starpu_pthread_mutex_t *mutex);
  111. #endif // __COMMON_UTILS_H__