1 /* Copyright (c) 2004-2023. The SimGrid Team. All rights reserved. */
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. */
9 #include "src/simgrid/module.hpp"
10 #include <xbt/asserts.h>
11 #include <xbt/function_types.h>
13 #include "src/internal_config.h"
14 #include "src/kernel/resource/profile/Profile.hpp"
21 #include <unordered_map>
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;
33 extern XBT_PRIVATE std::unordered_map<std::string, simgrid::kernel::profile::Profile*> traces_set_list;
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
38 static std::set<std::string, std::less<>> value;
42 static inline void double_update(double* variable, double value, double precision)
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));
52 if (*variable < precision)
56 static inline int double_positive(double value, double precision)
58 return (value > precision);
61 static inline int double_equals(double value1, double value2, double precision)
63 return (fabs(value1 - value2) < precision);
66 /** @ingroup SURF_models
67 * @brief Initializes the CPU model with the model Cas01
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.
73 * You shouldn't have to call it by yourself.
75 XBT_PUBLIC void surf_cpu_model_init_Cas01();
77 XBT_PUBLIC void surf_disk_model_init_S19();
79 /** @ingroup SURF_models
80 * @brief Initializes the VM model used in the platform
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
86 XBT_PUBLIC void surf_vm_model_init_HL13(simgrid::kernel::resource::CpuModel* cpu_pm_model);
88 /** @ingroup SURF_models
89 * @brief Initializes the platform with a compound host model
91 * This function should be called after a cpu_model and a network_model have been set up.
93 XBT_PUBLIC void surf_host_model_init_compound();
95 /** @ingroup SURF_models
96 * @brief Initializes the platform with the current best network and cpu models at hand
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!
103 XBT_PUBLIC void surf_host_model_init_current_default();
105 /** @ingroup SURF_models
106 * @brief Initializes the platform with the model L07
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.
111 XBT_PUBLIC void surf_host_model_init_ptask_L07();
113 /* --------------------
115 * -------------------- */
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;
127 void simgrid_create_models();
129 #endif /* SURF_MODEL_H_ */