6 #include "deployment.h"
14 // Creates log categories
15 XBT_LOG_NEW_CATEGORY(simu, "Simulation messages");
16 XBT_LOG_NEW_SUBCATEGORY(main, simu, "Messages from global infrastructure");
17 XBT_LOG_NEW_SUBCATEGORY(comm, simu, "Messages from asynchronous pipes");
18 XBT_LOG_NEW_SUBCATEGORY(proc, simu, "Messages from base process class");
19 XBT_LOG_NEW_SUBCATEGORY(loba, simu, "Messages from load-balancer");
21 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main);
23 // Failure exit status
25 EXIT_NO_FAILURE = 0x00, // no error
26 EXIT_FAILURE_ARGS = 0x01, // bad arguments
27 EXIT_FAILURE_INIT = 0x02, // failed to initialize simulator
28 EXIT_FAILURE_SIMU = 0x04, // simulation failed
29 EXIT_FAILURE_CLEAN = 0x08, // error at cleanup
32 #include "loba_simple.h"
33 int simulation_main(int argc, char* argv[])
38 proc = opt::loba_algorithms.new_instance(opt::loba_algo, argc, argv);
42 catch (std::invalid_argument& e) {
43 THROW1(arg_error, 0, "%s", e.what());
48 int main(int argc, char* argv[])
50 // Note: variables used after THROW must be declared as volatile.
51 volatile int exit_status = 0; // global exit status
52 volatile double simulated_time = -1.0;
53 timestamp simulation_time;
57 simulation_time.start();
59 // Set default logging parameters
60 // xbt_log_control_set("simu.thres:verbose");
61 xbt_log_control_set("simu.fmt:'[%h %r] [%c/%p] %m%n'");
63 // Initialize some MSG internal data.
64 // Note: MSG_global_init() may throw an exception, but it seems
65 // impossible to catch it correctly :-(
66 MSG_global_init(&argc, argv);
68 // Parse global parameters
69 int parse_res = opt::parse_args(&argc, argv);
71 || opt::version_requested || opt::help_requested) {
72 if (opt::version_requested)
73 std::clog << version::name << " (" << opt::program_name << ")"
74 << " version " << version::num << "\n"
75 << version::copyright << "\n"
76 "Compiled on " << version::date << "\n\n";
77 if (!parse_res || opt::help_requested)
80 exit(parse_res ? EXIT_NO_FAILURE : EXIT_FAILURE_ARGS);
85 exit_status = EXIT_FAILURE_INIT; // =====
87 // Register the default function of an agent
88 // MSG_function_register("simulation_main", simulation_main);
89 MSG_function_register_default(simulation_main);
91 // Create the platform and the application.
92 MSG_create_environment(opt::platform_file.c_str());
94 if (opt::auto_depl::enabled) {
95 if (!opt::auto_depl::nhosts)
96 opt::auto_depl::nhosts = hostdata::size();
97 if (!opt::auto_depl::load)
98 opt::auto_depl::load = hostdata::size();
99 MY_launch_application(); // it is already opt::* aware...
101 MSG_launch_application(opt::deployment_file.c_str());
104 exit_status = EXIT_FAILURE_SIMU; // =====
106 // Launch the MSG simulation.
107 INFO0("Starting simulation...");
109 INFO0("Simulation ended.");
110 simulated_time = MSG_get_clock();
112 THROW1(0, 0, "MSG_main() failed with status %#x", res);
114 exit_status = EXIT_NO_FAILURE; // =====
117 int len = strlen(ex.msg);
118 if (len > 0 && ex.msg[len - 1] == '\n')
119 ex.msg[len - 1] = '\0'; // strip the ending '\n'
120 ERROR1("%s", ex.msg);
121 DEBUG3("Error from %s() in %s:%d", ex.func, ex.file, ex.line);
125 // Clean the MSG simulation.
129 ERROR1("MSG_clean() failed with status %#x", res);
130 exit_status |= EXIT_FAILURE_CLEAN;
133 // Report final simulation status.
134 if (simulated_time >= 0.0) {
135 simulation_time.stop();
136 INFO0(",----[ Results ]");
137 INFO1("| Total simulated time...: %g", simulated_time);
138 INFO1("| Total simulation time..: %g", simulation_time.duration());
142 ERROR1("Simulation failed (%#x).", exit_status);
144 INFO0("Simulation succeeded.");