+ using simgrid::surf::AsCluster;
+ using simgrid::surf::AsClusterTorus;
+ using simgrid::surf::AsClusterFatTree;
+
+ int rankId=0;
+
+ s_sg_platf_link_cbarg_t link;
+
+ // What an inventive way of initializing the AS that I have as ancestor :-(
+ s_sg_platf_AS_cbarg_t AS;
+ AS.id = cluster->id;
+ switch (cluster->topology) {
+ case SURF_CLUSTER_TORUS:
+ AS.routing = A_surfxml_AS_routing_ClusterTorus;
+ break;
+ case SURF_CLUSTER_FAT_TREE:
+ AS.routing = A_surfxml_AS_routing_ClusterFatTree;
+ break;
+ default:
+ AS.routing = A_surfxml_AS_routing_Cluster;
+ break;
+ }
+ sg_platf_new_AS_begin(&AS);
+ simgrid::surf::AsCluster *current_as = static_cast<AsCluster*>(routing_get_current());
+ current_as->parse_specific_arguments(cluster);
+
+ if(cluster->loopback_bw!=0 || cluster->loopback_lat!=0){
+ current_as->nb_links_per_node_++;
+ current_as->has_loopback_ = 1;
+ }
+
+ if(cluster->limiter_link!=0){
+ current_as->nb_links_per_node_++;
+ current_as->has_limiter_ = 1;
+ }
+
+ std::vector<int> *radicals = explodesRadical(cluster->radical);
+ for (int i : *radicals) {
+ char * host_id = bprintf("%s%d%s", cluster->prefix, i, cluster->suffix);
+ char * link_id = bprintf("%s_link_%d", cluster->id, i);
+
+ XBT_DEBUG("<host\tid=\"%s\"\tpower=\"%f\">", host_id, cluster->speed);
+
+ s_sg_platf_host_cbarg_t host;
+ memset(&host, 0, sizeof(host));
+ host.id = host_id;
+ if ((cluster->properties != NULL) && (!xbt_dict_is_empty(cluster->properties))) {
+ xbt_dict_cursor_t cursor=NULL;
+ char *key,*data;
+ host.properties = xbt_dict_new();
+
+ xbt_dict_foreach(cluster->properties,cursor,key,data) {
+ xbt_dict_set(host.properties, key, xbt_strdup(data),free);
+ }
+ }
+
+ host.speed_per_pstate = xbt_dynar_new(sizeof(double), NULL);
+ xbt_dynar_push(host.speed_per_pstate,&cluster->speed);
+ host.pstate = 0;
+ host.core_amount = cluster->core_amount;
+ host.coord = "";
+ sg_platf_new_host(&host);
+ xbt_dynar_free(&host.speed_per_pstate);
+ XBT_DEBUG("</host>");
+
+ XBT_DEBUG("<link\tid=\"%s\"\tbw=\"%f\"\tlat=\"%f\"/>", link_id, cluster->bw, cluster->lat);
+
+ s_surf_parsing_link_up_down_t info_lim, info_loop;
+ // All links are saved in a matrix;
+ // every row describes a single node; every node
+ // may have multiple links.
+ // the first column may store a link from x to x if p_has_loopback is set
+ // the second column may store a limiter link if p_has_limiter is set
+ // other columns are to store one or more link for the node
+
+ //add a loopback link
+ if(cluster->loopback_bw!=0 || cluster->loopback_lat!=0){
+ char *tmp_link = bprintf("%s_loopback", link_id);
+ XBT_DEBUG("<loopback\tid=\"%s\"\tbw=\"%f\"/>", tmp_link, cluster->limiter_link);
+
+ memset(&link, 0, sizeof(link));
+ link.id = tmp_link;
+ link.bandwidth = cluster->loopback_bw;
+ link.latency = cluster->loopback_lat;
+ link.policy = SURF_LINK_FATPIPE;
+ sg_platf_new_link(&link);
+ info_loop.link_up = info_loop.link_down = Link::byName(tmp_link);
+ free(tmp_link);
+ auto as_cluster = static_cast<AsCluster*>(current_as);
+ xbt_dynar_set(as_cluster->privateLinks_, rankId*as_cluster->nb_links_per_node_, &info_loop);
+ }
+
+ //add a limiter link (shared link to account for maximal bandwidth of the node)
+ if(cluster->limiter_link!=0){
+ char *tmp_link = bprintf("%s_limiter", link_id);
+ XBT_DEBUG("<limiter\tid=\"%s\"\tbw=\"%f\"/>", tmp_link, cluster->limiter_link);
+
+ memset(&link, 0, sizeof(link));
+ link.id = tmp_link;
+ link.bandwidth = cluster->limiter_link;
+ link.latency = 0;
+ link.policy = SURF_LINK_SHARED;
+ sg_platf_new_link(&link);
+ info_lim.link_up = info_lim.link_down = Link::byName(tmp_link);
+ free(tmp_link);
+ xbt_dynar_set(current_as->privateLinks_, rankId * current_as->nb_links_per_node_ + current_as->has_loopback_ , &info_lim);
+ }
+
+ //call the cluster function that adds the others links
+ if (cluster->topology == SURF_CLUSTER_FAT_TREE) {
+ ((AsClusterFatTree*) current_as)->addProcessingNode(i);
+ }
+ else {
+ current_as->create_links_for_node(cluster, i, rankId,
+ rankId*current_as->nb_links_per_node_ + current_as->has_loopback_ + current_as->has_limiter_ );
+ }
+ xbt_free(link_id);
+ xbt_free(host_id);
+ rankId++;
+ }
+ delete radicals;
+
+ // Add a router. It is magically used thanks to the way in which surf_routing_cluster is written,
+ // and it's very useful to connect clusters together
+ XBT_DEBUG(" ");
+ XBT_DEBUG("<router id=\"%s\"/>", cluster->router_id);
+ char *newid = NULL;
+ s_sg_platf_router_cbarg_t router;
+ memset(&router, 0, sizeof(router));
+ router.id = cluster->router_id;
+ if (!router.id || !strcmp(router.id, ""))
+ router.id = newid = bprintf("%s%s_router%s", cluster->prefix, cluster->id, cluster->suffix);
+ sg_platf_new_router(&router);
+ current_as->router_ = (simgrid::surf::NetCard*) xbt_lib_get_or_null(as_router_lib, router.id, ROUTING_ASR_LEVEL);
+ free(newid);
+
+ //Make the backbone
+ if ((cluster->bb_bw != 0) || (cluster->bb_lat != 0)) {
+
+ memset(&link, 0, sizeof(link));
+ link.id = bprintf("%s_backbone", cluster->id);
+ link.bandwidth = cluster->bb_bw;
+ link.latency = cluster->bb_lat;
+ link.policy = cluster->bb_sharing_policy;
+
+ XBT_DEBUG("<link\tid=\"%s\" bw=\"%f\" lat=\"%f\"/>", link.id, cluster->bb_bw, cluster->bb_lat);
+ sg_platf_new_link(&link);
+
+ routing_cluster_add_backbone(Link::byName(link.id));
+ free((char*)link.id);
+ }
+
+ XBT_DEBUG("</AS>");
+ sg_platf_new_AS_seal();