12 // Creates log categories
13 XBT_LOG_NEW_CATEGORY(simu, "Simulation messages");
14 XBT_LOG_NEW_SUBCATEGORY(main, simu, "Messages from global infrastructure");
15 XBT_LOG_NEW_SUBCATEGORY(comm, simu, "Messages from asynchronous pipes");
16 XBT_LOG_NEW_SUBCATEGORY(proc, simu, "Messages from base process class");
17 XBT_LOG_NEW_SUBCATEGORY(loba, simu, "Messages from load-balancer");
19 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(main);
21 // Failure exit status
23 EXIT_NO_FAILURE = 0x00, // no error
24 EXIT_FAILURE_ARGS = 0x01, // bad arguments
25 EXIT_FAILURE_INIT = 0x02, // failed to initialize simulator
26 EXIT_FAILURE_SIMU = 0x04, // simulation failed
27 EXIT_FAILURE_CLEAN = 0x08, // error at cleanup
30 #include "loba_least_loaded.h"
31 int simulation_main(int argc, char* argv[])
34 process* proc = new loba_least_loaded(argc, argv);
40 int main(int argc, char* argv[])
42 // Note: variables used after THROW must be declared as volatile.
43 volatile int exit_status = 0; // global exit status
44 volatile double simulated_time = -1.0;
45 timestamp simulation_time;
49 simulation_time.start();
51 // Set default logging parameters
52 // xbt_log_control_set("simu.thres:verbose");
53 xbt_log_control_set("simu.fmt:'[%h %r] [%c/%p] %m%n'");
55 // Initialize some MSG internal data.
56 // Note: MSG_global_init() may throw an exception, but it seems
57 // impossible to catch it correctly :-(
58 MSG_global_init(&argc, argv);
60 // Parse global parameters
61 int parse_res = opt::parse_args(&argc, argv);
63 || opt::version_requested || opt::help_requested) {
64 if (opt::version_requested)
65 std::clog << version::name << " version " << version::num << "\n"
66 << version::copyright << "\n"
67 "Compiled on " << version::date << "\n\n";
68 if (!parse_res || opt::help_requested)
71 exit(parse_res ? EXIT_NO_FAILURE : EXIT_FAILURE_ARGS);
76 exit_status = EXIT_FAILURE_INIT; // =====
78 // Register the main function of an agent in a global table.
79 MSG_function_register("simulation_main", simulation_main);
80 // Preserve some compatibility with old code...
81 MSG_function_register("Calculs", simulation_main);
83 // Create the platform and the application.
84 MSG_create_environment(opt::platform_file);
86 MSG_launch_application(opt::application_file);
88 exit_status = EXIT_FAILURE_SIMU; // =====
90 // Launch the MSG simulation.
91 INFO0("Starting simulation...");
93 INFO0("Simulation ended.");
94 simulated_time = MSG_get_clock();
96 THROW1(0, 0, "MSG_main() failed with status %#x", res);
98 exit_status = EXIT_NO_FAILURE; // =====
101 int len = strlen(ex.msg);
102 if (len > 0 && ex.msg[len - 1] == '\n')
103 ex.msg[len - 1] = '\0'; // strip the ending '\n'
104 ERROR1("%s", ex.msg);
105 DEBUG3("Error from %s() in %s:%d", ex.func, ex.file, ex.line);
109 // Clean the MSG simulation.
113 ERROR1("MSG_clean() failed with status %#x", res);
114 exit_status |= EXIT_FAILURE_CLEAN;
117 // Report final simulation status.
118 if (simulated_time >= 0.0) {
119 simulation_time.stop();
120 INFO0(",----[ Results ]");
121 INFO1("| Total simulated time...: %g", simulated_time);
122 INFO1("| Total simulation time..: %g", simulation_time.duration());
126 ERROR1("Simulation failed (%#x).", exit_status);
128 INFO0("Simulation succeeded.");