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-2018 Université de Bordeaux
4  * Copyright (C) 2011,2012,2017 Inria
5  * Copyright (C) 2010-2017, 2019 CNRS
6  *
7  * StarPU is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License as published by
9  * the Free Software Foundation; either version 2.1 of the License, or (at
10  * your option) any later version.
11  *
12  * StarPU is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  * See the GNU Lesser General Public License in COPYING.LGPL for more details.
17  */
18 
19 #ifndef __STARPU_HELPER_H__
20 #define __STARPU_HELPER_H__
21 
22 #include <stdio.h>
23 #include <starpu.h>
24 
25 #ifdef __cplusplus
26 extern "C"
27 {
28 #endif
29 
38 #define STARPU_MIN(a,b) ((a)<(b)?(a):(b))
39 
42 #define STARPU_MAX(a,b) ((a)<(b)?(b):(a))
43 
48 #define STARPU_POISON_PTR ((void *)0xdeadbeef)
49 
50 extern int _starpu_silent;
51 
52 char *starpu_getenv(const char *str);
53 
59 static __starpu_inline int starpu_get_env_number(const char *str)
60 {
61  char *strval;
62 
63  strval = starpu_getenv(str);
64  if (strval)
65  {
66  /* the env variable was actually set */
67  long int val;
68  char *pcheck;
69 
70  val = strtol(strval, &pcheck, 10);
71  if (*pcheck) {
72  fprintf(stderr,"The %s environment variable must contain an integer\n", str);
73  STARPU_ABORT();
74  }
75 
76  /* fprintf(stderr, "ENV %s WAS %d\n", str, val); */
77  STARPU_ASSERT_MSG(val >= 0, "The value for the environment variable '%s' cannot be negative", str);
78  return (int)val;
79  }
80  else
81  {
82  /* there is no such env variable */
83  /* fprintf("There was no %s ENV\n", str); */
84  return -1;
85  }
86 }
87 
88 static __starpu_inline int starpu_get_env_number_default(const char *str, int defval)
89 {
90  int ret = starpu_get_env_number(str);
91  if (ret == -1)
92  ret = defval;
93  return ret;
94 }
95 
96 static __starpu_inline float starpu_get_env_float_default(const char *str, float defval)
97 {
98  char *strval;
99 
100  strval = starpu_getenv(str);
101  if (strval)
102  {
103  /* the env variable was actually set */
104  float val;
105  char *pcheck;
106 
107  val = strtof(strval, &pcheck);
108  if (*pcheck) {
109  fprintf(stderr,"The %s environment variable must contain a float\n", str);
110  STARPU_ABORT();
111  }
112 
113  /* fprintf(stderr, "ENV %s WAS %f\n", str, val); */
114  return val;
115  }
116  else
117  {
118  /* there is no such env variable */
119  /* fprintf("There was no %s ENV\n", str); */
120  return defval;
121  }
122 }
123 
138 void starpu_execute_on_each_worker(void (*func)(void *), void *arg, uint32_t where);
139 
144 void starpu_execute_on_each_worker_ex(void (*func)(void *), void *arg, uint32_t where, const char *name);
145 
152 void starpu_execute_on_specific_workers(void (*func)(void*), void *arg, unsigned num_workers, unsigned *workers, const char *name);
153 
157 double starpu_timing_now(void);
158 
169 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);
170 
173 #ifdef __cplusplus
174 }
175 #endif
176 
177 #endif // __STARPU_HELPER_H__
STARPU_ASSERT_MSG
#define STARPU_ASSERT_MSG(x, msg,...)
Definition: starpu_util.h:228
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:46
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:245
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:59
starpu_execute_on_specific_workers
void starpu_execute_on_specific_workers(void(*func)(void *), void *arg, unsigned num_workers, unsigned *workers, const char *name)