Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Trace manager : Add and change some structures and functions
authorjbrv <jean-baptiste.herve@esial.net>
Mon, 11 Jun 2012 14:13:33 +0000 (16:13 +0200)
committerjbrv <jean-baptiste.herve@esial.net>
Mon, 11 Jun 2012 14:45:16 +0000 (16:45 +0200)
New structure to generate event dates, and new functions to create them.
The tmgr_trace structure takes now a dynar of events, or 2 event generators.

include/simgrid/platf.h
src/surf/trace_mgr.c
src/surf/trace_mgr_private.h

index 53dfb19..ad045ed 100644 (file)
@@ -19,13 +19,24 @@ XBT_PUBLIC(sg_routing_edge_t) sg_routing_edge_by_name_or_null(const char *name);
 
 
 typedef struct tmgr_trace *tmgr_trace_t; /**< Opaque structure defining an availability trace */
+
+/** opaque structure defining a event generator for avaibility based on a probability distribution */
+typedef struct probabilist_event_generator *probabilist_event_generator_t;
+
 XBT_PUBLIC(tmgr_trace_t) tmgr_trace_new_from_file(const char *filename);
 XBT_PUBLIC(tmgr_trace_t) tmgr_trace_new_from_string(const char *id,
                                                     const char *input,
                                                     double periodicity);
-XBT_PUBLIC(tmgr_trace_t) tmgr_trace_new_uniform(double alpha, double beta);
-XBT_PUBLIC(tmgr_trace_t) tmgr_trace_new_exponential(double lambda);
-XBT_PUBLIC(tmgr_trace_t) tmgr_trace_new_weibull(double lambda, double k);
+typedef struct RngStream_InfoState *RngStream;
+XBT_PUBLIC(RngStream) tmgr_rng_stream_from_id(char* id);
+XBT_PUBLIC(probabilist_event_generator_t) tmgr_event_generator_new_uniform(RngStream rng_stream,
+                                                                           double alpha,
+                                                                           double beta);
+XBT_PUBLIC(probabilist_event_generator_t) tmgr_event_generator_new_exponential(RngStream rng_stream,
+                                                                               double lambda);
+XBT_PUBLIC(probabilist_event_generator_t) tmgr_event_generator_new_weibull(RngStream rng_stream,
+                                                                           double lambda,
+                                                                           double k);
 
 /** Defines whether a given resource is working or not */
 typedef enum {
index 2947389..a73e539 100644 (file)
 #include "xbt/dict.h"
 #include "trace_mgr_private.h"
 #include "surf_private.h"
+#include "xbt/RngStream.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_trace, surf, "Surf trace management");
 
 static xbt_dict_t trace_list = NULL;
 
+// a unique RngStream structure for everyone
+// FIXME : has to be created by someone
+static RngStream common_rng_stream = NULL;
+
 XBT_INLINE tmgr_history_t tmgr_history_new(void)
 {
   tmgr_history_t h;
@@ -32,46 +37,65 @@ XBT_INLINE void tmgr_history_free(tmgr_history_t h)
   free(h);
 }
 
-tmgr_trace_t tmgr_trace_new_uniform(double alpha, double beta)
-{  
-  tmgr_trace_t trace = NULL;
+RngStream tmgr_rng_stream_from_id(char* id)
+{
+  unsigned int id_hash;
+  RngStream rng_stream = NULL;
   
-  trace = xbt_new0(s_tmgr_trace_t, 1);
-  trace->type = e_trace_uniform;
-  trace->s_uniform.alpha = alpha;
-  trace->s_uniform.beta = beta;
+  rng_stream = RngStream_CopyStream(common_rng_stream);
+  id_hash = xbt_dict_hash(id);
+  RngStream_AdvanceState(rng_stream, 0, id_hash);
+  
+  return rng_stream;
+}
+
+probabilist_event_generator_t tmgr_event_generator_new_uniform(RngStream rng_stream,
+                                                               double alpha,
+                                                               double beta)
+{  
+  probabilist_event_generator_t event_generator = NULL;
   
+  event_generator = xbt_new0(s_probabilist_event_generator_t, 1);
+  event_generator->type = e_generator_uniform;
+  event_generator->s_uniform_parameters.alpha = alpha;
+  event_generator->s_uniform_parameters.beta = beta;
+  event_generator->rng_stream = rng_stream;
+
   //FIXME Generate a new event date
   
-  return trace;
+  return event_generator;
 }
 
-
-tmgr_trace_t tmgr_trace_new_exponential(double lambda)
+probabilist_event_generator_t tmgr_event_generator_new_exponential(RngStream rng_stream,
+                                                                   double lambda)
 {  
-  tmgr_trace_t trace = NULL;
-  
-  trace = xbt_new0(s_tmgr_trace_t, 1);
-  trace->type = e_trace_exponential;
-  trace->s_exponential.lambda = lambda;
+  probabilist_event_generator_t event_generator = NULL;
   
-  // FIXME Generate a new event date
+  event_generator = xbt_new0(s_probabilist_event_generator_t, 1);
+  event_generator->type = e_generator_exponential;
+  event_generator->s_exponential_parameters.lambda = lambda;
+  event_generator->rng_stream = rng_stream;
+
+  //FIXME Generate a new event date
   
-  return trace;
+  return event_generator;
 }
 
-tmgr_trace_t tmgr_trace_new_weibull(double lambda, double k)
+probabilist_event_generator_t tmgr_event_generator_new_weibull(RngStream rng_stream,
+                                                               double lambda,
+                                                               double k)
 {  
-  tmgr_trace_t trace = NULL;
-  
-  trace = xbt_new0(s_tmgr_trace_t, 1);
-  trace->type = e_trace_weibull;
-  trace->s_weibull.lambda = lambda;
-  trace->s_weibull.k = k;
+  probabilist_event_generator_t event_generator = NULL;
   
+  event_generator = xbt_new0(s_probabilist_event_generator_t, 1);
+  event_generator->type = e_generator_weibull;
+  event_generator->s_weibull_parameters.lambda = lambda;
+  event_generator->s_weibull_parameters.k = k;
+  event_generator->rng_stream = rng_stream;
+
   // FIXME Generate a new event date
   
-  return trace;
+  return event_generator;
 }
 
 tmgr_trace_t tmgr_trace_new_from_string(const char *id, const char *input,
index dd5e09e..9498be8 100644 (file)
@@ -10,6 +10,7 @@
 #include "xbt/swag.h"
 #include "xbt/heap.h"
 #include "surf/trace_mgr.h"
+#include "xbt/RngStream.h"
 
 typedef struct tmgr_event {
   double delta;
@@ -17,32 +18,43 @@ typedef struct tmgr_event {
 } s_tmgr_event_t, *tmgr_event_t;
 
 enum e_trace_type {
-  e_trace_list, e_trace_uniform, e_trace_exponential, e_trace_weibull
+  e_trace_list, e_trace_probabilist
 };
 
-typedef struct tmgr_trace {
-  enum e_trace_type type;
+enum e_event_generator_type {
+  e_generator_uniform, e_generator_exponential, e_generator_weibull
+};
+
+typedef struct probabilist_event_generator {
+  enum e_event_generator_type type;
+  RngStream rng_stream;
+  double next_value;
   union {
-    struct {
-      xbt_dynar_t event_list;
-    } s_list;
     struct {
       double alpha;
       double beta;
-      s_tmgr_event_t next_event;
-      /* and probably other things */
-    } s_uniform;
+    } s_uniform_parameters;
     struct {
       double lambda;
-      s_tmgr_event_t next_event;
-      /* and probably other things */
-    } s_exponential;
+    } s_exponential_parameters;
     struct {
       double lambda;
       double k;
-      s_tmgr_event_t next_event;
-      /* and probably other things */
-    } s_weibull;
+    } s_weibull_parameters;
+  };
+} s_probabilist_event_generator_t, *probabilist_event_generator_t;
+
+typedef struct tmgr_trace {
+  enum e_trace_type type;
+  union {
+    struct {
+      xbt_dynar_t event_list;
+    } s_list;
+    struct {
+      probabilist_event_generator_t event1_generator;
+      probabilist_event_generator_t event2_generator;
+      int next_event;
+    } s_probabilist;
   };
 } s_tmgr_trace_t;
 
@@ -58,4 +70,5 @@ typedef struct tmgr_history {
   xbt_heap_t heap;
 } s_tmgr_history_t;
 
+
 #endif                          /* _SURF_TMGR_PRIVATE_H */