StarPU Handbook
starpu_helper.h
Go to the documentation of this file.
1 /* StarPU --- Runtime system for heterogeneous multicore architectures.
2  *
3  * Copyright (C) 2008-2021 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 __STARPU_HELPER_H__
18 #define __STARPU_HELPER_H__
19 
20 #include <stdio.h>
21 #include <starpu.h>
22 
23 #ifdef STARPU_HAVE_HWLOC
24 #include <hwloc.h>
25 #endif
26 
27 #ifdef __cplusplus
28 extern "C"
29 {
30 #endif
31 
40 #define STARPU_MIN(a,b) ((a)<(b)?(a):(b))
44 #define STARPU_MAX(a,b) ((a)<(b)?(b):(a))
45 
50 #define STARPU_POISON_PTR ((void *)0xdeadbeef)
51 
52 extern int _starpu_silent;
53 
54 char *starpu_getenv(const char *str);
55 
61 int starpu_get_env_string_var_default(const char *str, const char *strings[], int defvalue);
62 
68 int starpu_get_env_size_default(const char *str, int defval);
69 
75 static __starpu_inline int starpu_get_env_number(const char *str)
76 {
77  char *strval;
78 
79  strval = starpu_getenv(str);
80  if (strval)
81  {
82  /* the env variable was actually set */
83  long int val;
84  char *pcheck;
85 
86  val = strtol(strval, &pcheck, 10);
87  if (*pcheck)
88  {
89  fprintf(stderr,"The %s environment variable must contain an integer\n", str);
90  STARPU_ABORT();
91  }
92 
93  /* fprintf(stderr, "ENV %s WAS %d\n", str, val); */
94  STARPU_ASSERT_MSG(val >= 0, "The value for the environment variable '%s' cannot be negative", str);
95  return (int)val;
96  }
97  else
98  {
99  /* there is no such env variable */
100  /* fprintf("There was no %s ENV\n", str); */
101  return -1;
102  }
103 }
104 
105 static __starpu_inline int starpu_get_env_number_default(const char *str, int defval)
106 {
107  int ret = starpu_get_env_number(str);
108  if (ret == -1)
109  ret = defval;
110  return ret;
111 }
112 
113 static __starpu_inline float starpu_get_env_float_default(const char *str, float defval)
114 {
115  char *strval;
116 
117  strval = starpu_getenv(str);
118  if (strval)
119  {
120  /* the env variable was actually set */
121  float val;
122  char *pcheck;
123 
124  val = strtof(strval, &pcheck);
125  if (*pcheck)
126  {
127  fprintf(stderr,"The %s environment variable must contain a float\n", str);
128  STARPU_ABORT();
129  }
130 
131  /* fprintf(stderr, "ENV %s WAS %f\n", str, val); */
132  return val;
133  }
134  else
135  {
136  /* there is no such env variable */
137  /* fprintf("There was no %s ENV\n", str); */
138  return defval;
139  }
140 }
141 
156 void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t where);
157 
162 void starpu_execute_on_each_worker_ex(void (*func)(void *), void *arg, uint32_t where, const char *name);
163 
170 void starpu_execute_on_specific_workers(void (*func)(void*), void *arg, unsigned num_workers, unsigned *workers, const char *name);
171 
175 double starpu_timing_now(void);
176 
187 int starpu_data_cpy(starpu_data_handle_t dst_handle, starpu_data_handle_t src_handle, int asynchronous, void (*callback_func)(void*), void *callback_arg);
188 
196 
201 int starpu_get_pu_os_index(unsigned logical_index);
202 
203 #ifdef STARPU_HAVE_HWLOC
208 hwloc_topology_t starpu_get_hwloc_topology(void);
209 #endif
212 #ifdef __cplusplus
213 }
214 #endif
215 
216 #endif // __STARPU_HELPER_H__
struct _starpu_data_state * starpu_data_handle_t
Definition: starpu_data.h:44
void starpu_execute_on_specific_workers(void(*func)(void *), void *arg, unsigned num_workers, unsigned *workers, const char *name)
int starpu_get_pu_os_index(unsigned logical_index)
int starpu_get_env_size_default(const char *str, int defval)
void starpu_display_bindings(void)
double starpu_timing_now(void)
void starpu_execute_on_each_worker_ex(void(*func)(void *), void *arg, uint32_t where, const char *name)
void starpu_execute_on_each_worker(void(*func)(void *), void *arg, uint32_t where)
int starpu_get_env_string_var_default(const char *str, const char *strings[], int defvalue)
int starpu_data_cpy(starpu_data_handle_t dst_handle, starpu_data_handle_t src_handle, int asynchronous, void(*callback_func)(void *), void *callback_arg)
hwloc_topology_t starpu_get_hwloc_topology(void)
static __starpu_inline int starpu_get_env_number(const char *str)
Definition: starpu_helper.h:75
#define STARPU_ABORT()
Definition: starpu_util.h:246
#define STARPU_ASSERT_MSG(x, msg,...)
Definition: starpu_util.h:229