1 /* Copyright (c) 2006-2014. The SimGrid Team.
2 * All rights reserved. */
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. */
11 #include "xbt/RngStream.h"
12 #include <xbt/signal.hpp>
13 #include "simgrid/platf_interface.h"
14 #include "surf/surf.h"
16 #include "src/simix/smx_private.h"
17 #include "src/surf/platform.hpp"
19 #include "surf/surfxml_parse.h"// FIXME: brain dead public header
21 #include "src/surf/platform.hpp"
22 #include "src/surf/cpu_interface.hpp"
23 #include "src/surf/host_interface.hpp"
24 #include "src/surf/network_interface.hpp"
25 #include "surf/surf_routing.h" // FIXME: brain dead public header
26 #include "src/surf/surf_routing_cluster.hpp"
27 #include "src/surf/surf_routing_cluster_torus.hpp"
28 #include "src/surf/surf_routing_cluster_fat_tree.hpp"
30 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_parse);
32 XBT_PRIVATE xbt_dynar_t mount_list = NULL;
37 simgrid::xbt::signal<void(sg_platf_link_cbarg_t)> on_link;
38 simgrid::xbt::signal<void(sg_platf_cluster_cbarg_t)> on_cluster;
39 simgrid::xbt::signal<void(void)> on_postparse;
44 static int surf_parse_models_setup_already_called = 0;
46 /* one RngStream for the platform, to respect some statistic rules */
47 static RngStream sg_platf_rng_stream = NULL;
49 /** Module management function: creates all internal data structures */
50 void sg_platf_init(void) {
53 /** Module management function: frees all internal data structures */
54 void sg_platf_exit(void) {
55 simgrid::surf::on_link.disconnect_all_slots();
56 simgrid::surf::on_cluster.disconnect_all_slots();
57 simgrid::surf::on_postparse.disconnect_all_slots();
59 /* make sure that we will reinit the models while loading the platf once reinited */
60 surf_parse_models_setup_already_called = 0;
63 /** @brief Add an "host" to the current AS */
64 void sg_platf_new_host(sg_platf_host_cbarg_t host)
66 xbt_assert(! sg_host_by_name(host->id),
67 "Refusing to create a second host named '%s'.", host->id);
69 simgrid::surf::As* current_routing = routing_get_current();
70 if (current_routing->hierarchy_ == SURF_ROUTING_NULL)
71 current_routing->hierarchy_ = SURF_ROUTING_BASE;
73 simgrid::surf::NetCard *netcard =
74 new simgrid::surf::NetCardImpl(host->id, SURF_NETWORK_ELEMENT_HOST, current_routing);
76 netcard->setId(current_routing->addComponent(netcard));
77 sg_host_t h = simgrid::s4u::Host::by_name_or_create(host->id);
78 h->pimpl_netcard = netcard;
79 simgrid::surf::netcardCreatedCallbacks(netcard);
82 xbt_lib_set(storage_lib, host->id, ROUTING_STORAGE_HOST_LEVEL, (void *) mount_list);
86 if (host->coord && strcmp(host->coord, "")) {
90 if (!COORD_HOST_LEVEL)
91 xbt_die ("To use host coordinates, please add --cfg=network/coordinates:yes to your command line");
92 /* Pre-parse the host coordinates -- FIXME factorize with routers by overloading the routing->parse_PU function*/
93 xbt_dynar_t ctn_str = xbt_str_split_str(host->coord, " ");
94 xbt_dynar_t ctn = xbt_dynar_new(sizeof(double),NULL);
95 xbt_dynar_foreach(ctn_str,cursor, str) {
96 double val = xbt_str_parse_double(str, "Invalid coordinate: %s");
97 xbt_dynar_push(ctn,&val);
99 xbt_dynar_shrink(ctn, 0);
100 xbt_dynar_free(&ctn_str);
101 h->extension_set(COORD_HOST_LEVEL, (void *) ctn);
102 XBT_DEBUG("Having set host coordinates for '%s'",host->id);
106 simgrid::surf::Cpu *cpu = surf_cpu_model_pm->createCpu( h,
109 host->speed_scale, host->speed_trace,
111 host->initiallyOn, host->state_trace);
112 surf_host_model->createHost(host->id, netcard, cpu, host->properties)->attach(h);
113 simgrid::s4u::Host::onCreation(*h);
115 if (TRACE_is_enabled() && TRACE_needs_platform())
116 sg_instr_new_host(host);
120 * \brief Add a "router" to the network element list
122 void sg_platf_new_router(sg_platf_router_cbarg_t router)
124 simgrid::surf::As* current_routing = routing_get_current();
126 if (current_routing->hierarchy_ == SURF_ROUTING_NULL)
127 current_routing->hierarchy_ = SURF_ROUTING_BASE;
128 xbt_assert(!xbt_lib_get_or_null(as_router_lib, router->id, ROUTING_ASR_LEVEL),
129 "Reading a router, processing unit \"%s\" already exists",
132 simgrid::surf::NetCard *info = new simgrid::surf::NetCardImpl(router->id, SURF_NETWORK_ELEMENT_ROUTER, current_routing);
133 info->setId(current_routing->addComponent(info));
134 xbt_lib_set(as_router_lib, router->id, ROUTING_ASR_LEVEL, (void *) info);
135 XBT_DEBUG("Having set name '%s' id '%d'", router->id, info->id());
136 simgrid::surf::netcardCreatedCallbacks(info);
138 if (router->coord && strcmp(router->coord, "")) {
142 if (!COORD_ASR_LEVEL)
143 xbt_die ("To use host coordinates, please add --cfg=network/coordinates:yes to your command line");
144 /* Pre-parse the host coordinates */
145 xbt_dynar_t ctn_str = xbt_str_split_str(router->coord, " ");
146 xbt_dynar_t ctn = xbt_dynar_new(sizeof(double),NULL);
147 xbt_dynar_foreach(ctn_str,cursor, str) {
148 double val = xbt_str_parse_double(str, "Invalid coordinate: %s");
149 xbt_dynar_push(ctn,&val);
151 xbt_dynar_shrink(ctn, 0);
152 xbt_dynar_free(&ctn_str);
153 xbt_lib_set(as_router_lib, router->id, COORD_ASR_LEVEL, (void *) ctn);
154 XBT_DEBUG("Having set router coordinates for '%s'",router->id);
157 if (TRACE_is_enabled() && TRACE_needs_platform())
158 sg_instr_new_router(router);
161 void sg_platf_new_link(sg_platf_link_cbarg_t link){
162 simgrid::surf::on_link(link);
165 void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
167 using simgrid::surf::AsCluster;
168 using simgrid::surf::AsClusterTorus;
169 using simgrid::surf::AsClusterFatTree;
171 char *host_id, *groups, *link_id = NULL;
172 xbt_dict_t patterns = NULL;
175 s_sg_platf_host_cbarg_t host = SG_PLATF_HOST_INITIALIZER;
176 s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
180 if ((cluster->availability_trace && strcmp(cluster->availability_trace, ""))
181 || (cluster->state_trace && strcmp(cluster->state_trace, ""))) {
182 patterns = xbt_dict_new_homogeneous(xbt_free_f);
183 xbt_dict_set(patterns, "id", xbt_strdup(cluster->id), NULL);
184 xbt_dict_set(patterns, "prefix", xbt_strdup(cluster->prefix), NULL);
185 xbt_dict_set(patterns, "suffix", xbt_strdup(cluster->suffix), NULL);
188 /* Parse the topology attributes.
189 * Nothing to do in a vanilla cluster, but that's another story for torus and flat_trees */
190 s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER;
193 switch (cluster->topology) {
194 case SURF_CLUSTER_TORUS:
195 AS.routing = A_surfxml_AS_routing_ClusterTorus;
197 case SURF_CLUSTER_FAT_TREE:
198 AS.routing = A_surfxml_AS_routing_ClusterFatTree;
201 AS.routing = A_surfxml_AS_routing_Cluster;
205 // What an inventive way of initializing the AS that I have as ancestor :-(
206 sg_platf_new_AS_begin(&AS);
207 simgrid::surf::As *current_routing = routing_get_current();
208 static_cast<AsCluster*>(current_routing)->parse_specific_arguments(cluster);
210 if(cluster->loopback_bw!=0 || cluster->loopback_lat!=0){
211 ((AsCluster*)current_routing)->nb_links_per_node_++;
212 ((AsCluster*)current_routing)->has_loopback_=1;
215 if(cluster->limiter_link!=0){
216 ((AsCluster*)current_routing)->nb_links_per_node_++;
217 ((AsCluster*)current_routing)->has_limiter_=1;
222 xbt_dynar_t radical_elements = xbt_str_split(cluster->radical, ",");
223 xbt_dynar_foreach(radical_elements, iter, groups) {
225 xbt_dynar_t radical_ends = xbt_str_split(groups, "-");
226 int start = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 0, char *));
229 switch (xbt_dynar_length(radical_ends)) {
234 end = surf_parse_get_int(xbt_dynar_get_as(radical_ends, 1, char *));
237 surf_parse_error("Malformed radical");
240 for (int i = start; i <= end; i++) {
241 host_id = bprintf("%s%d%s", cluster->prefix, i, cluster->suffix);
242 link_id = bprintf("%s_link_%d", cluster->id, i);
244 XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, cluster->speed);
246 memset(&host, 0, sizeof(host));
248 if ((cluster->properties != NULL) && (!xbt_dict_is_empty(cluster->properties))) {
249 xbt_dict_cursor_t cursor=NULL;
251 host.properties = xbt_dict_new();
253 xbt_dict_foreach(cluster->properties,cursor,key,data) {
254 xbt_dict_set(host.properties, key, xbt_strdup(data),free);
257 if (cluster->availability_trace && strcmp(cluster->availability_trace, "")) {
258 xbt_dict_set(patterns, "radical", bprintf("%d", i), NULL);
259 char *avail_file = xbt_str_varsubst(cluster->availability_trace, patterns);
260 XBT_DEBUG("\tavailability_file=\"%s\"", avail_file);
261 host.speed_trace = tmgr_trace_new_from_file(avail_file);
262 xbt_free(avail_file);
264 XBT_DEBUG("\tavailability_file=\"\"");
267 if (cluster->state_trace && strcmp(cluster->state_trace, "")) {
268 char *avail_file = xbt_str_varsubst(cluster->state_trace, patterns);
269 XBT_DEBUG("\tstate_file=\"%s\"", avail_file);
270 host.state_trace = tmgr_trace_new_from_file(avail_file);
271 xbt_free(avail_file);
273 XBT_DEBUG("\tstate_file=\"\"");
276 host.speed_peak = xbt_dynar_new(sizeof(double), NULL);
277 xbt_dynar_push(host.speed_peak,&cluster->speed);
280 //host.power_peak = cluster->power;
281 host.speed_scale = 1.0;
282 host.core_amount = cluster->core_amount;
283 host.initiallyOn = 1;
285 sg_platf_new_host(&host);
286 xbt_dynar_free(&host.speed_peak);
287 XBT_DEBUG("</host>");
289 XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id,
290 cluster->bw, cluster->lat);
293 s_surf_parsing_link_up_down_t info_lim, info_loop;
294 // All links are saved in a matrix;
295 // every row describes a single node; every node
296 // may have multiple links.
297 // the first column may store a link from x to x if p_has_loopback is set
298 // the second column may store a limiter link if p_has_limiter is set
299 // other columns are to store one or more link for the node
301 //add a loopback link
302 if(cluster->loopback_bw!=0 || cluster->loopback_lat!=0){
303 char *tmp_link = bprintf("%s_loopback", link_id);
304 XBT_DEBUG("<loopback\tid=\"%s\"\tbw=\"%f\"/>", tmp_link,
305 cluster->limiter_link);
308 memset(&link, 0, sizeof(link));
310 link.bandwidth = cluster->loopback_bw;
311 link.latency = cluster->loopback_lat;
312 link.initiallyOn = 1;
313 link.policy = SURF_LINK_FATPIPE;
314 sg_platf_new_link(&link);
315 info_loop.link_up = Link::byName(tmp_link);
316 info_loop.link_down = info_loop.link_up;
318 xbt_dynar_set(current_routing->upDownLinks,
319 rankId*(static_cast<AsCluster*>(current_routing))->nb_links_per_node_, &info_loop);
322 //add a limiter link (shared link to account for maximal bandwidth of the node)
323 if(cluster->limiter_link!=0){
324 char *tmp_link = bprintf("%s_limiter", link_id);
325 XBT_DEBUG("<limiter\tid=\"%s\"\tbw=\"%f\"/>", tmp_link,
326 cluster->limiter_link);
329 memset(&link, 0, sizeof(link));
331 link.bandwidth = cluster->limiter_link;
333 link.initiallyOn = 1;
334 link.policy = SURF_LINK_SHARED;
335 sg_platf_new_link(&link);
336 info_lim.link_up = Link::byName(tmp_link);
337 info_lim.link_down = info_lim.link_up;
339 auto as_cluster = static_cast<AsCluster*>(current_routing);
340 xbt_dynar_set(current_routing->upDownLinks,
341 rankId*(as_cluster)->nb_links_per_node_ + as_cluster->has_loopback_ ,
347 //call the cluster function that adds the others links
348 if (cluster->topology == SURF_CLUSTER_FAT_TREE) {
349 ((AsClusterFatTree*) current_routing)->addProcessingNode(i);
352 static_cast<AsCluster*>(current_routing)->create_links_for_node(cluster, i, rankId, rankId*
353 static_cast<AsCluster*>(current_routing)->nb_links_per_node_
354 + static_cast<AsCluster*>(current_routing)->has_loopback_
355 + static_cast<AsCluster*>(current_routing)->has_limiter_ );
362 xbt_dynar_free(&radical_ends);
364 xbt_dynar_free(&radical_elements);
366 // For fat trees, the links must be created once all nodes have been added
367 if(cluster->topology == SURF_CLUSTER_FAT_TREE) {
368 static_cast<simgrid::surf::AsClusterFatTree*>(current_routing)->create_links();
370 // Add a router. It is magically used thanks to the way in which surf_routing_cluster is written,
371 // and it's very useful to connect clusters together
373 XBT_DEBUG("<router id=\"%s\"/>", cluster->router_id);
375 s_sg_platf_router_cbarg_t router = SG_PLATF_ROUTER_INITIALIZER;
376 memset(&router, 0, sizeof(router));
377 router.id = cluster->router_id;
379 if (!router.id || !strcmp(router.id, ""))
381 bprintf("%s%s_router%s", cluster->prefix, cluster->id,
383 sg_platf_new_router(&router);
384 ((AsCluster*)current_routing)->router_ = (simgrid::surf::NetCard*) xbt_lib_get_or_null(as_router_lib, router.id, ROUTING_ASR_LEVEL);
388 if ((cluster->bb_bw != 0) || (cluster->bb_lat != 0)) {
389 char *link_backbone = bprintf("%s_backbone", cluster->id);
390 XBT_DEBUG("<link\tid=\"%s\" bw=\"%f\" lat=\"%f\"/>", link_backbone,
391 cluster->bb_bw, cluster->bb_lat);
393 memset(&link, 0, sizeof(link));
394 link.id = link_backbone;
395 link.bandwidth = cluster->bb_bw;
396 link.latency = cluster->bb_lat;
397 link.initiallyOn = 1;
398 link.policy = cluster->bb_sharing_policy;
400 sg_platf_new_link(&link);
402 routing_cluster_add_backbone(Link::byName(link_backbone));
408 sg_platf_new_AS_end();
410 xbt_dict_free(&patterns); // no op if it were never set
412 simgrid::surf::on_cluster(cluster);
415 void sg_platf_new_storage(sg_platf_storage_cbarg_t storage)
417 xbt_assert(!xbt_lib_get_or_null(storage_lib, storage->id,ROUTING_STORAGE_LEVEL),
418 "Refusing to add a second storage named \"%s\"", storage->id);
420 void* stype = xbt_lib_get_or_null(storage_type_lib, storage->type_id,ROUTING_STORAGE_TYPE_LEVEL);
421 xbt_assert(stype,"No storage type '%s'", storage->type_id);
423 XBT_DEBUG("ROUTING Create a storage name '%s' with type_id '%s' and content '%s'",
428 xbt_lib_set(storage_lib,
430 ROUTING_STORAGE_LEVEL,
431 (void *) xbt_strdup(storage->type_id));
433 // if storage content is not specified use the content of storage_type if any
434 if(!strcmp(storage->content,"") && strcmp(((storage_type_t) stype)->content,"")){
435 storage->content = ((storage_type_t) stype)->content;
436 storage->content_type = ((storage_type_t) stype)->content_type;
437 XBT_DEBUG("For disk '%s' content is empty, inherit the content (of type %s) from storage type '%s' ",
438 storage->id,((storage_type_t) stype)->content_type,
439 ((storage_type_t) stype)->type_id);
442 XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s' "
443 "\n\t\tmodel '%s' \n\t\tcontent '%s'\n\t\tcontent_type '%s' "
444 "\n\t\tproperties '%p''\n",
446 ((storage_type_t) stype)->model,
447 ((storage_type_t) stype)->type_id,
449 storage->content_type,
450 storage->properties);
452 surf_storage_model->createStorage(storage->id,
453 ((storage_type_t) stype)->type_id,
455 storage->content_type,
459 void sg_platf_new_storage_type(sg_platf_storage_type_cbarg_t storage_type){
461 xbt_assert(!xbt_lib_get_or_null(storage_type_lib, storage_type->id,ROUTING_STORAGE_TYPE_LEVEL),
462 "Reading a storage type, processing unit \"%s\" already exists", storage_type->id);
464 storage_type_t stype = xbt_new0(s_storage_type_t, 1);
465 stype->model = xbt_strdup(storage_type->model);
466 stype->properties = storage_type->properties;
467 stype->content = xbt_strdup(storage_type->content);
468 stype->content_type = xbt_strdup(storage_type->content_type);
469 stype->type_id = xbt_strdup(storage_type->id);
470 stype->size = storage_type->size;
471 stype->model_properties = storage_type->model_properties;
473 XBT_DEBUG("ROUTING Create a storage type id '%s' with model '%s', "
474 "content '%s', and content_type '%s'",
477 storage_type->content,
478 storage_type->content_type);
480 xbt_lib_set(storage_type_lib,
482 ROUTING_STORAGE_TYPE_LEVEL,
485 void sg_platf_new_mstorage(sg_platf_mstorage_cbarg_t mstorage)
490 static void mount_free(void *p)
492 mount_t mnt = (mount_t) p;
496 void sg_platf_new_mount(sg_platf_mount_cbarg_t mount){
497 // Verification of an existing storage
498 xbt_assert(xbt_lib_get_or_null(storage_lib, mount->storageId, ROUTING_STORAGE_LEVEL),
499 "Cannot mount non-existent disk \"%s\"", mount->storageId);
501 XBT_DEBUG("ROUTING Mount '%s' on '%s'",mount->storageId, mount->name);
504 mnt.storage = surf_storage_resource_priv(surf_storage_resource_by_name(mount->storageId));
505 mnt.name = xbt_strdup(mount->name);
508 XBT_DEBUG("Create a Mount list for %s",A_surfxml_host_id);
509 mount_list = xbt_dynar_new(sizeof(s_mount_t), mount_free);
511 xbt_dynar_push(mount_list, &mnt);
514 void sg_platf_new_route(sg_platf_route_cbarg_t route)
516 routing_get_current()->parseRoute(route);
519 void sg_platf_new_bypassRoute(sg_platf_route_cbarg_t bypassRoute)
521 routing_get_current()->parseBypassroute(bypassRoute);
524 void sg_platf_new_process(sg_platf_process_cbarg_t process)
527 xbt_die("Cannot create process without SIMIX.");
529 sg_host_t host = sg_host_by_name(process->host);
531 // The requested host does not exist. Do a nice message to the user
532 char *tmp = bprintf("Cannot create process '%s': host '%s' does not exist\nExisting hosts: '",process->function, process->host);
533 xbt_strbuff_t msg = xbt_strbuff_new_from(tmp);
535 xbt_dynar_t all_hosts = xbt_dynar_sort_strings(sg_hosts_as_dynar());
536 simgrid::s4u::Host* host;
538 xbt_dynar_foreach(all_hosts,cursor, host) {
539 xbt_strbuff_append(msg,host->name().c_str());
540 xbt_strbuff_append(msg,"', '");
541 if (msg->used > 1024) {
542 msg->data[msg->used-3]='\0';
545 xbt_strbuff_append(msg," ...(list truncated)......");// That will be shortened by 3 chars when existing the loop
548 msg->data[msg->used-3]='\0';
549 xbt_die("%s", msg->data);
551 xbt_main_func_t parse_code = SIMIX_get_registered_function(process->function);
552 xbt_assert(parse_code, "Function '%s' unknown", process->function);
554 double start_time = process->start_time;
555 double kill_time = process->kill_time;
556 int auto_restart = process->on_failure == SURF_PROCESS_ON_FAILURE_DIE ? 0 : 1;
558 smx_process_arg_t arg = NULL;
559 smx_process_t process_created = NULL;
561 arg = xbt_new0(s_smx_process_arg_t, 1);
562 arg->code = parse_code;
564 arg->hostname = sg_host_get_name(host);
565 arg->argc = process->argc;
566 arg->argv = xbt_new(char *,process->argc);
568 for (i=0; i<process->argc; i++)
569 arg->argv[i] = xbt_strdup(process->argv[i]);
570 arg->name = xbt_strdup(arg->argv[0]);
571 arg->kill_time = kill_time;
572 arg->properties = current_property_set;
573 if (!sg_host_simix(host)->boot_processes) {
574 sg_host_simix(host)->boot_processes = xbt_dynar_new(sizeof(smx_process_arg_t), _SIMIX_host_free_process_arg);
576 xbt_dynar_push_as(sg_host_simix(host)->boot_processes,smx_process_arg_t,arg);
578 if (start_time > SIMIX_get_clock()) {
579 arg = xbt_new0(s_smx_process_arg_t, 1);
580 arg->name = (char*)(process->argv)[0];
581 arg->code = parse_code;
583 arg->hostname = sg_host_get_name(host);
584 arg->argc = process->argc;
585 arg->argv = (char**)(process->argv);
586 arg->kill_time = kill_time;
587 arg->properties = current_property_set;
589 XBT_DEBUG("Process %s(%s) will be started at time %f", arg->name,
590 arg->hostname, start_time);
591 SIMIX_timer_set(start_time, [](void* arg) {
592 SIMIX_process_create_from_wrapper((smx_process_arg_t) arg);
594 } else { // start_time <= SIMIX_get_clock()
595 XBT_DEBUG("Starting Process %s(%s) right now", arg->name, sg_host_get_name(host));
597 if (simix_global->create_process_function)
598 process_created = simix_global->create_process_function(
602 sg_host_get_name(host),
605 (char**)(process->argv),
606 current_property_set,
609 process_created = simcall_process_create(arg->name, parse_code, NULL, sg_host_get_name(host), kill_time, process->argc,
610 (char**)process->argv, current_property_set,auto_restart);
612 /* verify if process has been created (won't be the case if the host is currently dead, but that's fine) */
613 if (!process_created) {
617 current_property_set = NULL;
620 void sg_platf_route_begin (sg_platf_route_cbarg_t route){
621 route->link_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
624 void sg_platf_route_end (sg_platf_route_cbarg_t route){
625 sg_platf_new_route(route);
628 void sg_platf_route_add_link (const char* link_id, sg_platf_route_cbarg_t route){
629 char *link_name = xbt_strdup(link_id);
630 xbt_dynar_push(route->link_list, &link_name);
632 void sg_platf_ASroute_add_link (const char* link_id, sg_platf_route_cbarg_t ASroute){
633 char *link_name = xbt_strdup(link_id);
634 xbt_dynar_push(ASroute->link_list, &link_name);
637 void sg_platf_begin() { /* Do nothing: just for symmetry of user code */ }
639 void sg_platf_end() {
640 simgrid::surf::on_postparse();
643 void sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS)
645 if (!surf_parse_models_setup_already_called) {
646 /* Initialize the surf models. That must be done after we got all config, and before we need the models.
647 * That is, after the last <config> tag, if any, and before the first of cluster|peer|AS|trace|trace_connect
649 * I'm not sure for <trace> and <trace_connect>, there may be a bug here
650 * (FIXME: check it out by creating a file beginning with one of these tags)
651 * but cluster and peer create ASes internally, so putting the code in there is ok.
653 * TODO, There used to be a guard protecting here against
654 * xbt_dynar_length(sg_platf_AS_begin_cb_list) because we don't want to
655 * initialize the models if we are parsing the file to get the deployment.
656 * That could happen if the same file would be used for platf and deploy:
657 * it'd contain AS tags even during the deploy parsing. Removing that guard
658 * would result of the models to get re-inited when parsing for deploy.
659 * Currently using the same file for platform and deployment is broken
660 * however. This guard will have to ba adapted in order to make this feature
663 surf_parse_models_setup_already_called = 1;
664 surf_config_models_setup();
667 routing_AS_begin(AS);
668 if (TRACE_is_enabled())
669 sg_instr_AS_begin(AS);
672 void sg_platf_new_AS_end()
675 if (TRACE_is_enabled())
678 /* ***************************************** */
680 void sg_platf_rng_stream_init(unsigned long seed[6]) {
681 RngStream_SetPackageSeed(seed);
682 sg_platf_rng_stream = RngStream_CreateStream(NULL);
685 RngStream sg_platf_rng_stream_get(const char* id) {
686 RngStream stream = NULL;
687 unsigned int id_hash;
689 stream = RngStream_CopyStream(sg_platf_rng_stream);
690 id_hash = xbt_str_hash(id);
691 RngStream_AdvanceState(stream, 0, (long)id_hash);