Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
adding modifications for 1 pass & for adding routes only when platform end tag reached
[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
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_environment, simix,
14                                 "Logging specific to SIMIX (environment)");
15
16 /********************************* SIMIX **************************************/
17
18 /** 
19  * \brief A platform constructor.
20  *
21  * Creates a new platform, including hosts, links and the
22  * routing_table. 
23  * \param file a filename of a xml description of a platform. This file 
24  * follows this DTD :
25  *
26  *     \include surfxml.dtd
27  *
28  * Here is a small example of such a platform 
29  *
30  *     \include small_platform.xml
31  *
32  */
33 void SIMIX_create_environment(const char *file)
34 {
35   xbt_dict_cursor_t cursor = NULL;
36   char *name = NULL;
37   void *workstation = NULL;
38   char *workstation_model_name;
39   int workstation_id = -1;
40
41   simix_config_init();          /* make sure that our configuration set is created */
42   surf_timer_model_init(file);
43
44   /* which model do you want today? */
45   workstation_model_name =
46       xbt_cfg_get_string(_simix_cfg_set, "workstation_model");
47
48   DEBUG1("Model : %s", workstation_model_name);
49   workstation_id =
50       find_model_description(surf_workstation_model_description,
51                                 surf_workstation_model_description_size,
52                                 workstation_model_name);
53   if (!strcmp(workstation_model_name, "compound")) {
54     xbt_ex_t e;
55     char *network_model_name = NULL;
56     char *cpu_model_name = NULL;
57     int network_id = -1;
58     int cpu_id = -1;
59
60     TRY {
61       cpu_model_name = xbt_cfg_get_string(_simix_cfg_set, "cpu_model");
62     } CATCH(e) {
63       if (e.category == bound_error) {
64         xbt_assert0(0,
65                     "Set a cpu model to use with the 'compound' workstation model");
66         xbt_ex_free(e);
67       } else {
68         RETHROW;
69       }
70     }
71
72     TRY {
73       network_model_name =
74           xbt_cfg_get_string(_simix_cfg_set, "network_model");
75     }
76     CATCH(e) {
77       if (e.category == bound_error) {
78         xbt_assert0(0,
79                     "Set a network model to use with the 'compound' workstation model");
80         xbt_ex_free(e);
81       } else {
82         RETHROW;
83       }
84     }
85
86     network_id =
87         find_model_description(surf_network_model_description,
88                                   surf_network_model_description_size,
89                                   network_model_name);
90     cpu_id =
91         find_model_description(surf_cpu_model_description,
92                                   surf_cpu_model_description_size,
93                                   cpu_model_name);
94
95     surf_cpu_model_description[cpu_id].model_init(file);
96     surf_network_model_description[network_id].model_init(file);
97
98   }
99
100   surf_workstation_model_description[workstation_id].
101       model_init(file);
102
103   /* Parse the platform file */
104   parse_platform_file(file);
105
106   _simix_init_status = 2;       /* inited; don't change settings now */
107
108   xbt_dict_foreach(workstation_set, cursor, name, workstation) {
109     __SIMIX_host_create(name, workstation, NULL);
110   }
111
112   return;
113 }