Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / src / kernel / resource / FactorSet.hpp
1 /* Copyright (c) 2016-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 RESOURCE_FACTORSET_HPP
7 #define RESOURCE_FACTORSET_HPP
8 #include <xbt/base.h>
9
10 #include <cstddef>
11 #include <functional>
12 #include <string>
13 #include <string_view>
14 #include <vector>
15
16 // Methods used to parse and store the values for timing injections in smpi
17 struct s_smpi_factor_t {
18   size_t factor = 0;
19   std::vector<double> values;
20 };
21
22 namespace simgrid::kernel::resource {
23
24 class FactorSet {
25   const std::string name_;
26   std::vector<s_smpi_factor_t> factors_;
27   double default_value_;
28   const std::function<double(std::vector<double> const&, double)> lambda_;
29   bool initialized_ = false;
30
31 public:
32   // Parse the factor from a string
33   FactorSet(
34       const std::string& name, double default_value = 1,
35       std::function<double(std::vector<double> const&, double)> const& lambda = [](std::vector<double> const& values,
36                                                                                    double) { return values.front(); });
37   void parse(const std::string& string_values);
38   bool is_initialized() const { return initialized_; }
39   // Get the default value
40   double operator()() const;
41   // Get the factor to use for the provided size
42   double operator()(double size) const;
43 };
44
45 } // namespace simgrid::kernel::resource
46 #endif