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-2020 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 __cplusplus
24 extern "C"
25 {
26 #endif
27 
36 #define STARPU_MIN(a,b) ((a)<(b)?(a):(b))
37 
40 #define STARPU_MAX(a,b) ((a)<(b)?(b):(a))
41 
46 #define STARPU_POISON_PTR ((void *)0xdeadbeef)
47 
48 extern int _starpu_silent;
49 
50 char *starpu_getenv(const char *str);
51 
57 int starpu_get_env_string_var_default(const char *str, const char *strings[], int defvalue);
58 
64 int starpu_get_env_size_default(const char *str, int defval);
65 
71 static __starpu_inline int starpu_get_env_number(const char *str)
72 {
73  char *strval;
74 
75  strval = starpu_getenv(str);
76  if (strval)
77  {
78  /* the env variable was actually set */
79  long int val;
80  char *pcheck;
81 
82  val = strtol(strval, &pcheck, 10);
83  if (*pcheck)
84  {
85  fprintf(stderr,"The %s environment variable must contain an integer\n", str);
86  STARPU_ABORT();
87  }
88 
89  /* fprintf(stderr, "ENV %s WAS %d\n", str, val); */
90  STARPU_ASSERT_MSG(val >= 0, "The value for the environment variable '%s' cannot be negative", str);
91  return (int)val;
92  }
93  else
94  {
95  /* there is no such env variable */
96  /* fprintf("There was no %s ENV\n", str); */
97  return -1;
98  }
99 }
100 
101 static __starpu_inline int starpu_get_env_number_default(const char *str, int defval)
102 {
103  int ret = starpu_get_env_number(str);
104  if (ret == -1)
105  ret = defval;
106  return ret;
107 }
108 
109 static __starpu_inline float starpu_get_env_float_default(const char *str, float defval)
110 {
111  char *strval;
112 
113  strval = starpu_getenv(str);
114  if (strval)
115  {
116  /* the env variable was actually set */
117  float val;
118  char *pcheck;
119 
120  val = strtof(strval, &pcheck);
121  if (*pcheck)
122  {
123  fprintf(stderr,"The %s environment variable must contain a float\n", str);
124  STARPU_ABORT();
125  }
126 
127  /* fprintf(stderr, "ENV %s WAS %f\n", str, val); */
128  return val;
129  }
130  else
131  {
132  /* there is no such env variable */
133  /* fprintf("There was no %s ENV\n", str); */
134  return defval;
135  }
136 }
137 
152 void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t where);
153 
158 void starpu_execute_on_each_worker_ex(void (*func)(void *), void *arg, uint32_t where, const char *name);
159 
166 void starpu_execute_on_specific_workers(void (*func)(void*), void *arg, unsigned num_workers, unsigned *workers, const char *name);
167 
171 double starpu_timing_now(void);
172 
183 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);
184 
187 #ifdef __cplusplus
188 }
189 #endif
190 
191 #endif // __STARPU_HELPER_H__
STARPU_ASSERT_MSG
#define STARPU_ASSERT_MSG(x, msg,...)
Definition: starpu_util.h:226
starpu_get_env_size_default
int starpu_get_env_size_default(const char *str, int defval)
starpu_execute_on_each_worker
void starpu_execute_on_each_worker(void(*func)(void *), void *arg, uint32_t where)
starpu_data_handle_t
struct _starpu_data_state * starpu_data_handle_t
Definition: starpu_data.h:44
starpu.h
starpu_data_cpy
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)
starpu_execute_on_each_worker_ex
void starpu_execute_on_each_worker_ex(void(*func)(void *), void *arg, uint32_t where, const char *name)
STARPU_ABORT
#define STARPU_ABORT()
Definition: starpu_util.h:243
starpu_get_env_string_var_default
int starpu_get_env_string_var_default(const char *str, const char *strings[], int defvalue)
starpu_timing_now
double starpu_timing_now(void)
starpu_get_env_number
static __starpu_inline int starpu_get_env_number(const char *str)
Definition: starpu_helper.h:71
starpu_execute_on_specific_workers
void starpu_execute_on_specific_workers(void(*func)(void *), void *arg, unsigned num_workers, unsigned *workers, const char *name)