Explorar o código

define rand functions in a dedicated .h file and add starpu definition for 'struct drand48_data'

Nathalie Furmento %!s(int64=13) %!d(string=hai) anos
pai
achega
55482d9c38

+ 2 - 1
Makefile.am

@@ -61,7 +61,8 @@ versinclude_HEADERS = 				\
 	include/starpu_scheduler.h		\
 	include/starpu_top.h			\
 	include/starpu_deprecated_api.h         \
-	include/starpu_hash.h
+	include/starpu_hash.h			\
+	include/starpu_rand.h
 
 nodist_versinclude_HEADERS = 			\
 	include/starpu_config.h

+ 1 - 11
configure.ac

@@ -145,17 +145,7 @@ AC_ARG_ENABLE(default-drand48, [AS_HELP_STRING([--disable-default-drand48],
 				   [Do not use the default version of drand48])],
 				   enable_default_drand48=$enableval, enable_default_drand48=yes)
 if test x$have_drand48 = xyes -a x$enable_default_drand48 = xyes ; then
-  AC_DEFINE([starpu_srand48(seed)],[srand48(seed)],[srand48 equivalent function])
-  AC_DEFINE([starpu_drand48()],[drand48()],[drand48 equivalent function])
-  AC_DEFINE([starpu_erand48(xsubi)],[erand48(xsubi)],[erand48 equivalent function])
-  AC_DEFINE([starpu_srand48_r(seed, buffer)],[srand48_r(seed, buffer)],[srand48_r equivalent function])
-  AC_DEFINE([starpu_erand48_r(xsubi, buffer, result)],[erand48_r(xsubi, buffer, result)],[erand48_r equivalent function])
-else
-  AC_DEFINE([starpu_srand48(seed)],[srand(seed)],[srand48 equivalent function])
-  AC_DEFINE([starpu_drand48()],[((double)(rand()) / RAND_MAX)],[drand48 equivalent function])
-  AC_DEFINE([starpu_erand48(xsubi)],[starpu_drand48()],[erand48 equivalent function])
-  AC_DEFINE([starpu_srand48_r(seed, buffer)],[srand((unsigned int)seed)],[srand48_r equivalent function])
-  AC_DEFINE([starpu_erand48_r(xsubi, buffer, result)],[do {*(result) = ((double)(rand()) / RAND_MAX);} while (0);],[erand48_r equivalent function])
+   AC_DEFINE([STARPU_USE_DRAND48], [1], [Define to 1 if drandr48 is available and should be used])
 fi
 
 # Some systems do not define strerror_r

+ 1 - 1
examples/pi/pi_redux.c

@@ -53,7 +53,7 @@ static curandGenerator_t curandgens[STARPU_NMAXWORKERS];
 /* state for the erand48 function : note the huge padding to avoid false-sharing */
 #define PADDING	1024
 static unsigned short xsubi[STARPU_NMAXWORKERS*PADDING];
-static struct drand48_data randbuffer[STARPU_NMAXWORKERS*PADDING];
+static starpu_drand48_data randbuffer[STARPU_NMAXWORKERS*PADDING];
 
 /* Function to initialize the random number generator in the current worker */
 static void init_rng(void *arg __attribute__((unused)))

+ 1 - 0
include/starpu.h

@@ -44,6 +44,7 @@ typedef unsigned long long uint64_t;
 #include <starpu_task_list.h>
 #include <starpu_scheduler.h>
 #include <starpu_expert.h>
+#include <starpu_rand.h>
 
 #ifdef __cplusplus
 extern "C"

+ 1 - 0
include/starpu_config.h.in

@@ -92,5 +92,6 @@ typedef ssize_t starpu_ssize_t;
 #endif
 
 #undef STARPU_SLOW_MACHINE
+#undef STARPU_USE_DRAND48
 
 #endif

+ 38 - 0
include/starpu_rand.h

@@ -0,0 +1,38 @@
+/* StarPU --- Runtime system for heterogeneous multicore architectures.
+ *
+ * Copyright (C) 2012  Centre National de la Recherche Scientifique
+ *
+ * StarPU is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * StarPU is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU Lesser General Public License in COPYING.LGPL for more details.
+ */
+
+#ifndef __STARPU_RAND_H__
+#define __STARPU_RAND_H__
+
+#include <stdlib.h>
+
+#ifdef STARPU_USE_DRAND48
+typedef struct drand48_data starpu_drand48_data;
+#  define starpu_srand48(seed)				srand48(seed)
+#  define starpu_drand48()				drand48()
+#  define starpu_erand48(xsubi)				erand48(xsubi)
+#  define starpu_srand48_r(seed, buffer)		srand48_r(seed, buffer)
+#  define starpu_erand48_r(xsubi, buffer, result)	erand48_r(xsubi, buffer, result)
+#else
+typedef int starpu_drand48_data;
+#  define starpu_srand48(seed)				srand(seed)
+#  define starpu_drand48() 				(double)(rand()) / RAND_MAX
+#  define starpu_erand48(xsubi)				starpu_drand48()
+#  define starpu_srand48_r(seed, buffer) 		srand((unsigned int)seed)
+#  define starpu_erand48_r(xsubi, buffer, result)	do {*(result) = ((double)(rand()) / RAND_MAX);} while (0)
+#endif
+
+#endif /* __STARPU_RAND_H__ */

+ 2 - 1
src/sched_policies/random_policy.c

@@ -1,7 +1,7 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
  * Copyright (C) 2010-2011  Université de Bordeaux 1
- * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
+ * Copyright (C) 2010, 2011, 2012  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as published by
@@ -17,6 +17,7 @@
 
 /* Policy attributing tasks randomly to workers */
 
+#include <starpu_rand.h>
 #include <core/workers.h>
 #include <sched_policies/fifo_queues.h>