#include <memory>
#include <simgrid/kernel/resource/Action.hpp>
+#include <unordered_map>
namespace simgrid {
namespace kernel {
*/
class XBT_PUBLIC Model {
public:
+ /** @brief Possible model types */
+ enum class Type {
+ HOST, /**< Host models: see surf_host_model_description for more details */
+ NETWORK, /**< Network models: see surf_network_model_description for more details */
+ CPU, /**< CPU models: see surf_cpu_model_description for more details */
+ DISK, /**< Disk models: see surf_disk_model_description for more details */
+ VM /**< VM model */
+ };
+
/** @brief Possible update mechanisms */
enum class UpdateAlgo {
FULL, /**< Full update mechanism: the remaining time of every action is recomputed at each step */
* @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
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);
CpuCas01Model::CpuCas01Model(Model::UpdateAlgo algo) : CpuModel(algo)
{
all_existing_models.push_back(this);
+ models_by_type[simgrid::kernel::resource::Model::Type::CPU].push_back(this);
bool select = config::get_value<bool>("cpu/maxmin-selective-update");
CpuTiModel::CpuTiModel() : CpuModel(Model::UpdateAlgo::FULL)
{
all_existing_models.push_back(this);
+ models_by_type[simgrid::kernel::resource::Model::Type::CPU].push_back(this);
}
CpuTiModel::~CpuTiModel()
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)
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)
: 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");
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*/,
"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>();
surf_host_model = new simgrid::surf::HostL07Model();
all_existing_models.push_back(surf_host_model);
+ models_by_type[simgrid::kernel::resource::Model::Type::HOST].push_back(surf_host_model);
}
namespace simgrid {
model->update_actions_state(NOW, 0.0);
}
+static void surf_update_next_event(std::vector<simgrid::kernel::resource::Model*> const& models, double& time_delta)
+{
+ for (auto* model : models) {
+ double next_event = model->next_occurring_event(NOW);
+ if ((time_delta < 0.0 || next_event < time_delta) && next_event >= 0.0) {
+ time_delta = next_event;
+ }
+ }
+}
+
double surf_solve(double max_date)
{
double time_delta = -1.0; /* duration */
/* Physical models MUST be resolved first */
XBT_DEBUG("Looking for next event in physical models");
- double next_event_phy = surf_host_model->next_occurring_event(NOW);
- if ((time_delta < 0.0 || next_event_phy < time_delta) && next_event_phy >= 0.0) {
- time_delta = next_event_phy;
- }
- if (surf_vm_model != nullptr) {
- XBT_DEBUG("Looking for next event in virtual models");
- double next_event_virt = surf_vm_model->next_occurring_event(NOW);
- if ((time_delta < 0.0 || next_event_virt < time_delta) && next_event_virt >= 0.0)
- time_delta = next_event_virt;
- }
+ surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::HOST], 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);
- for (auto const& model : all_existing_models) {
- if (model != surf_host_model && model != surf_vm_model && model != surf_network_model && model != surf_disk_model) {
- double next_event_model = model->next_occurring_event(NOW);
- if ((time_delta < 0.0 || next_event_model < time_delta) && next_event_model >= 0.0)
- time_delta = next_event_model;
- }
- }
+ XBT_DEBUG("Looking for next event in CPU models");
+ surf_update_next_event(models_by_type[simgrid::kernel::resource::Model::Type::CPU], time_delta);
XBT_DEBUG("Min for resources (remember that NS3 don't update that value): %f", time_delta);
*********/
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;