+#define DATA_DESCR_WIDTH 39
+
+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 all_comp_iterations;
+ statistics iter_deviation;
+ 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;
+ statistics idle_duration;
+ statistics convergence;
+
+}
+
+static int simulation_main(int argc, char* argv[])
+{
+ int result;
+ process* proc;
+
+ 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());
+ all_comp_iterations.push(proc->get_all_comp_iter());
+ iter_deviation.push(proc->get_iter_deviation());
+ 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());
+ idle_duration.push(proc->get_idle_duration());
+ double c = proc->get_convergence();
+ if (c != -1.0)
+ convergence.push(c);
+
+ // 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;
+
+ 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);
+
+ double total_running = process::get_total_load_running();
+ double running_ratio = 100.0 * total_running / total_init;
+ if (running_ratio < -opt::load_ratio_threshold) {
+ XBT_ERROR("Negative running load at exit! %g (%g%%) <============",
+ total_running, running_ratio);
+ res = false;
+ } else if (running_ratio > opt::load_ratio_threshold) {
+ XBT_ERROR("Remaining running load at exit! %g (%g%%) <============",
+ total_running, running_ratio);
+ res = false;
+ } else
+ XBT_VERB("Running load at exit looks good: %g (%g%%)",
+ total_running, running_ratio);
+ return res;
+}
+
+static void check_file_access(const std::string& name)
+{
+ if (access(name.c_str(), R_OK) != 0) {
+ std::cerr << "ERROR: cannot access to file \""
+ << name << "\" for reading: " << strerror(errno) << "\n";
+ exit(EXIT_FAILURE_ARGS);
+ }
+}