-void model_help(const char *category, s_surf_model_description_t * table)
-{
- printf("Long description of the %s models accepted by this simulator:\n", category);
- for (int i = 0; table[i].name; i++)
- printf(" %s: %s\n", table[i].name, table[i].description);
-}
-
-int find_model_description(s_surf_model_description_t* table, std::string name)
-{
- for (int i = 0; table[i].name; i++)
- if (name == table[i].name)
- return i;
-
- if (not table[0].name)
- xbt_die("No model is valid! This is a bug.");
-
- std::string name_list = std::string(table[0].name);
- for (int i = 1; table[i].name; i++)
- name_list = name_list + ", " + table[i].name;
-
- xbt_die("Model '%s' is invalid! Valid models are: %s.", name.c_str(), name_list.c_str());
- return -1;
-}
-
-void sg_version_check(int lib_version_major, int lib_version_minor, int lib_version_patch)
-{
- if ((lib_version_major != SIMGRID_VERSION_MAJOR) || (lib_version_minor != SIMGRID_VERSION_MINOR)) {
- fprintf(stderr, "FATAL ERROR: Your program was compiled with SimGrid version %d.%d.%d, "
- "and then linked against SimGrid %d.%d.%d. Please fix this.\n",
- lib_version_major, lib_version_minor, lib_version_patch, SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR,
- SIMGRID_VERSION_PATCH);
- abort();
- }
- if (lib_version_patch != SIMGRID_VERSION_PATCH) {
- if (SIMGRID_VERSION_PATCH >= 90 || lib_version_patch >= 90) {
- fprintf(
- stderr,
- "FATAL ERROR: Your program was compiled with SimGrid version %d.%d.%d, "
- "and then linked against SimGrid %d.%d.%d. \n"
- "One of them is a development version, and should not be mixed with the stable release. Please fix this.\n",
- lib_version_major, lib_version_minor, lib_version_patch, SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR,
- SIMGRID_VERSION_PATCH);
- abort();
- }
- fprintf(stderr, "Warning: Your program was compiled with SimGrid version %d.%d.%d, "
- "and then linked against SimGrid %d.%d.%d. Proceeding anyway.\n",
- lib_version_major, lib_version_minor, lib_version_patch, SIMGRID_VERSION_MAJOR, SIMGRID_VERSION_MINOR,
- SIMGRID_VERSION_PATCH);
- }
-}
-
-void sg_version_get(int* ver_major, int* ver_minor, int* ver_patch)
-{
- *ver_major = SIMGRID_VERSION_MAJOR;
- *ver_minor = SIMGRID_VERSION_MINOR;
- *ver_patch = SIMGRID_VERSION_PATCH;
-}
-
-void sg_version()
-{
- std::printf("This program was linked against %s (git: %s), found in %s.\n",
- SIMGRID_VERSION_STRING, SIMGRID_GIT_VERSION, SIMGRID_INSTALL_PREFIX);
-
-#if SIMGRID_HAVE_MC
- std::printf(" Model-checking support compiled in.\n");
-#else
- std::printf(" Model-checking support disabled at compilation.\n");
-#endif
-
-#if SIMGRID_HAVE_NS3
- std::printf(" NS3 support compiled in.\n");
-#else
- std::printf(" NS3 support disabled at compilation.\n");
-#endif
-
-#if SIMGRID_HAVE_JEDULE
- std::printf(" Jedule support compiled in.\n");
-#else
- std::printf(" Jedule support disabled at compilation.\n");
-#endif
-
-#if SIMGRID_HAVE_LUA
- std::printf(" Lua support compiled in.\n");
-#else
- std::printf(" Lua support disabled at compilation.\n");
-#endif
-
-#if SIMGRID_HAVE_MALLOCATOR
- std::printf(" Mallocator support compiled in.\n");
-#else
- std::printf(" Mallocator support disabled at compilation.\n");
-#endif
-
- std::printf("\nTo cite SimGrid in a publication, please use:\n"
- " Henri Casanova, Arnaud Giersch, Arnaud Legrand, Martin Quinson, Frédéric Suter. \n"
- " Versatile, Scalable, and Accurate Simulation of Distributed Applications and Platforms. \n"
- " Journal of Parallel and Distributed Computing, Elsevier, 2014, 74 (10), pp.2899-2917.\n");
- std::printf("The pdf file and a BibTeX entry for LaTeX users can be found at http://hal.inria.fr/hal-01017319\n");
-}
-
-void surf_init(int *argc, char **argv)
-{
- if (USER_HOST_LEVEL != -1) // Already initialized
- return;
-
- XBT_DEBUG("Create all Libs");
- USER_HOST_LEVEL = simgrid::s4u::Host::extension_create(nullptr);
-
- xbt_init(argc, argv);
- if (not all_existing_models)
- all_existing_models = new std::vector<simgrid::surf::Model*>();
- if (not future_evt_set)
- future_evt_set = new simgrid::trace_mgr::future_evt_set();
-
- sg_config_init(argc, argv);
-
- if (MC_is_active())
- MC_memory_init();
-}
-
-void surf_exit()
-{
- TRACE_end(); /* Just in case it was not called by the upper layer (or there is no upper layer) */
-
- sg_host_exit();
- sg_link_exit();
- for (auto const& e : storage_types) {
- simgrid::surf::StorageType* stype = e.second;
- delete stype->properties;
- delete stype->model_properties;
- delete stype;
- }
- for (auto const& s : *simgrid::surf::StorageImpl::storagesMap())
- delete s.second;
- delete simgrid::surf::StorageImpl::storagesMap();
-
- for (auto const& model : *all_existing_models)
- delete model;
- delete all_existing_models;
-
- simgrid::surf::surfExitCallbacks();
-
- if (future_evt_set) {
- delete future_evt_set;
- future_evt_set = nullptr;
- }
-
- tmgr_finalize();
- sg_platf_exit();
- simgrid::s4u::Engine::shutdown();
-
- NOW = 0; /* Just in case the user plans to restart the simulation afterward */
-}
-
-/*********
- * Model *
- *********/
-
-namespace simgrid {
-namespace surf {
-
-Model::Model()
- : maxminSystem_(nullptr)
-{
- readyActionSet_ = new ActionList();
- runningActionSet_ = new ActionList();
- failedActionSet_ = new ActionList();
- doneActionSet_ = new ActionList();
-
- modifiedSet_ = nullptr;
- actionHeap_ = nullptr;
- updateMechanism_ = UM_UNDEFINED;
- selectiveUpdate_ = 0;
-}
-
-Model::~Model(){
- delete readyActionSet_;
- delete runningActionSet_;
- delete failedActionSet_;
- delete doneActionSet_;
-}
-
-double Model::nextOccuringEvent(double now)
-{
- //FIXME: set the good function once and for all
- if (updateMechanism_ == UM_LAZY)
- return nextOccuringEventLazy(now);
- else if (updateMechanism_ == UM_FULL)
- return nextOccuringEventFull(now);
- else
- xbt_die("Invalid cpu update mechanism!");
-}
-
-double Model::nextOccuringEventLazy(double now)
-{
- XBT_DEBUG("Before share resources, the size of modified actions set is %zu", modifiedSet_->size());
- lmm_solve(maxminSystem_);
- XBT_DEBUG("After share resources, The size of modified actions set is %zu", modifiedSet_->size());
-
- while (not modifiedSet_->empty()) {
- Action *action = &(modifiedSet_->front());
- modifiedSet_->pop_front();
- bool max_dur_flag = false;
-
- if (action->getStateSet() != runningActionSet_)
- continue;
-
- /* bogus priority, skip it */
- if (action->getPriority() <= 0 || action->getHat()==LATENCY)
- continue;
-
- action->updateRemainingLazy(now);
-
- double min = -1;
- double share = lmm_variable_getvalue(action->getVariable());
-
- if (share > 0) {
- double time_to_completion;
- if (action->getRemains() > 0) {
- time_to_completion = action->getRemainsNoUpdate() / share;
- } else {
- time_to_completion = 0.0;
- }
- min = now + time_to_completion; // when the task will complete if nothing changes
- }
-
- if ((action->getMaxDuration() > NO_MAX_DURATION) &&
- (min <= -1 || action->getStartTime() + action->getMaxDuration() < min)) {
- // when the task will complete anyway because of the deadline if any
- min = action->getStartTime() + action->getMaxDuration();
- max_dur_flag = true;
- }
-
- XBT_DEBUG("Action(%p) corresponds to variable %d", action, action->getVariable()->id_int);
-
- XBT_DEBUG("Action(%p) Start %f. May finish at %f (got a share of %f). Max_duration %f", action,
- action->getStartTime(), min, share,
- action->getMaxDuration());
-
- if (min > -1) {
- action->heapUpdate(actionHeap_, min, max_dur_flag ? MAX_DURATION : NORMAL);
- XBT_DEBUG("Insert at heap action(%p) min %f now %f", action, min, now);
- } else
- DIE_IMPOSSIBLE;
- }
-
- //hereafter must have already the min value for this resource model
- if (xbt_heap_size(actionHeap_) > 0) {
- double min = xbt_heap_maxkey(actionHeap_) - now;
- XBT_DEBUG("minimum with the HEAP %f", min);
- return min;
- } else {
- XBT_DEBUG("The HEAP is empty, thus returning -1");
- return -1;
- }
-}
-
-double Model::nextOccuringEventFull(double /*now*/) {
- maxminSystem_->solve_fun(maxminSystem_);
-
- double min = -1;
- for (auto it(getRunningActionSet()->begin()), itend(getRunningActionSet()->end()); it != itend ; ++it) {
- Action *action = &*it;
- double value = lmm_variable_getvalue(action->getVariable());
- if (value > 0) {
- if (action->getRemains() > 0)
- value = action->getRemainsNoUpdate() / value;
- else
- value = 0.0;
- if (min < 0 || value < min) {
- min = value;
- XBT_DEBUG("Updating min (value) with %p: %f", action, min);
- }
- }
- if ((action->getMaxDuration() >= 0) && (min<0 || action->getMaxDuration() < min)) {
- min = action->getMaxDuration();
- XBT_DEBUG("Updating min (duration) with %p: %f", action, min);
- }
- }
- XBT_DEBUG("min value : %f", min);
-
- return min;
-}
-
-void Model::updateActionsState(double now, double delta)
-{
- if (updateMechanism_ == UM_FULL)
- updateActionsStateFull(now, delta);
- else if (updateMechanism_ == UM_LAZY)
- updateActionsStateLazy(now, delta);
- else
- xbt_die("Invalid cpu update mechanism!");
-}
-
-void Model::updateActionsStateLazy(double /*now*/, double /*delta*/)
-{
- THROW_UNIMPLEMENTED;
-}
-
-void Model::updateActionsStateFull(double /*now*/, double /*delta*/)
-{
- THROW_UNIMPLEMENTED;
-}
-
-}
-}
-
-/************
- * Resource *
- ************/
-
-namespace simgrid {
-namespace surf {
-
-Resource::Resource(Model* model, const std::string& name, lmm_constraint_t constraint)
- : name_(name), model_(model), constraint_(constraint)
-{}
-
-Resource::~Resource() = default;
-
-bool Resource::isOn() const {
- return isOn_;
-}
-bool Resource::isOff() const {
- return not isOn_;
-}
-
-void Resource::turnOn()