StarPU Internal Handbook
Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1/* StarPU --- Runtime system for heterogeneous multicore architectures.
2 *
3 * Copyright (C) 2010-2023 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
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
17#ifndef __COMMON_UTILS_H__
18#define __COMMON_UTILS_H__
19
22#include <common/config.h>
23#include <starpu.h>
24#include <sys/stat.h>
25#include <string.h>
26#include <stdlib.h>
27#ifdef HAVE_UNISTD_H
28#include <unistd.h>
29#endif
30#include <math.h>
31#ifdef STARPU_HAVE_SCHED_YIELD
32#include <sched.h>
33#endif
34#include <limits.h>
35
36#ifdef STARPU_HAVE_HELGRIND_H
37#include <valgrind/helgrind.h>
38#endif
39
40#pragma GCC visibility push(hidden)
41
42#define _STARPU_STRINGIFY_(x) #x
43#define _STARPU_STRINGIFY(x) _STARPU_STRINGIFY_(x)
44
45#ifndef DO_CREQ_v_WW
46#define DO_CREQ_v_WW(_creqF, _ty1F, _arg1F, _ty2F, _arg2F) ((void)0)
47#endif
48#ifndef DO_CREQ_v_W
49#define DO_CREQ_v_W(_creqF, _ty1F, _arg1F) ((void)0)
50#endif
51#ifndef ANNOTATE_HAPPENS_BEFORE
52#define ANNOTATE_HAPPENS_BEFORE(obj) ((void)0)
53#endif
54#ifndef ANNOTATE_HAPPENS_BEFORE_FORGET_ALL
55#define ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(obj) ((void)0)
56#endif
57#ifndef ANNOTATE_HAPPENS_AFTER
58#define ANNOTATE_HAPPENS_AFTER(obj) ((void)0)
59#endif
60#ifndef VALGRIND_HG_DISABLE_CHECKING
61#define VALGRIND_HG_DISABLE_CHECKING(start, len) ((void)0)
62#endif
63#ifndef VALGRIND_HG_ENABLE_CHECKING
64#define VALGRIND_HG_ENABLE_CHECKING(start, len) ((void)0)
65#endif
66#ifndef VALGRIND_STACK_REGISTER
67#define VALGRIND_STACK_REGISTER(stackbottom, stacktop) 0
68#endif
69#ifndef VALGRIND_STACK_DEREGISTER
70#define VALGRIND_STACK_DEREGISTER(id) ((void)0)
71#endif
72#ifndef RUNNING_ON_VALGRIND
73#define RUNNING_ON_VALGRIND 0
74#endif
75#ifdef STARPU_SANITIZE_THREAD
76#define STARPU_RUNNING_ON_VALGRIND 1
77#else
78#define STARPU_RUNNING_ON_VALGRIND RUNNING_ON_VALGRIND
79#endif
80#define STARPU_HG_DISABLE_CHECKING(variable) VALGRIND_HG_DISABLE_CHECKING(&(variable), sizeof(variable))
81#define STARPU_HG_ENABLE_CHECKING(variable) VALGRIND_HG_ENABLE_CHECKING(&(variable), sizeof(variable))
82
83#define STARPU_DEBUG_PREFIX "[starpu]"
84
85/* This is needed in some places to make valgrind yield to another thread to be
86 * able to progress. */
87#if defined(__i386__) || defined(__x86_64__)
88#define _STARPU_UYIELD() __asm__ __volatile("rep; nop")
89#else
90#define _STARPU_UYIELD() ((void)0)
91#endif
92#if defined(STARPU_HAVE_SCHED_YIELD) && defined(STARPU_HAVE_HELGRIND_H)
93#define STARPU_VALGRIND_YIELD() do { if (STARPU_RUNNING_ON_VALGRIND) sched_yield(); } while (0)
94#define STARPU_UYIELD() do { if (STARPU_RUNNING_ON_VALGRIND) sched_yield(); else _STARPU_UYIELD(); } while (0)
95#else
96#define STARPU_VALGRIND_YIELD() do { } while (0)
97#define STARPU_UYIELD() _STARPU_UYIELD()
98#endif
99
100#ifdef STARPU_VERBOSE
101# define _STARPU_DEBUG(fmt, ...) do { if (!_starpu_silent) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%s] " fmt ,__starpu_func__ ,## __VA_ARGS__); fflush(stderr); }} while(0)
102# define _STARPU_DEBUG_NO_HEADER(fmt, ...) do { if (!_starpu_silent) {fprintf(stderr, fmt , ## __VA_ARGS__); fflush(stderr); }} while(0)
103#else
104# define _STARPU_DEBUG(fmt, ...) do { } while (0)
105# define _STARPU_DEBUG_NO_HEADER(fmt, ...) do { } while (0)
106#endif
107
108#ifdef STARPU_EXTRA_VERBOSE
109# define _STARPU_EXTRA_DEBUG(fmt, ...) do { if (!_starpu_silent) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%s] " fmt ,__starpu_func__ ,## __VA_ARGS__); fflush(stderr); }} while(0)
110#else
111# define _STARPU_EXTRA_DEBUG(fmt, ...) do { } while (0)
112#endif
113
114#ifdef STARPU_EXTRA_VERBOSE
115# define _STARPU_LOG_IN() do { if (!_starpu_silent) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%ld][%s:%s@%d] -->\n", starpu_pthread_self(), __starpu_func__,__FILE__, __LINE__); }} while(0)
116# define _STARPU_LOG_OUT() do { if (!_starpu_silent) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%ld][%s:%s@%d] <--\n", starpu_pthread_self(), __starpu_func__, __FILE__, __LINE__); }} while(0)
117# define _STARPU_LOG_OUT_TAG(outtag) do { if (!_starpu_silent) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%ld][%s:%s@%d] <-- (%s)\n", starpu_pthread_self(), __starpu_func__, __FILE__, __LINE__, outtag); }} while(0)
118#else
119# define _STARPU_LOG_IN()
120# define _STARPU_LOG_OUT()
121# define _STARPU_LOG_OUT_TAG(outtag)
122#endif
123
124/* TODO: cache */
125#if defined(STARPU_USE_MPI)
126
127#if !defined HOST_NAME_MAX
128#define HOST_NAME_MAX 256
129#endif
130
131#define _STARPU_MSG(fmt, ...) do { char _msghost[HOST_NAME_MAX]; gethostname(_msghost, HOST_NAME_MAX); fprintf(stderr, STARPU_DEBUG_PREFIX"[%s][%s] " fmt, _msghost, __starpu_func__, ## __VA_ARGS__); } while(0)
132#define _STARPU_DISP(fmt, ...) do { if (!_starpu_silent) { char _disphost[HOST_NAME_MAX]; gethostname(_disphost, HOST_NAME_MAX); fprintf(stderr, STARPU_DEBUG_PREFIX"[%s][%s] " fmt, _disphost, __starpu_func__, ## __VA_ARGS__); }} while(0)
133#define _STARPU_ERROR(fmt, ...) \
134 do { \
135 char _errorhost[HOST_NAME_MAX]; \
136 gethostname(_errorhost, HOST_NAME_MAX); \
137 fprintf(stderr, "\n\n[starpu][%s][%s] Error: " fmt, _errorhost, __starpu_func__, ## __VA_ARGS__); \
138 fprintf(stderr, "\n\n"); \
139 STARPU_ABORT(); \
140 } while (0)
141#else /* STARPU_USE_MPI */
142#define _STARPU_MSG(fmt, ...) do { fprintf(stderr, STARPU_DEBUG_PREFIX"[%s] " fmt ,__starpu_func__ ,## __VA_ARGS__); } while(0)
143#define _STARPU_DISP(fmt, ...) do { if (!_starpu_silent) {fprintf(stderr, STARPU_DEBUG_PREFIX"[%s] " fmt ,__starpu_func__ ,## __VA_ARGS__); }} while(0)
144#define _STARPU_ERROR(fmt, ...) \
145 do { \
146 fprintf(stderr, "\n\n[starpu][%s] Error: " fmt ,__starpu_func__ ,## __VA_ARGS__); \
147 fprintf(stderr, "\n\n"); \
148 STARPU_ABORT(); \
149 } while (0)
150#endif /* STARPU_USE_MPI */
151
152#ifdef _MSC_VER
153# if defined(__cplusplus)
154# define _STARPU_DECLTYPE(x) (decltype(x))
155# else
156# define _STARPU_DECLTYPE(x)
157# endif
158#else
159# define _STARPU_DECLTYPE(x) (__typeof(x))
160#endif
161
162#define _STARPU_MALLOC(ptr, size) do { ptr = _STARPU_DECLTYPE(ptr) malloc(size); STARPU_ASSERT_MSG(ptr != NULL || size == 0, "Cannot allocate %ld bytes\n", (long) (size)); } while (0)
163#define _STARPU_CALLOC(ptr, nmemb, size) do { ptr = _STARPU_DECLTYPE(ptr) calloc(nmemb, size); STARPU_ASSERT_MSG(ptr != NULL || size == 0, "Cannot allocate %ld bytes\n", (long) (nmemb*size)); } while (0)
164#define _STARPU_REALLOC(ptr, size) do { void *_new_ptr = realloc(ptr, size); STARPU_ASSERT_MSG(_new_ptr != NULL || size == 0, "Cannot reallocate %ld bytes\n", (long) (size)); ptr = _STARPU_DECLTYPE(ptr) _new_ptr;} while (0)
165
166#ifdef _MSC_VER
167#define _STARPU_IS_ZERO(a) (a == 0.0)
168#else
169#define _STARPU_IS_ZERO(a) (fpclassify(a) == FP_ZERO)
170#endif
171
172char *_starpu_mkdtemp_internal(char *tmpl) STARPU_ATTRIBUTE_VISIBILITY_DEFAULT;
173char *_starpu_mkdtemp(char *tmpl) STARPU_ATTRIBUTE_VISIBILITY_DEFAULT;
174int _starpu_mkpath(const char *s, mode_t mode);
175void _starpu_mkpath_and_check(const char *s, mode_t mode) STARPU_ATTRIBUTE_VISIBILITY_DEFAULT;
176char *_starpu_mktemp(const char *directory, int flags, int *fd);
179char *_starpu_mktemp_many(const char *directory, int depth, int flags, int *fd);
180void _starpu_rmtemp_many(char *path, int depth);
181void _starpu_rmdir_many(char *path, int depth);
182int _starpu_fftruncate(FILE *file, size_t length);
183int _starpu_ftruncate(int fd, size_t length);
184int _starpu_frdlock(FILE *file);
185int _starpu_frdunlock(FILE *file);
186int _starpu_fwrlock(FILE *file);
187int _starpu_fwrunlock(FILE *file);
188char *_starpu_get_home_path(void);
189void _starpu_gethostname(char *hostname, size_t size) STARPU_ATTRIBUTE_VISIBILITY_DEFAULT;
190
193
194struct _starpu_job;
199
200struct starpu_codelet;
202const char *_starpu_codelet_get_model_name(struct starpu_codelet *cl);
203
205const char *_starpu_codelet_get_name(struct starpu_codelet *cl);
206
207int _starpu_check_mutex_deadlock(starpu_pthread_mutex_t *mutex);
208
209void _starpu_util_init(void);
210
211enum initialization { UNINITIALIZED = 0, CHANGING, INITIALIZED };
212
213#pragma GCC visibility pop
214
215#endif // __COMMON_UTILS_H__
Definition jobs.h:74
char * _starpu_mktemp_many(const char *directory, int depth, int flags, int *fd)
const char * _starpu_codelet_get_model_name(struct starpu_codelet *cl)
const char * _starpu_job_get_task_name(struct _starpu_job *j)
void _starpu_drop_comments(FILE *f)
const char * _starpu_job_get_model_name(struct _starpu_job *j)
const char * _starpu_codelet_get_name(struct starpu_codelet *cl)