Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
display on configuration output whether the mallocators are activated or not
[simgrid.git] / teshsuite / simdag / platforms / flatifier.c
1 /* Copyright (c) 2008, 2009, 2010. 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 #ifndef _XBT_WIN32
8 #include <unistd.h>
9 #endif
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <time.h>
14 #include <string.h>
15 #include <math.h>
16
17
18 #include "simdag/simdag.h"
19 #include "xbt/log.h"
20 #include "xbt/dict.h"
21 #include "xbt/ex.h"
22 #include "surf/surf.h"
23 #include "surf/surf_private.h"
24
25 XBT_LOG_NEW_DEFAULT_CATEGORY(flatifier,
26                              "Logging specific to this platform parsing tool");
27
28 static int name_compare_hosts(const void *n1, const void *n2)
29 {
30   char name1[80], name2[80];
31   strcpy(name1, SD_workstation_get_name(*((SD_workstation_t *) n1)));
32   strcpy(name2, SD_workstation_get_name(*((SD_workstation_t *) n2)));
33
34   return strcmp(name1, name2);
35 }
36
37 static int name_compare_links(const void *n1, const void *n2)
38 {
39   char name1[80], name2[80];
40   strcpy(name1, SD_link_get_name(*((SD_link_t *) n1)));
41   strcpy(name2, SD_link_get_name(*((SD_link_t *) n2)));
42
43   return strcmp(name1, name2);
44 }
45
46 int main(int argc, char **argv)
47 {
48   char *platformFile = NULL;
49   int totalHosts, totalLinks;
50   int timings=0;
51   unsigned int i;
52   xbt_dict_t props = NULL;
53   xbt_dict_cursor_t cursor = NULL;
54   xbt_lib_cursor_t cursor_src = NULL;
55   xbt_lib_cursor_t cursor_dst = NULL;
56   char *src,*dst,*key,*data;
57   sg_routing_edge_t value1;
58   sg_routing_edge_t value2;
59   xbt_ex_t e;
60
61   const SD_workstation_t *hosts;
62   const SD_link_t *links;
63   xbt_os_timer_t parse_time = xbt_os_timer_new();
64
65   setvbuf(stdout, NULL, _IOLBF, 0);
66
67   SD_init(&argc, argv);
68
69   platformFile = argv[1];
70   if (!strcmp(platformFile,"--timings")) {
71      platformFile=argv[2];
72      timings=1;
73   }
74       
75   XBT_DEBUG("%s", platformFile);
76   TRY {
77     xbt_os_timer_start(parse_time);
78     SD_create_environment(platformFile);
79     xbt_os_timer_stop(parse_time);
80   }
81   CATCH(e) {
82     xbt_die("Error while loading %s: %s",platformFile,e.msg);
83   }
84
85   if (timings) {
86     XBT_INFO("Parsing time: %fs (%d hosts, %d links)",
87           xbt_os_timer_elapsed(parse_time),SD_workstation_get_number(),SD_link_get_number());
88   } else {
89     printf("<?xml version='1.0'?>\n");
90     printf("<!DOCTYPE platform SYSTEM \"http://simgrid.gforge.inria.fr/simgrid.dtd\">\n");
91     printf("<platform version=\"3\">\n");
92     printf("<AS id=\"AS0\" routing=\"Full\">\n");
93
94     // Hosts
95     totalHosts = SD_workstation_get_number();
96     hosts = SD_workstation_get_list();
97     qsort((void *) hosts, totalHosts, sizeof(SD_workstation_t),
98         name_compare_hosts);
99
100     for (i = 0; i < totalHosts; i++) {
101       printf("  <host id=\"%s\" power=\"%.0f\"",
102           SD_workstation_get_name(hosts[i]),
103           SD_workstation_get_power(hosts[i]));
104       props = SD_workstation_get_properties(hosts[i]);
105       if (props && !xbt_dict_is_empty(props)) {
106         printf(">\n");
107         xbt_dict_foreach(props, cursor, key, data) {
108           printf("    <prop id=\"%s\" value=\"%s\"/>\n", key, data);
109         }
110         printf("  </host>\n");
111       } else {
112         printf("/>\n");
113       }
114     }
115
116     // Routers
117     xbt_lib_foreach(as_router_lib, cursor_src, key, value1) {
118       if(((sg_routing_edge_t)xbt_lib_get_or_null(as_router_lib, key,
119           ROUTING_ASR_LEVEL))->rc_type == SURF_NETWORK_ELEMENT_ROUTER)
120       {
121         printf("  <router id=\"%s\"/>\n",key);
122       }
123     }
124
125     // Links
126     totalLinks = SD_link_get_number();
127     links = SD_link_get_list();
128
129     qsort((void *) links, totalLinks, sizeof(SD_link_t), name_compare_links);
130
131     for (i = 0; i < totalLinks; i++) {
132       printf("  <link id=\"");
133
134       printf("%s\" bandwidth=\"%.0f\" latency=\"%.9f\"",
135           SD_link_get_name(links[i]),
136           SD_link_get_current_bandwidth(links[i]),
137           SD_link_get_current_latency(links[i]));
138       if (SD_link_get_sharing_policy(links[i]) == SD_LINK_SHARED) {
139         printf("/>\n");
140       } else {
141         printf(" sharing_policy=\"FATPIPE\"/>\n");
142       }
143     }
144
145
146     xbt_lib_foreach(host_lib, cursor_src, src, value1) // Routes from host
147     {
148       value1 = xbt_lib_get_or_null(host_lib,src,ROUTING_HOST_LEVEL);
149       xbt_lib_foreach(host_lib, cursor_dst, dst, value2) //to host
150       {
151         printf("  <route src=\"%s\" dst=\"%s\">\n  "
152             ,src
153             ,dst);
154         xbt_dynar_t route=NULL;
155         value2 = xbt_lib_get_or_null(host_lib,dst,ROUTING_HOST_LEVEL);
156         routing_get_route_and_latency(value1,value2,&route,NULL);
157         for(i=0;i<xbt_dynar_length(route) ;i++)
158         {
159           void *link = xbt_dynar_get_as(route,i,void *);
160
161           char *link_name = xbt_strdup(((surf_resource_t)link)->name);
162           printf("<link_ctn id=\"%s\"/>",link_name);
163           free(link_name);
164         }
165         printf("\n  </route>\n");
166       }
167       xbt_lib_foreach(as_router_lib, cursor_dst, dst, value2) //to router
168       {
169         if(routing_get_network_element_type(dst) == SURF_NETWORK_ELEMENT_ROUTER){
170           printf("  <route src=\"%s\" dst=\"%s\">\n  "
171               ,src
172               ,dst);
173           xbt_dynar_t route=NULL;
174           value2 = xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL);
175           routing_get_route_and_latency((sg_routing_edge_t)value1,(sg_routing_edge_t)value2,&route,NULL);
176           for(i=0;i<xbt_dynar_length(route) ;i++)
177           {
178             void *link = xbt_dynar_get_as(route,i,void *);
179
180             char *link_name = xbt_strdup(((surf_resource_t)link)->name);
181             printf("<link_ctn id=\"%s\"/>",link_name);
182             free(link_name);
183           }
184           printf("\n  </route>\n");
185         }
186       }
187     }
188
189     xbt_lib_foreach(as_router_lib, cursor_src, src, value1) // Routes from router
190     {
191       value1 = xbt_lib_get_or_null(as_router_lib,src,ROUTING_ASR_LEVEL);
192       if(routing_get_network_element_type(src) == SURF_NETWORK_ELEMENT_ROUTER){
193         xbt_lib_foreach(as_router_lib, cursor_dst, dst, value2) //to router
194           {
195           if(routing_get_network_element_type(dst) == SURF_NETWORK_ELEMENT_ROUTER){
196             printf("  <route src=\"%s\" dst=\"%s\">\n  "
197                 ,src
198                 ,dst);
199             xbt_dynar_t route=NULL;
200             value2 = xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL);
201             routing_get_route_and_latency((sg_routing_edge_t)value1,(sg_routing_edge_t)value2,&route,NULL);
202             for(i=0;i<xbt_dynar_length(route) ;i++)
203             {
204               void *link = xbt_dynar_get_as(route,i,void *);
205
206               char *link_name = xbt_strdup(((surf_resource_t)link)->name);
207               printf("<link_ctn id=\"%s\"/>",link_name);
208               free(link_name);
209             }
210             printf("\n  </route>\n");
211           }
212           }
213         xbt_lib_foreach(host_lib, cursor_dst, dst, value2) //to host
214         {
215           printf("  <route src=\"%s\" dst=\"%s\">\n  "
216               ,src, dst);
217           xbt_dynar_t route=NULL;
218           value2 = xbt_lib_get_or_null(host_lib,dst,ROUTING_HOST_LEVEL);
219           routing_get_route_and_latency((sg_routing_edge_t)value1,(sg_routing_edge_t)value2,&route, NULL);
220           for(i=0;i<xbt_dynar_length(route) ;i++)
221           {
222             void *link = xbt_dynar_get_as(route,i,void *);
223
224             char *link_name = xbt_strdup(((surf_resource_t)link)->name);
225             printf("<link_ctn id=\"%s\"/>",link_name);
226             free(link_name);
227           }
228           printf("\n  </route>\n");
229         }
230       }
231     }
232
233     printf("</AS>\n");
234     printf("</platform>\n");
235   }
236   SD_exit();
237
238   return 0;
239 }