Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Do connect all log channel manually to parent using XBT_LOG_CONNECT() too, so that...
[simgrid.git] / src / simix / smx_environment.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2007 Arnaud Legrand, Bruno Donnassolo.
4    All rights reserved.                                          */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include "private.h"
10 #include "xbt/sysdep.h"
11 #include "xbt/log.h"
12 #include "xbt/xbt_os_time.h"
13
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_environment, simix,
15                                 "Logging specific to SIMIX (environment)");
16
17 /********************************* SIMIX **************************************/
18
19 /** 
20  * \brief A platform constructor.
21  *
22  * Creates a new platform, including hosts, links and the
23  * routing_table. 
24  * \param file a filename of a xml description of a platform. This file 
25  * follows this DTD :
26  *
27  *     \include surfxml.dtd
28  *
29  * Here is a small example of such a platform 
30  *
31  *     \include small_platform.xml
32  *
33  */
34 void SIMIX_create_environment(const char *file)
35 {
36   int parsed = 0;
37   xbt_dict_cursor_t cursor = NULL;
38   char *name = NULL;
39   void *workstation = NULL;
40   char *workstation_model_name;
41   int workstation_id = -1;
42   double start, end;
43
44   simix_config_init();          /* make sure that our configuration set is created */
45   surf_timer_model_init(file);
46
47   /* which model do you want today? */
48   workstation_model_name =
49       xbt_cfg_get_string(_simix_cfg_set, "workstation_model");
50
51   DEBUG1("Model : %s", workstation_model_name);
52   workstation_id =
53       find_model_description(surf_workstation_model_description,
54                                 surf_workstation_model_description_size,
55                                 workstation_model_name);
56   if (!strcmp(workstation_model_name, "compound")) {
57     xbt_ex_t e;
58     char *network_model_name = NULL;
59     char *cpu_model_name = NULL;
60     int network_id = -1;
61     int cpu_id = -1;
62
63     TRY {
64       cpu_model_name = xbt_cfg_get_string(_simix_cfg_set, "cpu_model");
65     } CATCH(e) {
66       if (e.category == bound_error) {
67         xbt_assert0(0,
68                     "Set a cpu model to use with the 'compound' workstation model");
69         xbt_ex_free(e);
70       } else {
71         RETHROW;
72       }
73     }
74
75     TRY {
76       network_model_name =
77           xbt_cfg_get_string(_simix_cfg_set, "network_model");
78     }
79     CATCH(e) {
80       if (e.category == bound_error) {
81         xbt_assert0(0,
82                     "Set a network model to use with the 'compound' workstation model");
83         xbt_ex_free(e);
84       } else {
85         RETHROW;
86       }
87     }
88
89     network_id =
90         find_model_description(surf_network_model_description,
91                                   surf_network_model_description_size,
92                                   network_model_name);
93     cpu_id =
94         find_model_description(surf_cpu_model_description,
95                                   surf_cpu_model_description_size,
96                                   cpu_model_name);
97
98     surf_cpu_model_description[cpu_id].model_init(file);
99     surf_network_model_description[network_id].model_init(file);
100
101     start = xbt_os_time();
102     parse_platform_file(file);
103     end = xbt_os_time();
104     DEBUG1("PARSE TIME: %lg", (end-start));
105     parsed = 1; 
106   }
107
108   surf_workstation_model_description[workstation_id].
109       model_init(file);
110
111   if  (!parsed)  {
112     start = xbt_os_time();
113     parse_platform_file(file);
114     if (surf_workstation_model_description[workstation_id].create_ws != NULL)
115       surf_workstation_model_description[workstation_id].create_ws();
116     end = xbt_os_time();
117     DEBUG1("PARSE TIME: %lg", (end-start));
118   }
119
120   _simix_init_status = 2;       /* inited; don't change settings now */
121
122   xbt_dict_foreach(workstation_set, cursor, name, workstation) {
123     __SIMIX_host_create(name, workstation, NULL);
124   }
125
126   return;
127 }