Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Oups : the visual project of the msg_prop example
[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   int parsed = 0;
36   xbt_dict_cursor_t cursor = NULL;
37   char *name = NULL;
38   void *workstation = NULL;
39   char *workstation_model_name;
40   int workstation_id = -1;
41
42   simix_config_init();          /* make sure that our configuration set is created */
43   surf_timer_model_init(file);
44
45   /* which model do you want today? */
46   workstation_model_name =
47       xbt_cfg_get_string(_simix_cfg_set, "workstation_model");
48
49   DEBUG1("Model : %s", workstation_model_name);
50   workstation_id =
51       find_model_description(surf_workstation_model_description,
52                                 surf_workstation_model_description_size,
53                                 workstation_model_name);
54   if (!strcmp(workstation_model_name, "compound")) {
55     xbt_ex_t e;
56     char *network_model_name = NULL;
57     char *cpu_model_name = NULL;
58     int network_id = -1;
59     int cpu_id = -1;
60
61     TRY {
62       cpu_model_name = xbt_cfg_get_string(_simix_cfg_set, "cpu_model");
63     } CATCH(e) {
64       if (e.category == bound_error) {
65         xbt_assert0(0,
66                     "Set a cpu model to use with the 'compound' workstation model");
67         xbt_ex_free(e);
68       } else {
69         RETHROW;
70       }
71     }
72
73     TRY {
74       network_model_name =
75           xbt_cfg_get_string(_simix_cfg_set, "network_model");
76     }
77     CATCH(e) {
78       if (e.category == bound_error) {
79         xbt_assert0(0,
80                     "Set a network model to use with the 'compound' workstation model");
81         xbt_ex_free(e);
82       } else {
83         RETHROW;
84       }
85     }
86
87     network_id =
88         find_model_description(surf_network_model_description,
89                                   surf_network_model_description_size,
90                                   network_model_name);
91     cpu_id =
92         find_model_description(surf_cpu_model_description,
93                                   surf_cpu_model_description_size,
94                                   cpu_model_name);
95
96     surf_cpu_model_description[cpu_id].model_init(file);
97     surf_network_model_description[network_id].model_init(file);
98
99     parse_platform_file(file);
100     parsed = 1; 
101   }
102
103   
104
105   surf_workstation_model_description[workstation_id].
106       model_init(file);
107
108   if  (!parsed) parse_platform_file(file);
109
110   _simix_init_status = 2;       /* inited; don't change settings now */
111
112   xbt_dict_foreach(workstation_set, cursor, name, workstation) {
113     __SIMIX_host_create(name, workstation, NULL);
114   }
115
116   return;
117 }