Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
460886ab6280d2f2737c7c0326ec4e97a7000dd3
[simgrid.git] / src / surf / sg_platf.cpp
1 /* Copyright (c) 2006-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "xbt/misc.h"
8 #include "xbt/log.h"
9 #include "xbt/str.h"
10 #include "xbt/dict.h"
11 #include "xbt/RngStream.h"
12 #include "simgrid/platf_interface.h"
13 #include "surf/surf_routing.h"
14 #include "surf/surf.h"
15
16 #include "src/simix/smx_private.h"
17
18 #include "cpu_interface.hpp"
19 #include "host_interface.hpp"
20
21 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
22 xbt_dynar_t sg_platf_host_cb_list = NULL;   // of sg_platf_host_cb_t
23 xbt_dynar_t sg_platf_host_link_cb_list = NULL;   // of sg_platf_host_link_cb_t
24 xbt_dynar_t sg_platf_link_cb_list = NULL;   // of sg_platf_link_cb_t
25 xbt_dynar_t sg_platf_peer_cb_list = NULL; // of sg_platf_peer_cb_t
26 xbt_dynar_t sg_platf_cluster_cb_list = NULL; // of sg_platf_cluster_cb_t
27 xbt_dynar_t sg_platf_cabinet_cb_list = NULL; // of sg_platf_cluster_cb_t
28 xbt_dynar_t sg_platf_postparse_cb_list = NULL; // of void_f_void_t
29 xbt_dynar_t sg_platf_prop_cb_list = NULL; // of sg_platf_prop_cb_t
30
31 xbt_dynar_t sg_platf_route_cb_list = NULL; // of sg_platf_route_cb_t
32 xbt_dynar_t sg_platf_ASroute_cb_list = NULL; // of sg_platf_ASroute_cb_t
33 xbt_dynar_t sg_platf_bypassRoute_cb_list = NULL; // of sg_platf_bypassRoute_cb_t
34 xbt_dynar_t sg_platf_bypassASroute_cb_list = NULL; // of sg_platf_bypassASroute_cb_t
35
36 xbt_dynar_t sg_platf_trace_cb_list = NULL;
37 xbt_dynar_t sg_platf_trace_connect_cb_list = NULL;
38
39 /* ***************************************** */
40 /* TUTORIAL: New TAG                         */
41
42 xbt_dynar_t sg_platf_gpu_cb_list = NULL;
43 /* ***************************************** */
44
45
46 static int surf_parse_models_setup_already_called = 0;
47
48 /* one RngStream for the platform, to respect some statistic rules */
49 static RngStream sg_platf_rng_stream = NULL;
50
51 /** Module management function: creates all internal data structures */
52 void sg_platf_init(void) {
53
54   //FIXME : Ugly, but useful...
55   if(sg_platf_host_cb_list)
56     return; //Already initialized, so do nothing...
57
58   sg_platf_host_cb_list = xbt_dynar_new(sizeof(sg_platf_host_cb_t), NULL);
59   sg_platf_host_link_cb_list = xbt_dynar_new(sizeof(sg_platf_host_link_cb_t), NULL);
60   sg_platf_link_cb_list = xbt_dynar_new(sizeof(sg_platf_link_cb_t), NULL);
61   sg_platf_peer_cb_list = xbt_dynar_new(sizeof(sg_platf_peer_cb_t), NULL);
62   sg_platf_cluster_cb_list = xbt_dynar_new(sizeof(sg_platf_cluster_cb_t), NULL);
63   sg_platf_cabinet_cb_list = xbt_dynar_new(sizeof(sg_platf_cabinet_cb_t), NULL);
64   sg_platf_postparse_cb_list = xbt_dynar_new(sizeof(sg_platf_link_cb_t),NULL);
65   sg_platf_prop_cb_list = xbt_dynar_new(sizeof(sg_platf_prop_cb_t),NULL);
66
67   sg_platf_route_cb_list = xbt_dynar_new(sizeof(sg_platf_route_cb_t), NULL);
68   sg_platf_ASroute_cb_list = xbt_dynar_new(sizeof(sg_platf_route_cb_t), NULL);
69   sg_platf_bypassRoute_cb_list = xbt_dynar_new(sizeof(sg_platf_route_cb_t), NULL);
70   sg_platf_bypassASroute_cb_list = xbt_dynar_new(sizeof(sg_platf_route_cb_t), NULL);
71
72   sg_platf_trace_cb_list = xbt_dynar_new(sizeof(sg_platf_trace_cb_t), NULL);
73   sg_platf_trace_connect_cb_list = xbt_dynar_new(sizeof(sg_platf_trace_connect_cb_t), NULL);
74
75   /* ***************************************** */
76   /* TUTORIAL: New TAG                         */
77
78   sg_platf_gpu_cb_list = xbt_dynar_new(sizeof(sg_platf_gpu_cb_t), NULL);
79   /* ***************************************** */
80 }
81 /** Module management function: frees all internal data structures */
82 void sg_platf_exit(void) {
83   xbt_dynar_free(&sg_platf_host_cb_list);
84   xbt_dynar_free(&sg_platf_host_link_cb_list);
85   xbt_dynar_free(&sg_platf_link_cb_list);
86   xbt_dynar_free(&sg_platf_postparse_cb_list);
87   xbt_dynar_free(&sg_platf_peer_cb_list);
88   xbt_dynar_free(&sg_platf_cluster_cb_list);
89   xbt_dynar_free(&sg_platf_cabinet_cb_list);
90   xbt_dynar_free(&sg_platf_prop_cb_list);
91
92   xbt_dynar_free(&sg_platf_trace_cb_list);
93   xbt_dynar_free(&sg_platf_trace_connect_cb_list);
94
95   xbt_dynar_free(&sg_platf_route_cb_list);
96   xbt_dynar_free(&sg_platf_ASroute_cb_list);
97   xbt_dynar_free(&sg_platf_bypassRoute_cb_list);
98   xbt_dynar_free(&sg_platf_bypassASroute_cb_list);
99
100   /* ***************************************** */
101   /* TUTORIAL: New TAG                         */
102
103   xbt_dynar_free(&sg_platf_gpu_cb_list);
104
105   /* ***************************************** */
106
107   /* make sure that we will reinit the models while loading the platf once reinited */
108   surf_parse_models_setup_already_called = 0;
109 }
110
111 void sg_platf_new_host(sg_platf_host_cbarg_t host)
112 {
113
114   xbt_assert(! sg_host_by_name(host->id),
115                      "Refusing to create a second host named '%s'.", host->id);
116
117   RoutingEdge *net = NULL;
118   As* current_routing = routing_get_current();
119   if (current_routing)
120     net = routing_add_host(current_routing, host);
121
122   Cpu *cpu = surf_cpu_model_pm->createCpu(
123         host->id,
124         host->power_peak,
125         host->pstate,
126         host->power_scale,
127         host->power_trace,
128         host->core_amount,
129         host->initial_state,
130         host->state_trace,
131         host->properties);
132   surf_host_model->createHost(host->id, net, cpu);
133
134   unsigned int iterator;
135   sg_platf_host_cb_t fun;
136   xbt_dynar_foreach(sg_platf_host_cb_list, iterator, fun) {
137     fun(host);
138   }
139 }
140 void sg_platf_new_host_link(sg_platf_host_link_cbarg_t h){
141   unsigned int iterator;
142   sg_platf_host_link_cb_t fun;
143   xbt_dynar_foreach(sg_platf_host_link_cb_list, iterator, fun) {
144     fun(h);
145   }
146 }
147
148 /**
149  * \brief Add a "router" to the network element list
150  */
151 void sg_platf_new_router(sg_platf_router_cbarg_t router)
152 {
153   As* current_routing = routing_get_current();
154
155   if (current_routing->p_hierarchy == SURF_ROUTING_NULL)
156     current_routing->p_hierarchy = SURF_ROUTING_BASE;
157   xbt_assert(!xbt_lib_get_or_null(as_router_lib, router->id, ROUTING_ASR_LEVEL),
158              "Reading a router, processing unit \"%s\" already exists",
159              router->id);
160
161   RoutingEdge *info = new RoutingEdgeImpl(xbt_strdup(router->id),
162                                             -1,
163                                             SURF_NETWORK_ELEMENT_ROUTER,
164                                             current_routing);
165   info->setId(current_routing->parsePU(info));
166   xbt_lib_set(as_router_lib, router->id, ROUTING_ASR_LEVEL, (void *) info);
167   XBT_DEBUG("Having set name '%s' id '%d'", router->id, info->getId());
168   routingEdgeCreatedCallbacks(info);
169
170   if (router->coord && strcmp(router->coord, "")) {
171     unsigned int cursor;
172     char*str;
173
174     if (!COORD_ASR_LEVEL)
175       xbt_die ("To use host coordinates, please add --cfg=network/coordinates:yes to your command line");
176     /* Pre-parse the host coordinates */
177     xbt_dynar_t ctn_str = xbt_str_split_str(router->coord, " ");
178     xbt_dynar_t ctn = xbt_dynar_new(sizeof(double),NULL);
179     xbt_dynar_foreach(ctn_str,cursor, str) {
180       double val = atof(str);
181       xbt_dynar_push(ctn,&val);
182     }
183     xbt_dynar_shrink(ctn, 0);
184     xbt_dynar_free(&ctn_str);
185     xbt_lib_set(as_router_lib, router->id, COORD_ASR_LEVEL, (void *) ctn);
186     XBT_DEBUG("Having set router coordinates for '%s'",router->id);
187   }
188
189   if (TRACE_is_enabled())
190     sg_instr_new_router(router);
191 }
192
193 void sg_platf_new_link(sg_platf_link_cbarg_t link){
194   unsigned int iterator;
195   sg_platf_link_cb_t fun;
196   xbt_dynar_foreach(sg_platf_link_cb_list, iterator, fun) {
197     fun(link);
198   }
199 }
200
201 void sg_platf_new_peer(sg_platf_peer_cbarg_t peer){
202   unsigned int iterator;
203   sg_platf_peer_cb_t fun;
204   xbt_dynar_foreach(sg_platf_peer_cb_list, iterator, fun) {
205     fun(peer);
206   }
207 }
208 void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster){
209   unsigned int iterator;
210   sg_platf_cluster_cb_t fun;
211   xbt_dynar_foreach(sg_platf_cluster_cb_list, iterator, fun) {
212     fun(cluster);
213   }
214 }
215 void sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet){
216   unsigned int iterator;
217   sg_platf_cabinet_cb_t fun;
218   xbt_dynar_foreach(sg_platf_cabinet_cb_list, iterator, fun) {
219     fun(cabinet);
220   }
221 }
222 void sg_platf_new_storage(sg_platf_storage_cbarg_t storage)
223 {
224   xbt_assert(!xbt_lib_get_or_null(storage_lib, storage->id,ROUTING_STORAGE_LEVEL),
225                "Reading a storage, processing unit \"%s\" already exists", storage->id);
226
227   // Verification of an existing type_id
228 #ifndef NDEBUG
229   void* storage_type = xbt_lib_get_or_null(storage_type_lib, storage->type_id,ROUTING_STORAGE_TYPE_LEVEL);
230 #endif
231   xbt_assert(storage_type,"Reading a storage, type id \"%s\" does not exists", storage->type_id);
232
233   XBT_DEBUG("ROUTING Create a storage name '%s' with type_id '%s' and content '%s'",
234       storage->id,
235       storage->type_id,
236       storage->content);
237
238   xbt_lib_set(storage_lib,
239       storage->id,
240       ROUTING_STORAGE_LEVEL,
241       (void *) xbt_strdup(storage->type_id));
242
243   void* stype = xbt_lib_get_or_null(storage_type_lib,
244                                     storage->type_id,
245                                     ROUTING_STORAGE_TYPE_LEVEL);
246   if(!stype) xbt_die("No storage type '%s'",storage->type_id);
247
248   // if storage content is not specified use the content of storage_type if exist
249   if(!strcmp(storage->content,"") && strcmp(((storage_type_t) stype)->content,"")){
250     storage->content = ((storage_type_t) stype)->content;
251     storage->content_type = ((storage_type_t) stype)->content_type;
252     XBT_DEBUG("For disk '%s' content is empty, inherit the content (of type %s) from storage type '%s' ",
253         storage->id,((storage_type_t) stype)->content_type,
254         ((storage_type_t) stype)->type_id);
255   }
256
257   XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s' "
258       "\n\t\tmodel '%s' \n\t\tcontent '%s'\n\t\tcontent_type '%s' "
259       "\n\t\tproperties '%p''\n",
260       storage->id,
261       ((storage_type_t) stype)->model,
262       ((storage_type_t) stype)->type_id,
263       storage->content,
264       storage->content_type,
265       storage->properties);
266
267   surf_storage_model->createStorage(storage->id,
268                                      ((storage_type_t) stype)->type_id,
269                                      storage->content,
270                                      storage->content_type,
271                                      storage->properties,
272                                      storage->attach);
273 }
274 void sg_platf_new_storage_type(sg_platf_storage_type_cbarg_t storage_type){
275
276   xbt_assert(!xbt_lib_get_or_null(storage_type_lib, storage_type->id,ROUTING_STORAGE_TYPE_LEVEL),
277                "Reading a storage type, processing unit \"%s\" already exists", storage_type->id);
278
279   storage_type_t stype = xbt_new0(s_storage_type_t, 1);
280   stype->model = xbt_strdup(storage_type->model);
281   stype->properties = storage_type->properties;
282   stype->content = xbt_strdup(storage_type->content);
283   stype->content_type = xbt_strdup(storage_type->content_type);
284   stype->type_id = xbt_strdup(storage_type->id);
285   stype->size = storage_type->size;
286   stype->model_properties = storage_type->model_properties;
287
288   XBT_DEBUG("ROUTING Create a storage type id '%s' with model '%s', "
289       "content '%s', and content_type '%s'",
290       stype->type_id,
291       stype->model,
292       storage_type->content,
293       storage_type->content_type);
294
295   xbt_lib_set(storage_type_lib,
296       stype->type_id,
297       ROUTING_STORAGE_TYPE_LEVEL,
298       (void *) stype);
299 }
300 void sg_platf_new_mstorage(sg_platf_mstorage_cbarg_t mstorage)
301 {
302   THROW_UNIMPLEMENTED;
303 //  mount_t mnt = xbt_new0(s_mount_t, 1);
304 //  mnt->id = xbt_strdup(mstorage->type_id);
305 //  mnt->name = xbt_strdup(mstorage->name);
306 //
307 //  if(!mount_list){
308 //    XBT_DEBUG("Creata a Mount list for %s",A_surfxml_host_id);
309 //    mount_list = xbt_dynar_new(sizeof(char *), NULL);
310 //  }
311 //  xbt_dynar_push(mount_list,(void *) mnt);
312 //  free(mnt->id);
313 //  free(mnt->name);
314 //  xbt_free(mnt);
315 //  XBT_DEBUG("ROUTING Mount a storage name '%s' with type_id '%s'",mstorage->name, mstorage->id);
316 }
317
318 static void mount_free(void *p)
319 {
320   mount_t mnt = (mount_t) p;
321   xbt_free(mnt->name);
322 }
323
324 void sg_platf_new_mount(sg_platf_mount_cbarg_t mount){
325   // Verification of an existing storage
326 #ifndef NDEBUG
327   void* storage = xbt_lib_get_or_null(storage_lib, mount->storageId, ROUTING_STORAGE_LEVEL);
328 #endif
329   xbt_assert(storage,"Disk id \"%s\" does not exists", mount->storageId);
330
331   XBT_DEBUG("ROUTING Mount '%s' on '%s'",mount->storageId, mount->name);
332
333   s_mount_t mnt;
334   mnt.storage = surf_storage_resource_priv(surf_storage_resource_by_name(mount->storageId));
335   mnt.name = xbt_strdup(mount->name);
336
337   if(!mount_list){
338     XBT_DEBUG("Create a Mount list for %s",A_surfxml_host_id);
339     mount_list = xbt_dynar_new(sizeof(s_mount_t), mount_free);
340   }
341   xbt_dynar_push(mount_list, &mnt);
342 }
343
344 void sg_platf_new_route(sg_platf_route_cbarg_t route) {
345   unsigned int iterator;
346   sg_platf_route_cb_t fun;
347   xbt_dynar_foreach(sg_platf_route_cb_list, iterator, fun) {
348     fun(route);
349   }
350 }
351 void sg_platf_new_ASroute(sg_platf_route_cbarg_t ASroute) {
352   unsigned int iterator;
353   sg_platf_route_cb_t fun;
354   xbt_dynar_foreach(sg_platf_ASroute_cb_list, iterator, fun) {
355     fun(ASroute);
356   }
357 }
358 void sg_platf_new_bypassRoute(sg_platf_route_cbarg_t bypassRoute) {
359   unsigned int iterator;
360   sg_platf_route_cb_t fun;
361   xbt_dynar_foreach(sg_platf_bypassRoute_cb_list, iterator, fun) {
362     fun(bypassRoute);
363   }
364 }
365 void sg_platf_new_bypassASroute(sg_platf_route_cbarg_t bypassASroute) {
366   unsigned int iterator;
367   sg_platf_route_cb_t fun;
368   xbt_dynar_foreach(sg_platf_bypassASroute_cb_list, iterator, fun) {
369     fun(bypassASroute);
370   }
371 }
372 void sg_platf_new_prop(sg_platf_prop_cbarg_t prop) {
373   unsigned int iterator;
374   sg_platf_prop_cb_t fun;
375   xbt_dynar_foreach(sg_platf_prop_cb_list, iterator, fun) {
376     fun(prop);
377   }
378 }
379 void sg_platf_new_trace(sg_platf_trace_cbarg_t trace) {
380   unsigned int iterator;
381   sg_platf_trace_cb_t fun;
382   xbt_dynar_foreach(sg_platf_trace_cb_list, iterator, fun) {
383     fun(trace);
384   }
385 }
386 void sg_platf_trace_connect(sg_platf_trace_connect_cbarg_t trace_connect) {
387   unsigned int iterator;
388   sg_platf_trace_connect_cb_t fun;
389   xbt_dynar_foreach(sg_platf_trace_connect_cb_list, iterator, fun) {
390     fun(trace_connect);
391   }
392 }
393
394 void sg_platf_new_process(sg_platf_process_cbarg_t process)
395 {
396   if (!simix_global)
397     xbt_die("Cannot create process without SIMIX.");
398
399   sg_host_t host = sg_host_by_name(process->host);
400   if (!host)
401     THROWF(arg_error, 0, "Host '%s' unknown", process->host);
402   xbt_main_func_t parse_code = SIMIX_get_registered_function(process->function);
403   xbt_assert(parse_code, "Function '%s' unknown", process->function);
404
405   double start_time = process->start_time;
406   double kill_time  = process->kill_time;
407   int auto_restart = process->on_failure == SURF_PROCESS_ON_FAILURE_DIE ? 0 : 1;
408
409   smx_process_arg_t arg = NULL;
410   smx_process_t process_created = NULL;
411
412   arg = xbt_new0(s_smx_process_arg_t, 1);
413   arg->code = parse_code;
414   arg->data = NULL;
415   arg->hostname = sg_host_get_name(host);
416   arg->argc = process->argc;
417   arg->argv = xbt_new(char *,process->argc);
418   int i;
419   for (i=0; i<process->argc; i++)
420     arg->argv[i] = xbt_strdup(process->argv[i]);
421   arg->name = xbt_strdup(arg->argv[0]);
422   arg->kill_time = kill_time;
423   arg->properties = current_property_set;
424   if (!sg_host_simix(host)->boot_processes) {
425     sg_host_simix(host)->boot_processes = xbt_dynar_new(sizeof(smx_process_arg_t), _SIMIX_host_free_process_arg);
426   }
427   xbt_dynar_push_as(sg_host_simix(host)->boot_processes,smx_process_arg_t,arg);
428
429   if (start_time > SIMIX_get_clock()) {
430     arg = xbt_new0(s_smx_process_arg_t, 1);
431     arg->name = (char*)(process->argv)[0];
432     arg->code = parse_code;
433     arg->data = NULL;
434     arg->hostname = sg_host_get_name(host);
435     arg->argc = process->argc;
436     arg->argv = (char**)(process->argv);
437     arg->kill_time = kill_time;
438     arg->properties = current_property_set;
439
440     XBT_DEBUG("Process %s(%s) will be started at time %f", arg->name,
441            arg->hostname, start_time);
442     SIMIX_timer_set(start_time, [](void* arg) {
443       SIMIX_process_create_from_wrapper((smx_process_arg_t) arg);
444     }, arg);
445   } else {                      // start_time <= SIMIX_get_clock()
446     XBT_DEBUG("Starting Process %s(%s) right now", process->argv[0], sg_host_get_name(host));
447
448     if (simix_global->create_process_function)
449       process_created = simix_global->create_process_function(
450                                             (char*)(process->argv)[0],
451                                             parse_code,
452                                             NULL,
453                                             sg_host_get_name(host),
454                                             kill_time,
455                                             process->argc,
456                                             (char**)(process->argv),
457                                             current_property_set,
458                                             auto_restart, NULL);
459     else
460       process_created = simcall_process_create((char*)(process->argv)[0], parse_code, NULL, sg_host_get_name(host), kill_time, process->argc,
461           (char**)process->argv, current_property_set,auto_restart);
462
463     /* verify if process has been created (won't be the case if the host is currently dead, but that's fine) */
464     if (!process_created) {
465       return;
466     }
467   }
468   current_property_set = NULL;
469 }
470
471 void sg_platf_route_begin (sg_platf_route_cbarg_t route){
472   route->link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
473 }
474 void sg_platf_ASroute_begin (sg_platf_route_cbarg_t ASroute){
475   ASroute->link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
476 }
477
478 void sg_platf_route_end (sg_platf_route_cbarg_t route){
479   sg_platf_new_route(route);
480 }
481 void sg_platf_ASroute_end (sg_platf_route_cbarg_t ASroute){
482   sg_platf_new_ASroute(ASroute);
483 }
484
485 void sg_platf_route_add_link (const char* link_id, sg_platf_route_cbarg_t route){
486   char *link_name = xbt_strdup(link_id);
487   xbt_dynar_push(route->link_list, &link_name);
488 }
489 void sg_platf_ASroute_add_link (const char* link_id, sg_platf_route_cbarg_t ASroute){
490   char *link_name = xbt_strdup(link_id);
491   xbt_dynar_push(ASroute->link_list, &link_name);
492 }
493
494 void sg_platf_begin() { /* Do nothing: just for symmetry of user code */ }
495
496 void sg_platf_end() {
497   unsigned int iterator;
498   void_f_void_t fun;
499   xbt_dynar_foreach(sg_platf_postparse_cb_list, iterator, fun) {
500     fun();
501   }
502 }
503
504 void sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS)
505 {
506   if (!surf_parse_models_setup_already_called) {
507     /* Initialize the surf models. That must be done after we got all config, and before we need the models.
508      * That is, after the last <config> tag, if any, and before the first of cluster|peer|AS|trace|trace_connect
509      *
510      * I'm not sure for <trace> and <trace_connect>, there may be a bug here
511      * (FIXME: check it out by creating a file beginning with one of these tags)
512      * but cluster and peer create ASes internally, so putting the code in there is ok.
513      *
514      * TODO, There used to be a guard protecting here against
515      * xbt_dynar_length(sg_platf_AS_begin_cb_list) because we don't want to
516      * initialize the models if we are parsing the file to get the deployment.
517      * That could happen if the same file would be used for platf and deploy:
518      * it'd contain AS tags even during the deploy parsing. Removing that guard
519      * would result of the models to get re-inited when parsing for deploy.
520      * Currently using the same file for platform and deployment is broken
521      * however. This guard will have to ba adapted in order to make this feature
522      * work again.
523      */
524     surf_parse_models_setup_already_called = 1;
525     surf_config_models_setup();
526   }
527
528   routing_AS_begin(AS);
529   if (TRACE_is_enabled())
530     sg_instr_AS_begin(AS);
531 }
532
533 void sg_platf_new_AS_end()
534 {
535   routing_AS_end();
536   if (TRACE_is_enabled())
537     sg_instr_AS_end();
538 }
539
540 /* ***************************************** */
541 /* TUTORIAL: New TAG                         */
542
543 void sg_platf_new_gpu(sg_platf_gpu_cbarg_t gpu) {
544   unsigned int iterator;
545   void_f_void_t fun;
546   xbt_dynar_foreach(sg_platf_gpu_cb_list, iterator, fun) {
547     fun();
548   }
549 }
550
551 void sg_platf_gpu_add_cb(sg_platf_gpu_cb_t fct) {
552   xbt_dynar_push(sg_platf_gpu_cb_list, &fct);
553 }
554
555 /* ***************************************** */
556
557
558 void sg_platf_host_add_cb(sg_platf_host_cb_t fct) {
559   xbt_dynar_push(sg_platf_host_cb_list, &fct);
560 }
561 void sg_platf_host_link_add_cb(sg_platf_host_link_cb_t fct) {
562   xbt_dynar_push(sg_platf_host_link_cb_list, &fct);
563 }
564 void sg_platf_link_add_cb(sg_platf_link_cb_t fct) {
565   xbt_dynar_push(sg_platf_link_cb_list, &fct);
566 }
567 void sg_platf_peer_add_cb(sg_platf_peer_cb_t fct) {
568   xbt_dynar_push(sg_platf_peer_cb_list, &fct);
569 }
570 void sg_platf_cluster_add_cb(sg_platf_cluster_cb_t fct) {
571   xbt_dynar_push(sg_platf_cluster_cb_list, &fct);
572 }
573 void sg_platf_cabinet_add_cb(sg_platf_cabinet_cb_t fct) {
574   xbt_dynar_push(sg_platf_cabinet_cb_list, &fct);
575 }
576 void sg_platf_postparse_add_cb(void_f_void_t fct) {
577   xbt_dynar_push(sg_platf_postparse_cb_list, &fct);
578 }
579 void sg_platf_route_add_cb(sg_platf_route_cb_t fct) {
580   xbt_dynar_push(sg_platf_route_cb_list, &fct);
581 }
582 void sg_platf_ASroute_add_cb(sg_platf_route_cb_t fct) {
583   xbt_dynar_push(sg_platf_ASroute_cb_list, &fct);
584 }
585 void sg_platf_bypassRoute_add_cb(sg_platf_route_cb_t fct) {
586   xbt_dynar_push(sg_platf_bypassRoute_cb_list, &fct);
587 }
588 void sg_platf_bypassASroute_add_cb(sg_platf_route_cb_t fct) {
589   xbt_dynar_push(sg_platf_bypassASroute_cb_list, &fct);
590 }
591 void sg_platf_prop_add_cb(sg_platf_prop_cb_t fct) {
592   xbt_dynar_push(sg_platf_prop_cb_list, &fct);
593 }
594 void sg_platf_trace_add_cb(sg_platf_trace_cb_t fct) {
595   xbt_dynar_push(sg_platf_trace_cb_list, &fct);
596 }
597 void sg_platf_trace_connect_add_cb(sg_platf_trace_connect_cb_t fct) {
598   xbt_dynar_push(sg_platf_trace_connect_cb_list, &fct);
599 }
600 void sg_platf_rng_stream_init(unsigned long seed[6]) {
601   RngStream_SetPackageSeed(seed);
602   sg_platf_rng_stream = RngStream_CreateStream(NULL);
603 }
604
605 RngStream sg_platf_rng_stream_get(const char* id) {
606   RngStream stream = NULL;
607   unsigned int id_hash;
608
609   stream = RngStream_CopyStream(sg_platf_rng_stream);
610   id_hash = xbt_str_hash(id);
611   RngStream_AdvanceState(stream, 0, (long)id_hash);
612
613   return stream;
614 }