StarPU Handbook

starpu_rand.h
Go to the documentation of this file.
1/* StarPU --- Runtime system for heterogeneous multicore architectures.
2 *
3 * Copyright (C) 2012-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_RAND_H__
18#define __STARPU_RAND_H__
19
20#include <stdlib.h>
21#include <starpu_config.h>
22
23#ifdef __cplusplus
24 extern "C"
25{
26#endif
27
33#ifdef STARPU_SIMGRID
34/* In simgrid mode, force using seed 0 by default to get reproducible behavior by default */
35#define starpu_seed(seed) starpu_get_env_number_default("STARPU_RAND_SEED", 0)
36#else
37#define starpu_seed(seed) starpu_get_env_number_default("STARPU_RAND_SEED", (seed))
38#endif
39
40#ifdef STARPU_USE_DRAND48
41# define starpu_srand48(seed) srand48(starpu_seed(seed))
42# define starpu_drand48() drand48()
43# define starpu_lrand48() lrand48()
44# define starpu_erand48(xsubi) erand48(xsubi)
45# ifdef STARPU_USE_ERAND48_R
46 typedef struct drand48_data starpu_drand48_data;
47# define starpu_srand48_r(seed, buffer) srand48_r(starpu_seed(seed), buffer)
48# define starpu_drand48_r(buffer, result) drand48_r(buffer, result)
49# define starpu_lrand48_r(buffer, result) lrand48_r(buffer, result)
50# define starpu_erand48_r(xsubi, buffer, result) erand48_r(xsubi, buffer, result)
51#else
52 typedef int starpu_drand48_data;
53# define starpu_srand48_r(seed, buffer) srand48(starpu_seed(seed))
54# define starpu_drand48_r(buffer, result) do {*(result) = drand48(); } while (0)
55# define starpu_lrand48_r(buffer, result) do {*(result) = lrand48(); } while (0)
56# define starpu_erand48_r(xsubi, buffer, result) do {(void) buffer; *(result) = erand48(xsubi); } while (0)
57# endif
58#else
59 typedef int starpu_drand48_data;
60# define starpu_srand48(seed) srand(starpu_seed(seed))
61# define starpu_drand48() (double)(rand()) / RAND_MAX
62# define starpu_lrand48() rand()
63# define starpu_erand48(xsubi) starpu_drand48()
64# define starpu_srand48_r(seed, buffer) srand(starpu_seed(seed))
65# define starpu_erand48_r(xsubi, buffer, result) do {(void) xsubi; (void) buffer; *(result) = ((double)(rand()) / RAND_MAX);} while (0)
66#endif
67
70#ifdef __cplusplus
71}
72#endif
73
74#endif /* __STARPU_RAND_H__ */
starpu_config.h