Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0635354b61fd3f396e42253ab0843ffc7671d11e
[simgrid.git] / src / kernel / EngineImpl.cpp
1 /* Copyright (c) 2016-2021. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "src/kernel/EngineImpl.hpp"
7 #include "simgrid/Exception.hpp"
8 #include "simgrid/kernel/routing/NetPoint.hpp"
9 #include "simgrid/kernel/routing/NetZoneImpl.hpp"
10 #include "simgrid/s4u/Host.hpp"
11 #include "src/kernel/resource/DiskImpl.hpp"
12 #include "src/simix/smx_private.hpp"
13 #include "src/surf/network_interface.hpp"
14 #include "src/surf/xml/platf.hpp" // FIXME: KILLME. There must be a better way than mimicking XML here
15
16 namespace simgrid {
17 namespace kernel {
18
19 EngineImpl::~EngineImpl()
20 {
21   /* Since hosts_ is a std::map, the hosts are destroyed in the lexicographic order, which ensures that the output is
22    * reproducible.
23    */
24   while (not hosts_.empty())
25     hosts_.begin()->second->destroy();
26
27   /* Also delete the other data */
28   delete netzone_root_;
29   for (auto const& kv : netpoints_)
30     delete kv.second;
31
32   for (auto const& kv : links_)
33     if (kv.second)
34       kv.second->destroy();
35 }
36
37 void EngineImpl::load_deployment(const std::string& file) const
38 {
39   sg_platf_exit();
40   sg_platf_init();
41
42   surf_parse_open(file);
43   surf_parse();
44   surf_parse_close();
45 }
46
47 void EngineImpl::register_function(const std::string& name, const actor::ActorCodeFactory& code)
48 {
49   registered_functions[name] = code;
50 }
51 void EngineImpl::register_default(const actor::ActorCodeFactory& code)
52 {
53   default_function = code;
54 }
55
56 void EngineImpl::add_model(std::shared_ptr<resource::Model> model, const std::vector<resource::Model*>& dependencies)
57 {
58   auto model_name = model->get_name();
59   xbt_assert(models_prio_.find(model_name) == models_prio_.end(),
60              "Model %s already exists, use model.set_name() to change its name", model_name.c_str());
61
62   for (const auto dep : dependencies) {
63     xbt_assert(models_prio_.find(dep->get_name()) != models_prio_.end(),
64                "Model %s doesn't exists. Impossible to use it as dependency.", dep->get_name().c_str());
65   }
66   models_.push_back(model.get());
67   models_prio_[model_name] = std::move(model);
68 }
69
70 } // namespace kernel
71 } // namespace simgrid