Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / src / surf / surf_interface.hpp
1 /* Copyright (c) 2004-2023. 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 #ifndef SURF_MODEL_H_
7 #define SURF_MODEL_H_
8
9 #include "src/simgrid/module.hpp"
10 #include <xbt/asserts.h>
11 #include <xbt/function_types.h>
12
13 #include "src/internal_config.h"
14 #include "src/kernel/resource/profile/Profile.hpp"
15
16 #include <cfloat>
17 #include <cmath>
18 #include <functional>
19 #include <set>
20 #include <string>
21 #include <unordered_map>
22 #include <vector>
23
24 /*********
25  * Utils *
26  *********/
27
28 /* user-visible parameters */
29 XBT_PUBLIC_DATA double sg_maxmin_precision;
30 XBT_PUBLIC_DATA double sg_surf_precision;
31 XBT_PUBLIC_DATA int sg_concurrency_limit;
32
33 extern XBT_PRIVATE std::unordered_map<std::string, simgrid::kernel::profile::Profile*> traces_set_list;
34
35 /** set of hosts for which one want to be notified if they ever restart */
36 inline auto& watched_hosts() // avoid static initialization order fiasco
37 {
38   static std::set<std::string, std::less<>> value;
39   return value;
40 }
41
42 static inline void double_update(double* variable, double value, double precision)
43 {
44   if (false) { // debug
45     fprintf(stderr, "Updating %g -= %g +- %g\n", *variable, value, precision);
46     xbt_assert(value == 0.0 || value > precision);
47     // Check that precision is higher than the machine-dependent size of the mantissa. If not, brutal rounding  may
48     // happen, and the precision mechanism is not active...
49     xbt_assert(FLT_RADIX == 2 && *variable < precision * exp2(DBL_MANT_DIG));
50   }
51   *variable -= value;
52   if (*variable < precision)
53     *variable = 0.0;
54 }
55
56 static inline int double_positive(double value, double precision)
57 {
58   return (value > precision);
59 }
60
61 static inline int double_equals(double value1, double value2, double precision)
62 {
63   return (fabs(value1 - value2) < precision);
64 }
65
66 /** @ingroup SURF_models
67  *  @brief Initializes the CPU model with the model Cas01
68  *
69  *  By default, this model uses the lazy optimization mechanism that relies on partial invalidation in LMM and a heap
70  *  for lazy action update.
71  *  You can change this behavior by setting the cpu/optim configuration variable to a different value.
72  *
73  *  You shouldn't have to call it by yourself.
74  */
75 XBT_PUBLIC void surf_cpu_model_init_Cas01();
76
77 XBT_PUBLIC void surf_disk_model_init_S19();
78
79 /** @ingroup SURF_models
80  *  @brief Initializes the VM model used in the platform
81  *
82  *  A VM model depends on the physical CPU model to share the resources inside the VM
83  *  It will also creates the CPU model for actions running inside the VM
84  *
85  */
86 XBT_PUBLIC void surf_vm_model_init_HL13(simgrid::kernel::resource::CpuModel* cpu_pm_model);
87
88 /** @ingroup SURF_models
89  *  @brief Initializes the platform with a compound host model
90  *
91  *  This function should be called after a cpu_model and a network_model have been set up.
92  */
93 XBT_PUBLIC void surf_host_model_init_compound();
94
95 /** @ingroup SURF_models
96  *  @brief Initializes the platform with the current best network and cpu models at hand
97  *
98  *  This platform model separates the host model and the network model.
99  *  The host model will be initialized with the model compound, the network model with the model LV08 (with cross
100  *  traffic support) and the CPU model with the model Cas01.
101  *  Such model is subject to modification with warning in the ChangeLog so monitor it!
102  */
103 XBT_PUBLIC void surf_host_model_init_current_default();
104
105 /** @ingroup SURF_models
106  *  @brief Initializes the platform with the model L07
107  *
108  *  With this model, only parallel tasks can be used. Resource sharing is done by identifying bottlenecks and giving an
109  *  equal share of the model to each action.
110  */
111 XBT_PUBLIC void surf_host_model_init_ptask_L07();
112
113 /* --------------------
114  *  Model Descriptions
115  * -------------------- */
116
117 /** @brief The list of all available optimization modes (both for cpu and networks).
118  *  These optimization modes can be set using --cfg=cpu/optim:... and --cfg=network/optim:... */
119 XBT_PUBLIC_DATA simgrid::ModuleGroup surf_optimization_mode_description;
120 /** @brief The list of all cpu models (pick one with --cfg=cpu/model) */
121 XBT_PUBLIC_DATA simgrid::ModuleGroup surf_cpu_model_description;
122 /** @brief The list of all disk models (pick one with --cfg=disk/model) */
123 XBT_PUBLIC_DATA simgrid::ModuleGroup surf_disk_model_description;
124 /** @brief The list of all host models (pick one with --cfg=host/model:) */
125 XBT_PUBLIC_DATA simgrid::ModuleGroup surf_host_model_description;
126
127 void simgrid_create_models();
128
129 #endif /* SURF_MODEL_H_ */