Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add seed management to have independant streams.
authoralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sat, 15 Mar 2008 20:37:26 +0000 (20:37 +0000)
committeralegrand <alegrand@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sat, 15 Mar 2008 20:37:26 +0000 (20:37 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5297 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/include/surf/random_mgr.h
src/surf/random_mgr.c
src/surf/surfxml_parse.c

index d02ec3d..d839d55 100644 (file)
@@ -12,6 +12,7 @@ SG_BEGIN_DECL()
 typedef enum {NONE, DRAND48, RAND} Generator;
 
 typedef struct random_data_desc {
 typedef enum {NONE, DRAND48, RAND} Generator;
 
 typedef struct random_data_desc {
+  long int seed;
   double max, min, mean, stdDeviation;
   Generator generator;
 } s_random_data_t, *random_data_t;
   double max, min, mean, stdDeviation;
   Generator generator;
 } s_random_data_t, *random_data_t;
@@ -19,7 +20,9 @@ typedef struct random_data_desc {
 XBT_PUBLIC_DATA(xbt_dict_t) random_data_list;
 
 XBT_PUBLIC(double) random_generate(random_data_t random);
 XBT_PUBLIC_DATA(xbt_dict_t) random_data_list;
 
 XBT_PUBLIC(double) random_generate(random_data_t random);
-XBT_PUBLIC(random_data_t) random_new(Generator generator, double min, double max, double mean, double stdDeviation);
+XBT_PUBLIC(random_data_t) random_new(Generator generator, long int seed, 
+                                    double min, double max, double mean, 
+                                    double stdDeviation);
 
 SG_END_DECL()
 
 
 SG_END_DECL()
 
index 4a9a0b7..44f8534 100644 (file)
@@ -10,11 +10,12 @@ static double drand48(void)
 }
 #endif
 
 }
 #endif
 
-static double custom_random(Generator generator){
+static double custom_random(Generator generator, long int *seed){
    switch(generator) {
    switch(generator) {
-      
-       case DRAND48:return drand48();  
-       case RAND: return (double)rand()/RAND_MAX; 
+   case DRAND48:
+     return drand48();         
+   case RAND: 
+     return (double)rand_r((unsigned int*)seed)/RAND_MAX; 
    default: return drand48();
    }
 }
    default: return drand48();
    }
 }
@@ -31,8 +32,8 @@ double random_generate(random_data_t random){
          y1 = sqrt( - 2 * log(x1) ) * cos( 2 * pi * x2 )
     */ 
     do {
          y1 = sqrt( - 2 * log(x1) ) * cos( 2 * pi * x2 )
     */ 
     do {
-      x1 = 2.0 * custom_random(random->generator) - 1.0;
-      x2 = 2.0 * custom_random(random->generator) - 1.0;
+      x1 = 2.0 * custom_random(random->generator,&(random->seed)) - 1.0;
+      x2 = 2.0 * custom_random(random->generator,&(random->seed)) - 1.0;
       w = x1 * x1 + x2 * x2;
     } while ( w >= 1.0 );
 
       w = x1 * x1 + x2 * x2;
     } while ( w >= 1.0 );
 
@@ -46,9 +47,12 @@ double random_generate(random_data_t random){
   return y;
 }
 
   return y;
 }
 
-random_data_t random_new(Generator generator, double min, double max, double mean, double stdDeviation){
+random_data_t random_new(Generator generator, long int seed, 
+                        double min, double max, double mean, 
+                        double stdDeviation){
   random_data_t random = xbt_new0(s_random_data_t, 1);
   random->generator = generator;
   random_data_t random = xbt_new0(s_random_data_t, 1);
   random->generator = generator;
+  random->seed = seed;
   random->min = min;
   random->max = max;
   random->mean = mean;
   random->min = min;
   random->max = max;
   random->mean = mean;
index 87c8135..fc71eeb 100644 (file)
@@ -1127,7 +1127,7 @@ void init_randomness(void)
 void add_randomness(void)
 {
    /* If needed aditional properties can be added by using the prop tag */
 void add_randomness(void)
 {
    /* If needed aditional properties can be added by using the prop tag */
-   random_data_t random = random_new(random_generator, random_min, random_max, random_mean, random_std_deviation);
+  random_data_t random = random_new(random_generator, 0, random_min, random_max, random_mean, random_std_deviation);
    xbt_dict_set(random_data_list, random_id, (void *)random, NULL);
 }
 
    xbt_dict_set(random_data_list, random_id, (void *)random, NULL);
 }