A step forwards encapsulation.
Still not good for ptask model and its particularities.
cpu_plop.hpp and cpu_plop_cpp which contains classes CpuPlopModel, CpuPlop and
CpuPlopAction implementing respectively the interfaces CpuModel, Cpu and
CpuAction. You also need to define an initializing function like this:
-FIXME[donassolo]: update doc
~~~~
void surf_cpu_model_init_plop()
- the CPU resource,
- the timer resource.
- FIXME[donassolo]: fix doc
The implementation of these resources depends on the platform
models you choose. You can select your model by calling
#surf_host_model_init_current_default() (which will give you a
} // namespace kernel
} // namespace simgrid
-/** @ingroup SURF_models
- * @brief List of initialized models
- */
-XBT_PUBLIC_DATA std::vector<simgrid::kernel::resource::Model*> all_existing_models;
-/** @ingroup SURF_models
- * @brief Map of initialized models by category
- */
-XBT_PUBLIC_DATA
-std::unordered_map<simgrid::kernel::resource::Model::Type, std::vector<simgrid::kernel::resource::Model*>>
- models_by_type;
-
#endif
/** @brief Retrieves the disk model associated to this NetZone */
resource::DiskModel* get_disk_model() const { return disk_model_; }
/** @brief Retrieves the host model associated to this NetZone */
- // FIXME[donassolo]: why HostModel isn't in resource namespace?
simgrid::surf::HostModel* get_host_model() const { return host_model_; }
const s4u::NetZone* get_iface() const { return &piface_; }
default_function = code;
}
+void EngineImpl::add_model_ptask(simgrid::kernel::resource::Model::Type type, simgrid::kernel::resource::Model* model,
+ bool is_default)
+{
+ if (is_default)
+ models_by_type_[type].insert(models_by_type_[type].begin(), model);
+ else
+ models_by_type_[type].push_back(model);
+}
+
+void EngineImpl::add_model(simgrid::kernel::resource::Model::Type type,
+ std::unique_ptr<simgrid::kernel::resource::Model> model, bool is_default)
+{
+ add_model_ptask(type, model.get(), is_default);
+ models_.push_back(std::move(model));
+}
+
+simgrid::kernel::resource::Model* EngineImpl::get_default_model(simgrid::kernel::resource::Model::Type type)
+{
+ if (models_by_type_[type].size() > 0)
+ return models_by_type_[type][0];
+ else
+ return nullptr;
+}
+
} // namespace kernel
} // namespace simgrid
#ifndef SIMGRID_KERNEL_ENGINEIMPL_HPP
#define SIMGRID_KERNEL_ENGINEIMPL_HPP
+#include <simgrid/kernel/resource/Model.hpp>
#include <simgrid/s4u/Engine.hpp>
#include <simgrid/s4u/NetZone.hpp>
#include <simgrid/simix.hpp>
std::unordered_map<std::string, routing::NetPoint*> netpoints_;
std::unordered_map<std::string, actor::ActorCodeFactory> registered_functions; // Maps function names to actor code
actor::ActorCodeFactory default_function; // Function to use as a fallback when the provided name matches nothing
+ std::vector<std::unique_ptr<simgrid::kernel::resource::Model>> models_;
+ std::unordered_map<simgrid::kernel::resource::Model::Type, std::vector<simgrid::kernel::resource::Model*>>
+ models_by_type_;
friend s4u::Engine;
void register_function(const std::string& name, const actor::ActorCodeFactory& code);
void register_default(const actor::ActorCodeFactory& code);
+ /**
+ * @brief Add a model to engine list
+ *
+ * @param type Model type (network, disk, etc)
+ * @param model Pointer to model
+ * @param is_default Is this the default model for this type of resource in this exp
+ */
+ void add_model(simgrid::kernel::resource::Model::Type type, std::unique_ptr<simgrid::kernel::resource::Model> model,
+ bool is_default = false);
+ /**
+ * @brief Add a model (specific for ptask)
+ *
+ * Ptask is special. The CPU and NETWORK models need to be in the managed
+ * resources by surf_solve (model_by_type) but cannot be in the list of
+ * all models (old all_existing_models global variable)
+ *
+ * This methods does this job while we cannot handle ptask as the remaining models
+ */
+ void add_model_ptask(simgrid::kernel::resource::Model::Type type, simgrid::kernel::resource::Model* model,
+ bool is_default);
+ /** @brief Get current default model for a resource type */
+ simgrid::kernel::resource::Model* get_default_model(simgrid::kernel::resource::Model::Type type);
+
+ /** @brief Get list of models created for a resource type */
+ const std::vector<simgrid::kernel::resource::Model*>& get_model_list(simgrid::kernel::resource::Model::Type type)
+ {
+ return models_by_type_[type];
+ }
+ /** @brief Get list of all models managed by this engine */
+ const std::vector<std::unique_ptr<simgrid::kernel::resource::Model>>& get_all_models() { return models_; }
+
routing::NetZoneImpl* netzone_root_ = nullptr;
static EngineImpl* get_instance() { return simgrid::s4u::Engine::get_instance()->pimpl; }
actor::ActorCodeFactory get_function(const std::string& name)
#include "simgrid/kernel/routing/NetPoint.hpp"
#include "simgrid/s4u/Engine.hpp"
#include "simgrid/s4u/Host.hpp"
+#include "src/kernel/EngineImpl.hpp"
#include "src/kernel/resource/DiskImpl.hpp"
#include "src/surf/HostImpl.hpp"
#include "src/surf/cpu_interface.hpp"
xbt_assert(nullptr == s4u::Engine::get_instance()->netpoint_by_name_or_null(get_name()),
"Refusing to create a second NetZone called '%s'.", get_cname());
- netpoint_ = new NetPoint(name_, NetPoint::Type::NetZone, father_);
- if (models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM].size() > 0) {
- cpu_model_vm_ = static_cast<simgrid::kernel::resource::CpuModel*>(
- models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM][0]);
- }
+ netpoint_ = new NetPoint(name_, NetPoint::Type::NetZone, father_);
+ cpu_model_vm_ = static_cast<simgrid::kernel::resource::CpuModel*>(
+ simgrid::kernel::EngineImpl::get_instance()->get_default_model(simgrid::kernel::resource::Model::Type::CPU_VM));
cpu_model_pm_ = static_cast<simgrid::kernel::resource::CpuModel*>(
- models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM][0]);
+ simgrid::kernel::EngineImpl::get_instance()->get_default_model(simgrid::kernel::resource::Model::Type::CPU_PM));
disk_model_ = static_cast<simgrid::kernel::resource::DiskModel*>(
- models_by_type[simgrid::kernel::resource::Model::Type::DISK][0]);
- // FIXME[donassolo]: we probably need some validation of the coherence among
- // the different models in each netZone
- host_model_ = static_cast<simgrid::surf::HostModel*>(models_by_type[simgrid::kernel::resource::Model::Type::HOST][0]);
+ simgrid::kernel::EngineImpl::get_instance()->get_default_model(simgrid::kernel::resource::Model::Type::DISK));
+ host_model_ = static_cast<simgrid::surf::HostModel*>(
+ simgrid::kernel::EngineImpl::get_instance()->get_default_model(simgrid::kernel::resource::Model::Type::HOST));
XBT_DEBUG("NetZone '%s' created with the id '%u'", get_cname(), netpoint_->id());
}
#include "simgrid/Exception.hpp"
#include "simgrid/s4u/Exec.hpp"
#include "src/include/surf/surf.hpp"
+#include "src/kernel/EngineImpl.hpp"
#include "src/kernel/activity/ExecImpl.hpp"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(res_vm, ker_resource, "Virtual Machines, containing actors and mobile accross hosts");
void surf_vm_model_init_HL13()
{
- /* FIXME[donassolo]: this smells bad, but works
- * (the constructor saves its pointer in all_existing_models and models_by_type :O).
- * We need a manager for these models */
- new simgrid::vm::VMModel();
+ auto vm_model = std::make_unique<simgrid::vm::VMModel>();
+ simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::VM,
+ std::move(vm_model), true);
}
namespace simgrid {
VMModel::VMModel()
{
- all_existing_models.push_back(this);
- models_by_type[simgrid::kernel::resource::Model::Type::VM].push_back(this);
s4u::Host::on_state_change.connect(host_state_change);
s4u::Exec::on_start.connect(add_active_exec);
s4u::Exec::on_completion.connect(remove_active_exec);
for (int i = 0; i < physical_host->get_pstate_count(); i++)
speeds.push_back(physical_host->get_pstate_speed(i));
- // FIXME[donassolo]: shoud this be done at the Impl class???
physical_host->get_netpoint()->get_englobing_zone()->get_cpu_vm_model()->create_cpu(this, speeds)->set_core_count(core_amount)->seal();
if (physical_host->get_pstate() != 0)
set_pstate(physical_host->get_pstate());
#include "simgrid/kernel/resource/Model.hpp"
#include "simgrid/s4u/Engine.hpp"
#include "simgrid/sg_config.hpp"
+#include "src/kernel/EngineImpl.hpp"
#include "src/surf/surf_interface.hpp"
#include <array>
XBT_LOG_NEW_CATEGORY(sd, "Logging specific to SimDag");
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_kernel, sd, "Logging specific to SimDag (kernel)");
-simgrid::sd::Global *sd_global = nullptr;
+simgrid::sd::Global* sd_global = nullptr;
-namespace simgrid{
-namespace sd{
+namespace simgrid {
+namespace sd {
-std::set<SD_task_t>* simulate(double how_long){
+std::set<SD_task_t>* simulate(double how_long)
+{
XBT_VERB("Run simulation for %f seconds", how_long);
sd_global->watch_point_reached = false;
SD_task_run(*(sd_global->runnable_tasks.begin()));
double elapsed_time = 0.0;
- double total_time = 0.0;
+ double total_time = 0.0;
/* main loop */
while (elapsed_time >= 0 && (how_long < 0 || 0.00001 < (how_long - total_time)) &&
not sd_global->watch_point_reached) {
XBT_DEBUG("Total time: %f", total_time);
- elapsed_time = surf_solve(how_long > 0 ? surf_get_clock() + how_long - total_time: -1.0);
+ elapsed_time = surf_solve(how_long > 0 ? surf_get_clock() + how_long - total_time : -1.0);
XBT_DEBUG("surf_solve() returns %f", elapsed_time);
if (elapsed_time > 0.0)
total_time += elapsed_time;
/* let's see which tasks are done */
- for (auto const& model : all_existing_models) {
+ for (auto const& model : simgrid::kernel::EngineImpl::get_instance()->get_all_models()) {
const simgrid::kernel::resource::Action* action = model->extract_done_action();
while (action != nullptr && action->get_data() != nullptr) {
auto* task = static_cast<SD_task_t>(action->get_data());
succ->predecessors->erase(task);
succ->inputs->erase(task);
XBT_DEBUG("Release dependency on %s: %zu remain(s). Becomes schedulable if %zu=0", SD_task_get_name(succ),
- succ->predecessors->size()+succ->inputs->size(), succ->predecessors->size());
+ succ->predecessors->size() + succ->inputs->size(), succ->predecessors->size());
if (SD_task_get_state(succ) == SD_NOT_SCHEDULED && succ->predecessors->empty())
SD_task_set_state(succ, SD_SCHEDULABLE);
output->start_time = task->finish_time;
output->predecessors->erase(task);
if (SD_task_get_state(output) == SD_SCHEDULED)
- SD_task_set_state(output, SD_RUNNABLE);
+ SD_task_set_state(output, SD_RUNNABLE);
else
- SD_task_set_state(output, SD_SCHEDULABLE);
+ SD_task_set_state(output, SD_SCHEDULABLE);
SD_task_t comm_dst = *(output->successors->begin());
- if (SD_task_get_state(comm_dst) == SD_NOT_SCHEDULED && comm_dst->predecessors->empty()){
- XBT_DEBUG("%s is a transfer, %s may be ready now if %zu=0",
- SD_task_get_name(output), SD_task_get_name(comm_dst), comm_dst->predecessors->size());
+ if (SD_task_get_state(comm_dst) == SD_NOT_SCHEDULED && comm_dst->predecessors->empty()) {
+ XBT_DEBUG("%s is a transfer, %s may be ready now if %zu=0", SD_task_get_name(output),
+ SD_task_get_name(comm_dst), comm_dst->predecessors->size());
SD_task_set_state(comm_dst, SD_SCHEDULABLE);
}
if (SD_task_get_state(output) == SD_RUNNABLE && not sd_global->watch_point_reached)
XBT_WARN("%s is in %s state", SD_task_get_name(t), __get_state_name(SD_task_get_state(t)));
}
- XBT_DEBUG("elapsed_time = %f, total_time = %f, watch_point_reached = %d",
- elapsed_time, total_time, sd_global->watch_point_reached);
+ XBT_DEBUG("elapsed_time = %f, total_time = %f, watch_point_reached = %d", elapsed_time, total_time,
+ sd_global->watch_point_reached);
XBT_DEBUG("current time = %f", surf_get_clock());
return &sd_global->return_set;
}
-}
-}
+} // namespace sd
+} // namespace simgrid
/**
* @brief helper for pretty printing of task state
* @param state the state of a task
* @return the equivalent as a readable string
*/
-const char *__get_state_name(e_SD_task_state_t state){
+const char* __get_state_name(e_SD_task_state_t state)
+{
static constexpr std::array<const char*, 7> state_names{
{"not scheduled", "schedulable", "scheduled", "runnable", "running", "done", "failed"}};
return state_names.at(static_cast<int>(log2(static_cast<double>(state))));
* @param argv argument list
* @see SD_create_environment(), SD_exit()
*/
-void SD_init_nocheck(int *argc, char **argv)
+void SD_init_nocheck(int* argc, char** argv)
{
xbt_assert(sd_global == nullptr, "SD_init() already called");
*
* Example: SD_config("host/model","default")
*/
-void SD_config(const char *key, const char *value){
- xbt_assert(sd_global,"ERROR: Please call SD_init() before using SD_config()");
+void SD_config(const char* key, const char* value)
+{
+ xbt_assert(sd_global, "ERROR: Please call SD_init() before using SD_config()");
simgrid::config::set_as_string(key, value);
}
*
* @include small_platform.xml
*/
-void SD_create_environment(const char *platform_file)
+void SD_create_environment(const char* platform_file)
{
simgrid::s4u::Engine::get_instance()->load_platform(platform_file);
jedule_sd_init();
#endif
XBT_VERB("Starting simulation...");
- surf_presolve(); /* Takes traces into account */
+ surf_presolve(); /* Takes traces into account */
}
/**
}
/** @brief Returns the current clock, in seconds */
-double SD_get_clock() {
+double SD_get_clock()
+{
return surf_get_clock();
}
#include "src/smpi/include/smpi_actor.hpp"
#include "simgrid/sg_config.hpp"
+#include "src/kernel/EngineImpl.hpp"
#include "src/kernel/activity/ExecImpl.hpp"
#include "src/kernel/activity/IoImpl.hpp"
#include "src/kernel/activity/MailboxImpl.hpp"
namespace simgrid {
namespace simix {
-config::Flag<bool> cfg_verbose_exit{"debug/verbose-exit",
- "Display the actor status at exit",
- true};
+config::Flag<bool> cfg_verbose_exit{"debug/verbose-exit", "Display the actor status at exit", true};
} // namespace simix
} // namespace simgrid
XBT_INFO("CTRL-C pressed. The current status will be displayed before exit (disable that behavior with option "
"'debug/verbose-exit').");
simix_global->display_all_actor_status();
- }
- else {
+ } else {
XBT_INFO("CTRL-C pressed, exiting. Hiding the current process status since 'debug/verbose-exit' is set to false.");
}
exit(1);
"Minimal Working Example (MWE) reproducing your problem and a full backtrace\n"
"of the fault captured with gdb or valgrind.\n",
smx_context_stack_size / 1024);
- } else if (siginfo->si_signo == SIGSEGV) {
+ } else if (siginfo->si_signo == SIGSEGV) {
fprintf(stderr, "Segmentation fault.\n");
#if HAVE_SMPI
if (smpi_enabled() && smpi_cfg_privatization() == SmpiPrivStrategies::NONE) {
struct sigaction action;
struct sigaction old_action;
action.sa_sigaction = &segvhandler;
- action.sa_flags = SA_ONSTACK | SA_RESETHAND | SA_SIGINFO;
+ action.sa_flags = SA_ONSTACK | SA_RESETHAND | SA_SIGINFO;
sigemptyset(&action.sa_mask);
/* Linux tend to raise only SIGSEGV where other systems also raise SIGBUS on severe error */
/** Wake up all actors waiting for a Surf action to finish */
void Global::wake_all_waiting_actors() const
{
- for (auto const& model : all_existing_models) {
+ for (auto const& model : simgrid::kernel::EngineImpl::get_instance()->get_all_models()) {
kernel::resource::Action* action;
XBT_DEBUG("Handling the failed actions (if any)");
}
config::Flag<double> cfg_breakpoint{"debug/breakpoint",
- "When non-negative, raise a SIGTRAP after given (simulated) time",
- -1.0};
+ "When non-negative, raise a SIGTRAP after given (simulated) time", -1.0};
} // namespace simix
} // namespace simgrid
void SIMIX_set_maestro(void (*code)(void*), void* data)
{
#ifdef _WIN32
- XBT_INFO("WARNING, SIMIX_set_maestro is believed to not work on windows. Please help us investigating this issue if you need that feature");
+ XBT_INFO("WARNING, SIMIX_set_maestro is believed to not work on windows. Please help us investigating this issue if "
+ "you need that feature");
#endif
maestro_code = std::bind(code, data);
}
* @ingroup SIMIX_API
* @brief Initialize SIMIX internal data.
*/
-void SIMIX_global_init(int *argc, char **argv)
+void SIMIX_global_init(int* argc, char** argv)
{
#if SIMGRID_HAVE_MC
// The communication initialization is done ASAP.
#if HAVE_SMPI
if (not simix_global->process_list.empty()) {
- if(smpi_process()->initialized()){
+ if (smpi_process()->initialized()) {
xbt_die("Process exited without calling MPI_Finalize - Killing simulation");
- }else{
+ } else {
XBT_WARN("Process called exit when leaving - Skipping cleanups");
return;
}
*/
double SIMIX_get_clock()
{
- if(MC_is_active() || MC_record_replay_is_active()){
+ if (MC_is_active() || MC_record_replay_is_active()) {
return MC_process_clock_get(SIMIX_process_self());
- }else{
+ } else {
return surf_get_clock();
}
}
#include "cpu_cas01.hpp"
#include "simgrid/sg_config.hpp"
+#include "src/kernel/EngineImpl.hpp"
#include "src/kernel/resource/profile/Event.hpp"
#include "src/surf/cpu_ti.hpp"
#include "src/surf/surf_interface.hpp"
else
algo = simgrid::kernel::resource::Model::UpdateAlgo::FULL;
- auto cpu_model_pm = new simgrid::kernel::resource::CpuCas01Model(algo);
- models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM].push_back(cpu_model_pm);
- auto cpu_model_vm = new simgrid::kernel::resource::CpuCas01Model(algo);
- models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM].push_back(cpu_model_vm);
+ auto cpu_model_pm = std::make_unique<simgrid::kernel::resource::CpuCas01Model>(algo);
+ simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_PM,
+ std::move(cpu_model_pm), true);
+ auto cpu_model_vm = std::make_unique<simgrid::kernel::resource::CpuCas01Model>(algo);
+ simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_VM,
+ std::move(cpu_model_vm), true);
}
namespace simgrid {
CpuCas01Model::CpuCas01Model(Model::UpdateAlgo algo) : CpuModel(algo)
{
- all_existing_models.push_back(this);
-
bool select = config::get_value<bool>("cpu/maxmin-selective-update");
if (is_update_lazy()) {
set_maxmin_system(new lmm::System(select));
}
-CpuCas01Model::~CpuCas01Model()
-{
-}
+CpuCas01Model::~CpuCas01Model() {}
Cpu* CpuCas01Model::create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate)
{
{
speed_.scale = 1;
speed_.peak = speed_per_pstate_.front();
- // FIXME[donassolo]: don't set here.. everytime I take half an hour to discover where it comes
host->pimpl_cpu = this;
}
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "cpu_ti.hpp"
+#include "src/kernel/EngineImpl.hpp"
#include "src/kernel/resource/profile/Event.hpp"
#include "src/kernel/resource/profile/Profile.hpp"
#include "src/surf/surf_interface.hpp"
void CpuTiModel::create_pm_vm_models()
{
- auto cpu_model_pm = new CpuTiModel();
- models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM].push_back(cpu_model_pm);
- auto cpu_model_vm = new CpuTiModel();
- models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM].push_back(cpu_model_vm);
+ auto cpu_model_pm = std::make_unique<CpuTiModel>();
+ simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_PM,
+ std::move(cpu_model_pm), true);
+ auto cpu_model_vm = std::make_unique<CpuTiModel>();
+ simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::CPU_VM,
+ std::move(cpu_model_vm), true);
}
CpuTiModel::CpuTiModel() : CpuModel(Model::UpdateAlgo::FULL)
{
- all_existing_models.push_back(this);
}
-CpuTiModel::~CpuTiModel()
-{
-}
+CpuTiModel::~CpuTiModel() {}
Cpu* CpuTiModel::create_cpu(s4u::Host* host, const std::vector<double>& speed_per_pstate)
{
#include "simgrid/kernel/routing/NetPoint.hpp"
#include "simgrid/s4u/Engine.hpp"
#include "simgrid/s4u/Host.hpp"
+#include "src/kernel/EngineImpl.hpp"
#include "src/kernel/lmm/maxmin.hpp"
#include "src/surf/xml/platf.hpp"
#include "surf/surf.hpp"
void surf_disk_model_init_default()
{
- /* FIXME[donassolo]: this smells bad, but works
- * (the constructor saves its pointer in all_existing_models and models_by_type :O).
- * We need a manager for these models */
- new simgrid::kernel::resource::DiskS19Model();
+ auto disk_model = std::make_unique<simgrid::kernel::resource::DiskS19Model>();
+ simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::DISK,
+ std::move(disk_model), true);
}
namespace simgrid {
DiskS19Model::DiskS19Model()
{
- all_existing_models.push_back(this);
- models_by_type[simgrid::kernel::resource::Model::Type::DISK].push_back(this);
}
DiskImpl* DiskS19Model::create_disk(const std::string& name, double read_bandwidth, double write_bandwidth)
#include "src/surf/host_clm03.hpp"
#include "simgrid/kernel/routing/NetPoint.hpp"
#include "simgrid/sg_config.hpp"
+#include "src/kernel/EngineImpl.hpp"
#include "surf/surf.hpp"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(res_host);
void surf_host_model_init_current_default()
{
- /* FIXME[donassolo]: this smells bad, but works
- * (the constructor saves its pointer in all_existing_models and models_by_type :O).
- * We need a manager for these models */
- new simgrid::surf::HostCLM03Model();
+ auto host_model = std::make_unique<simgrid::surf::HostCLM03Model>();
simgrid::config::set_default<bool>("network/crosstraffic", true);
+ simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST,
+ std::move(host_model), true);
surf_cpu_model_init_Cas01();
surf_network_model_init_LegrandVelho();
}
void surf_host_model_init_compound()
{
- /* FIXME[donassolo]: this smells bad, but works
- * (the constructor saves its pointer in all_existing_models and models_by_type :O).
- * We need a manager for these models */
- new simgrid::surf::HostCLM03Model();
+ auto host_model = std::make_unique<simgrid::surf::HostCLM03Model>();
+ simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST,
+ std::move(host_model), true);
}
namespace simgrid {
namespace surf {
HostCLM03Model::HostCLM03Model()
{
- all_existing_models.push_back(this);
- models_by_type[simgrid::kernel::resource::Model::Type::HOST].push_back(this);
}
double HostCLM03Model::next_occurring_event(double now)
#include "src/surf/network_cm02.hpp"
#include "simgrid/s4u/Host.hpp"
#include "simgrid/sg_config.hpp"
+#include "src/kernel/EngineImpl.hpp"
#include "src/kernel/resource/profile/Event.hpp"
#include "src/surf/network_wifi.hpp"
#include "src/surf/surf_interface.hpp"
/* } */
void surf_network_model_init_LegrandVelho()
{
- /* FIXME[donassolo]: this smells bad, but works
- * (the constructor saves its pointer in all_existing_models and models_by_type :O).
- * We need a manager for these models */
- new simgrid::kernel::resource::NetworkCm02Model();
+ auto net_model = std::make_unique<simgrid::kernel::resource::NetworkCm02Model>();
+ simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
+ std::move(net_model), true);
simgrid::config::set_default<double>("network/latency-factor", 13.01);
simgrid::config::set_default<double>("network/bandwidth-factor", 0.97);
simgrid::config::set_default<double>("network/bandwidth-factor", 1.0);
simgrid::config::set_default<double>("network/weight-S", 0.0);
- /* FIXME[donassolo]: this smells bad, but works
- * (the constructor saves its pointer in all_existing_models and models_by_type :O).
- * We need a manager for these models */
- new simgrid::kernel::resource::NetworkCm02Model();
+ auto net_model = std::make_unique<simgrid::kernel::resource::NetworkCm02Model>();
+ simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
+ std::move(net_model), true);
}
namespace simgrid {
: NetworkModel(config::get_value<std::string>("network/optim") == "Full" ? Model::UpdateAlgo::FULL
: Model::UpdateAlgo::LAZY)
{
- all_existing_models.push_back(this);
- models_by_type[simgrid::kernel::resource::Model::Type::NETWORK].push_back(this);
-
std::string optim = config::get_value<std::string>("network/optim");
bool select = config::get_value<bool>("network/maxmin-selective-update");
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "network_constant.hpp"
+#include "src/kernel/EngineImpl.hpp"
#include "src/surf/surf_interface.hpp"
#include "surf/surf.hpp"
*********/
void surf_network_model_init_Constant()
{
- /* FIXME[donassolo]: this smells bad, but works
- * (the constructor saves its pointer in all_existing_models and models_by_type :O).
- * We need a manager for these models */
- new simgrid::kernel::resource::NetworkConstantModel();
+ auto net_model = std::make_unique<simgrid::kernel::resource::NetworkConstantModel>();
+ simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
+ std::move(net_model), true);
}
namespace simgrid {
NetworkConstantModel::NetworkConstantModel() : NetworkModel(Model::UpdateAlgo::FULL)
{
- all_existing_models.push_back(this);
- models_by_type[simgrid::kernel::resource::Model::Type::NETWORK].push_back(this);
}
LinkImpl* NetworkConstantModel::create_link(const std::string& name, const std::vector<double>& /*bandwidth*/,
#include "src/surf/network_ib.hpp"
#include "simgrid/kernel/routing/NetPoint.hpp"
#include "simgrid/sg_config.hpp"
+#include "src/kernel/EngineImpl.hpp"
#include "src/surf/HostImpl.hpp"
#include "src/surf/xml/platf.hpp"
#include "surf/surf.hpp"
/* } */
void surf_network_model_init_IB()
{
- /* FIXME[donassolo]: this smells bad, but works
- * (the constructor saves its pointer in all_existing_models and models_by_type :O).
- * We need a manager for these models */
- new simgrid::kernel::resource::NetworkIBModel();
+ auto net_model = std::make_unique<simgrid::kernel::resource::NetworkIBModel>();
+ simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
+ std::move(net_model), true);
+
simgrid::s4u::Link::on_communication_state_change.connect(IB_action_state_changed_callback);
simgrid::s4u::Link::on_communicate.connect(IB_action_init_callback);
simgrid::s4u::Host::on_creation.connect(IB_create_host_callback);
NetworkIBModel::NetworkIBModel() : NetworkSmpiModel()
{
- /* Do not add this into all_existing_models: our ancestor already does so */
-
std::string IB_factors_string = config::get_value<std::string>("smpi/IB-penalty-factors");
std::vector<std::string> radical_elements;
boost::split(radical_elements, IB_factors_string, boost::is_any_of(";"));
#include "simgrid/s4u/Engine.hpp"
#include "simgrid/s4u/NetZone.hpp"
#include "src/instr/instr_private.hpp" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals
+#include "src/kernel/EngineImpl.hpp"
#include "src/surf/surf_interface.hpp"
#include "src/surf/xml/platf_private.hpp"
#include "surf/surf.hpp"
*********/
void surf_network_model_init_NS3()
{
- /* FIXME[donassolo]: this smells bad, but works
- * (the constructor saves its pointer in all_existing_models and models_by_type :O).
- * We need a manager for these models */
- new simgrid::kernel::resource::NetworkNS3Model();
+ auto net_model = std::make_unique<simgrid::kernel::resource::NetworkNS3Model>();
+ simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
+ std::move(net_model), true);
}
static simgrid::config::Flag<std::string>
xbt_assert(not sg_link_energy_is_inited(),
"LinkEnergy plugin and ns-3 network models are not compatible. Are you looking for Ecofen, maybe?");
- all_existing_models.push_back(this);
- models_by_type[simgrid::kernel::resource::Model::Type::NETWORK].push_back(this);
-
NetPointNs3::EXTENSION_ID = routing::NetPoint::extension_create<NetPointNs3>();
ns3::Config::SetDefault("ns3::TcpSocket::SegmentSize", ns3::UintegerValue(1000));
#include "network_smpi.hpp"
#include "simgrid/sg_config.hpp"
#include "smpi_utils.hpp"
+#include "src/kernel/EngineImpl.hpp"
#include "src/surf/surf_interface.hpp"
#include "surf/surf.hpp"
/* New model based on LV08 and experimental results of MPI ping-pongs */
/************************************************************************/
/* @Inproceedings{smpi_ipdps, */
-/* author={Pierre-Nicolas Clauss and Mark Stillwell and Stéphane Genaud and Frédéric Suter and Henri Casanova and Martin Quinson}, */
+/* author={Pierre-Nicolas Clauss and Mark Stillwell and Stéphane Genaud and Frédéric Suter and Henri Casanova and
+ * Martin Quinson}, */
/* title={Single Node On-Line Simulation of {MPI} Applications with SMPI}, */
/* booktitle={25th IEEE International Parallel and Distributed Processing Symposium (IPDPS'11)}, */
/* address={Anchorage (Alaska) USA}, */
/* } */
void surf_network_model_init_SMPI()
{
- /* FIXME[donassolo]: this smells bad, but works
- * (the constructor saves its pointer in all_existing_models and models_by_type :O).
- * We need a manager for these models */
- new simgrid::kernel::resource::NetworkSmpiModel();
+ auto net_model = std::make_unique<simgrid::kernel::resource::NetworkSmpiModel>();
+ simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::NETWORK,
+ std::move(net_model), true);
simgrid::config::set_default<double>("network/weight-S", 8775);
}
NetworkSmpiModel::NetworkSmpiModel() : NetworkCm02Model()
{
- /* Do not add this into all_existing_models: our ancestor already does so */
}
double NetworkSmpiModel::get_bandwidth_factor(double size)
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "ptask_L07.hpp"
+#include "src/kernel/EngineImpl.hpp"
#include "src/kernel/resource/profile/Event.hpp"
#include "surf/surf.hpp"
#include "xbt/config.hpp"
{
XBT_CINFO(xbt_cfg, "Switching to the L07 model to handle parallel tasks.");
- auto host_model = new simgrid::surf::HostL07Model();
- all_existing_models.push_back(host_model);
- models_by_type[simgrid::kernel::resource::Model::Type::HOST].push_back(host_model);
+ auto host_model = std::make_unique<simgrid::surf::HostL07Model>();
+ simgrid::kernel::EngineImpl::get_instance()->add_model(simgrid::kernel::resource::Model::Type::HOST,
+ std::move(host_model), true);
}
namespace simgrid {
{
auto* maxmin_system = new simgrid::kernel::lmm::FairBottleneck(true /* selective update */);
set_maxmin_system(maxmin_system);
- network_model_ = std::make_unique<NetworkL07Model>(this, maxmin_system);
- models_by_type[simgrid::kernel::resource::Model::Type::NETWORK].push_back(network_model_.get());
- cpu_model_pm_ = std::make_unique<CpuL07Model>(this, maxmin_system);
- models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM].push_back(cpu_model_pm_.get());
+
+ net_model_ = std::make_unique<NetworkL07Model>(this, maxmin_system);
+ auto engine = simgrid::kernel::EngineImpl::get_instance();
+ engine->add_model_ptask(simgrid::kernel::resource::Model::Type::NETWORK, net_model_.get(), true);
+
+ cpu_model_ = std::make_unique<CpuL07Model>(this, maxmin_system);
+ engine->add_model_ptask(simgrid::kernel::resource::Model::Type::CPU_PM, cpu_model_.get(), true);
}
HostL07Model::~HostL07Model() {}
const double* bytes_amount, double rate) override;
private:
- std::unique_ptr<NetworkL07Model> network_model_;
- std::unique_ptr<CpuL07Model> cpu_model_pm_;
+ std::unique_ptr<NetworkL07Model> net_model_;
+ std::unique_ptr<CpuL07Model> cpu_model_;
};
class CpuL07Model : public kernel::resource::CpuModel {
surf_host_model_description[host_id].model_init_preparse();
XBT_DEBUG("Call vm_model_init");
- // FIXME[donassolo]: maybe remove it, find a way to create the object and leave the
- // dependency with surf_cpu_model_vm explicity
surf_vm_model_init_HL13();
XBT_DEBUG("Call disk_model_init");
simgrid::kernel::routing::NetZoneImpl* new_zone = nullptr;
simgrid::kernel::resource::NetworkModel* netmodel =
current_routing == nullptr ? static_cast<simgrid::kernel::resource::NetworkModel*>(
- models_by_type[simgrid::kernel::resource::Model::Type::NETWORK][0])
+ simgrid::kernel::EngineImpl::get_instance()->get_default_model(
+ simgrid::kernel::resource::Model::Type::NETWORK))
: current_routing->get_network_model();
if (strcasecmp(zone->routing.c_str(), "Cluster") == 0) {
#include "simgrid/s4u/Engine.hpp"
#include "src/include/surf/surf.hpp"
#include "src/instr/instr_private.hpp"
+#include "src/kernel/EngineImpl.hpp"
#include "src/kernel/resource/DiskImpl.hpp"
#include "src/kernel/resource/profile/FutureEvtSet.hpp"
#include "src/plugins/vm/VirtualMachineImpl.hpp"
}
XBT_DEBUG("Set every models in the right state by updating them to 0.");
- for (auto const& model : all_existing_models)
+ for (auto const& model : simgrid::kernel::EngineImpl::get_instance()->get_all_models())
model->update_actions_state(NOW, 0.0);
}
/* Physical models MUST be resolved first */
XBT_DEBUG("Looking for next event in physical models");
- surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::HOST], time_delta);
+ auto engine = simgrid::kernel::EngineImpl::get_instance();
+ surf_update_next_event(engine->get_model_list(simgrid::kernel::resource::Model::Type::HOST), time_delta);
// following the order it was done in HostCLM03Model->next_occurring_event
XBT_DEBUG("Looking for next event in CPU models");
- surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::CPU_PM], time_delta);
+ surf_update_next_event(engine->get_model_list(simgrid::kernel::resource::Model::Type::CPU_PM), time_delta);
+
XBT_DEBUG("Looking for next event in network models");
- surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::NETWORK], time_delta);
+ surf_update_next_event(engine->get_model_list(simgrid::kernel::resource::Model::Type::NETWORK), time_delta);
XBT_DEBUG("Looking for next event in disk models");
- surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::DISK], time_delta);
+ surf_update_next_event(engine->get_model_list(simgrid::kernel::resource::Model::Type::DISK), time_delta);
XBT_DEBUG("Looking for next event in virtual models");
- surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::VM], time_delta);
- surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::CPU_VM], time_delta);
+ surf_update_next_event(engine->get_model_list(simgrid::kernel::resource::Model::Type::VM), time_delta);
+ surf_update_next_event(engine->get_model_list(simgrid::kernel::resource::Model::Type::CPU_VM), time_delta);
XBT_DEBUG("Min for resources (remember that NS3 don't update that value): %f", time_delta);
double next_event_date = simgrid::kernel::profile::future_evt_set.next_date();
XBT_DEBUG("Next TRACE event: %f", next_event_date);
- for (auto* model : models_by_type[simgrid::kernel::resource::Model::Type::NETWORK]) {
+ for (auto* model : engine->get_model_list(simgrid::kernel::resource::Model::Type::NETWORK)) {
if (model->next_occurring_event_is_idempotent())
continue;
NOW = NOW + time_delta;
// Inform the models of the date change
- for (auto const& model : all_existing_models)
+ for (auto const& model : simgrid::kernel::EngineImpl::get_instance()->get_all_models())
model->update_actions_state(NOW, time_delta);
simgrid::s4u::Engine::on_time_advance(time_delta);
* Utils *
*********/
-std::vector<simgrid::kernel::resource::Model*> all_existing_models; /* to destroy models correctly */
-std::unordered_map<simgrid::kernel::resource::Model::Type, std::vector<simgrid::kernel::resource::Model*>>
- models_by_type;
-
simgrid::kernel::profile::FutureEvtSet future_evt_set;
std::vector<std::string> surf_path;
{
simgrid::s4u::Engine::shutdown();
- for (auto const& model : all_existing_models)
- delete model;
-
tmgr_finalize();
sg_platf_exit();
#include "simgrid/host.h"
#include "simgrid/kernel/routing/NetZoneImpl.hpp" // full type for NetZoneImpl object
#include "simgrid/zone.h"
+#include "src/kernel/EngineImpl.hpp"
#include "src/surf/cpu_interface.hpp"
#include "src/surf/network_interface.hpp"
#include "src/surf/surf_interface.hpp"
double now = surf_get_clock();
XBT_INFO("Next Event : %g", now);
- for (auto const& model : all_existing_models) {
+ for (auto const& model : simgrid::kernel::EngineImpl::get_instance()->get_all_models()) {
if (model->get_started_action_set()->size() != 0) {
XBT_DEBUG("\t Running that model");
running = 1;