Logo AND Algorithmique Numérique Distribuée

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