+#define DATA_DESCR_WIDTH 37
+
+namespace {
+ // Failure exit status
+ enum {
+ EXIT_NO_FAILURE = 0x00, // no error
+ EXIT_FAILURE_ARGS = 0x01, // bad arguments
+ EXIT_FAILURE_INIT = 0x02, // failed to initialize simulator
+ EXIT_FAILURE_SIMU = 0x04, // simulation failed
+ EXIT_FAILURE_CLEAN = 0x08, // error at cleanup
+ EXIT_FAILURE_INTR = 0x10, // interrupted by user
+ EXIT_FAILURE_LOAD = 0x20, // lost load on exit
+ EXIT_FAILURE_OTHER = 0x40, // other error
+ };
+
+ // Cannot be globally initialized...
+ mutex_t* proc_mutex;
+ condition_t* proc_cond;
+ unsigned proc_counter = 0;
+
+ statistics loads;
+ statistics comps;
+ statistics comp_iterations;
+ statistics data_send_amount;
+ statistics data_recv_amount;
+ statistics data_send_count;
+ statistics data_recv_count;
+ statistics ctrl_send_amount;
+ statistics ctrl_recv_amount;
+ statistics ctrl_send_count;
+ statistics ctrl_recv_count;
+
+}
+
+static int simulation_main(int argc, char* argv[])
+{
+ int result;
+ process* proc;
+ try {
+ proc = opt::loba_algorithms.new_instance(opt::loba_algo, argc, argv);
+
+ proc_mutex->acquire();
+ ++proc_counter;
+ proc_mutex->release();
+
+ result = proc->run();
+
+ proc_mutex->acquire();
+ loads.push(proc->get_real_load());
+ comps.push(proc->get_comp_amount());
+ comp_iterations.push(proc->get_comp_iter());
+ data_send_amount.push(proc->get_data_send_amount());
+ data_recv_amount.push(proc->get_data_recv_amount());
+ data_send_count.push(proc->get_data_send_count());
+ data_recv_count.push(proc->get_data_recv_count());
+ ctrl_send_amount.push(proc->get_ctrl_send_amount());
+ ctrl_recv_amount.push(proc->get_ctrl_recv_amount());
+ ctrl_send_count.push(proc->get_ctrl_send_count());
+ ctrl_recv_count.push(proc->get_ctrl_recv_count());
+
+ // Synchronization barrier...
+ // The goal is to circumvent a limitation in SimGrid (at least
+ // in version 3.5): a process must be alive when another one
+ // destroys a communication they had together.
+
+ --proc_counter;
+ proc_cond->broadcast();
+ while (proc_counter > 0)
+ proc_cond->wait(*proc_mutex);
+ proc_mutex->release();
+
+ delete proc;
+ }
+ catch (const std::invalid_argument& e) {
+ THROWF(arg_error, 0, "%s", e.what());
+ }
+ catch (const std::exception& e) {
+ THROWF(0, 0, "%s", e.what());
+ }
+ return result;
+}
+
+static bool check_for_lost_load()
+{
+ bool res = true;
+ double total_init = process::get_total_load_init();
+ double total_exit = process::get_total_load_exit();
+ double lost = total_init - total_exit;
+ double lost_ratio = 100.0 * lost / total_init;
+ if (lost_ratio < -opt::load_ratio_threshold) {
+ XBT_ERROR("Gained load at exit! %g (%g%%) <============",
+ -lost, -lost_ratio);
+ res = false;
+ } else if (lost_ratio > opt::load_ratio_threshold) {
+ XBT_ERROR("Lost load at exit! %g (%g%%) <============",
+ lost, lost_ratio);
+ res = false;
+ } else
+ XBT_VERB("Total load at exit looks good: %g (%g%%)", lost, lost_ratio);