Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'unify_models' into 'master'
[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(resource::Model::Type type, std::shared_ptr<resource::Model> model, bool is_default)
57 {
58   if (is_default)
59     models_by_type_[type].insert(models_by_type_[type].begin(), model.get());
60   else
61     models_by_type_[type].push_back(model.get());
62
63   models_.push_back(std::move(model));
64 }
65
66 resource::Model* EngineImpl::get_default_model(resource::Model::Type type) const
67 {
68   resource::Model* model = nullptr;
69   if (models_by_type_.find(type) != models_by_type_.end() and models_by_type_.at(type).size() > 0)
70     return models_by_type_.at(type)[0];
71   return model;
72 }
73
74 const std::vector<resource::Model*>& EngineImpl::get_model_list(resource::Model::Type type)
75 {
76   return models_by_type_[type];
77 }
78
79 } // namespace kernel
80 } // namespace simgrid