utils.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #ifdef STARPU_VERBOSE
  72. # define _STARPU_DEBUG(fmt, args ...) do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, "[starpu][%s] " fmt ,__starpu_func__ ,##args); fflush(stderr); }} while(0)
  73. #else
  74. # define _STARPU_DEBUG(fmt, args ...) do { } while (0)
  75. #endif
  76. #ifdef STARPU_VERBOSE0
  77. # define _STARPU_LOG_IN() do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, "[starpu][%ld][%s] -->\n", pthread_self(), __starpu_func__ ); }} while(0)
  78. # define _STARPU_LOG_OUT() do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, "[starpu][%ld][%s] <--\n", pthread_self(), __starpu_func__ ); }} while(0)
  79. # define _STARPU_LOG_OUT_TAG(outtag) do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, "[starpu][%ld][%s] <-- (%s)\n", pthread_self(), __starpu_func__, outtag); }} while(0)
  80. #else
  81. # define _STARPU_LOG_IN()
  82. # define _STARPU_LOG_OUT()
  83. # define _STARPU_LOG_OUT_TAG(outtag)
  84. #endif
  85. #define _STARPU_DISP(fmt, args ...) do { if (!getenv("STARPU_SILENT")) {fprintf(stderr, "[starpu][%s] " fmt ,__starpu_func__ ,##args); }} while(0)
  86. #define _STARPU_ERROR(fmt, args ...) \
  87. do { \
  88. fprintf(stderr, "\n\n[starpu][%s] Error: " fmt ,__starpu_func__ ,##args); \
  89. fprintf(stderr, "\n\n"); \
  90. STARPU_ABORT(); \
  91. } while (0)
  92. #define _STARPU_IS_ZERO(a) (fpclassify(a) == FP_ZERO)
  93. int _starpu_mkpath(const char *s, mode_t mode);
  94. void _starpu_mkpath_and_check(const char *s, mode_t mode);
  95. char *_starpu_get_home_path(void);
  96. void _starpu_gethostname(char *hostname, size_t size);
  97. /* If FILE is currently on a comment line, eat it. */
  98. void _starpu_drop_comments(FILE *f);
  99. struct _starpu_job;
  100. /* Returns the symbol associated to that job if any. */
  101. const char *_starpu_job_get_model_name(struct _starpu_job *j);
  102. struct starpu_codelet;
  103. /* Returns the symbol associated to that job if any. */
  104. const char *_starpu_codelet_get_model_name(struct starpu_codelet *cl);
  105. #endif // __COMMON_UTILS_H__