Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fc3a307a8443ffeddafd9b46151aa2125351db3a
[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 VM model used in the platform
68  *
69  *  A VM model depends on the physical CPU model to share the resources inside the VM
70  *  It will also creates the CPU model for actions running inside the VM
71  *
72  */
73 XBT_PUBLIC void surf_vm_model_init_HL13(simgrid::kernel::resource::CpuModel* cpu_pm_model);
74
75 /* --------------------
76  *  Model Descriptions
77  * -------------------- */
78
79 /** @brief The list of all available optimization modes (both for cpu and networks).
80  *  These optimization modes can be set using --cfg=cpu/optim:... and --cfg=network/optim:... */
81 XBT_PUBLIC_DATA simgrid::ModuleGroup surf_optimization_mode_description;
82
83 void simgrid_create_models();
84
85 #endif /* SURF_MODEL_H_ */