- Disk: examples/cpp/io-degradation
- Link: examples/cpp/network-nonlinear
- CPU: examples/cpp/exec-cpu-nonlinear
+ - Dynamic factors for CPU and disk: similarly to dynamic network factors,
+ allows the user to set a callback which can affect the progress of activities
+ (multiplicative factor applied when updating the amount of work remaining).
+ - Example: examples/cpp/exec-cpu-factors
S4U:
- New: s4u::Disk::set_sharing_policy() and s4u::Host::set_sharing_policy().
Documentation:
* New section "Release Notes" documenting recent and current developments.
+ * New section "Modeling I/O: the realistic way" presenting how to properly
+ model disks in SimGrid.
----------------------------------------------------------------------------
include examples/cpp/exec-async/s4u-exec-async.tesh
include examples/cpp/exec-basic/s4u-exec-basic.cpp
include examples/cpp/exec-basic/s4u-exec-basic.tesh
+include examples/cpp/exec-cpu-factors/s4u-exec-cpu-factors.cpp
+include examples/cpp/exec-cpu-factors/s4u-exec-cpu-factors.tesh
include examples/cpp/exec-cpu-nonlinear/s4u-exec-cpu-nonlinear.cpp
include examples/cpp/exec-cpu-nonlinear/s4u-exec-cpu-nonlinear.tesh
include examples/cpp/exec-dependent/s4u-exec-dependent.cpp
include teshsuite/smpi/pt2pt-pingpong/broken_hostfiles.tesh
include teshsuite/smpi/pt2pt-pingpong/pt2pt-pingpong.c
include teshsuite/smpi/pt2pt-pingpong/pt2pt-pingpong.tesh
+include teshsuite/smpi/replay-ti-colls/replay-ti-colls.c
+include teshsuite/smpi/replay-ti-colls/replay-ti-colls.tesh
include teshsuite/smpi/timers/timers.c
include teshsuite/smpi/timers/timers.tesh
include teshsuite/smpi/topo-cart-sub/topo-cart-sub.c
energy-exec energy-boot energy-link energy-vm energy-exec-ptask energy-wifi
engine-filtering
exec-async exec-basic exec-dvfs exec-remote exec-waitany exec-waitfor exec-dependent exec-unassigned
- exec-ptask-multicore exec-cpu-nonlinear
+ exec-ptask-multicore exec-cpu-nonlinear exec-cpu-factors
maestro-set
mc-bugged1 mc-bugged2 mc-electric-fence mc-failing-assert
network-wifi
--- /dev/null
+/* Copyright (c) 2010-2021. The SimGrid Team. All rights reserved. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+/* This example shows how to simulate variability for CPUs, using multiplicative factors
+ */
+
+#include <simgrid/s4u.hpp>
+
+namespace sg4 = simgrid::s4u;
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+
+/*************************************************************************************************/
+static void runner()
+{
+ double computation_amount = sg4::this_actor::get_host()->get_speed();
+
+ XBT_INFO("Executing 1 tasks of %g flops, should take 1 second.", computation_amount);
+ sg4::this_actor::execute(computation_amount);
+ XBT_INFO("Executing 1 tasks of %g flops, it would take .001s without factor. It'll take .002s",
+ computation_amount / 10);
+ sg4::this_actor::execute(computation_amount / 1000);
+
+ XBT_INFO("Finished executing. Goodbye now!");
+}
+/*************************************************************************************************/
+/** @brief Variability for CPU */
+static double cpu_variability(const sg4::Host* host, double flops)
+{
+ /* creates variability for tasks smaller than 1% of CPU power.
+ * unrealistic, for learning purposes */
+ double factor = 1.0;
+ double speed = host->get_speed();
+ if (flops < speed / 100) {
+ factor = 0.5;
+ }
+ XBT_INFO("Host %s, task with %lf flops, new factor %lf", host->get_cname(), flops, factor);
+ return factor;
+}
+
+/** @brief Create a simple 1-host platform */
+static void load_platform()
+{
+ auto* zone = sg4::create_empty_zone("Zone1");
+ auto* runner_host = zone->create_host("runner", 1e6);
+ runner_host->set_factor_cb(std::bind(&cpu_variability, runner_host, std::placeholders::_1))->seal();
+ zone->seal();
+
+ /* create actor runner */
+ sg4::Actor::create("runner", runner_host, runner);
+}
+
+/*************************************************************************************************/
+int main(int argc, char* argv[])
+{
+ sg4::Engine e(&argc, argv);
+
+ /* create platform */
+ load_platform();
+
+ /* runs the simulation */
+ e.run();
+
+ return 0;
+}
--- /dev/null
+$ ${bindir:=.}/s4u-exec-cpu-factors "--log=root.fmt:[%10.6r]%e(%i:%a@%h)%e%m%n"
+> [ 0.000000] (1:runner@runner) Executing 1 tasks of 1e+06 flops, should take 1 second.
+> [ 0.000000] (0:maestro@) Host runner, task with 1000000.000000 flops, new factor 1.000000
+> [ 1.000000] (1:runner@runner) Executing 1 tasks of 100000 flops, it would take .001s without factor. It'll take .002s
+> [ 1.000000] (0:maestro@) Host runner, task with 1000.000000 flops, new factor 0.500000
+> [ 1.002000] (1:runner@runner) Finished executing. Goodbye now!
namespace sg4 = simgrid::s4u;
-XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_network_nonlinear, "Messages specific for this s4u example");
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
/*************************************************************************************************/
static void runner()
/** @brief Non-linear resource sharing for CPU */
static double cpu_nonlinear(const sg4::Host* host, double capacity, int n)
{
- /* emulates a degradation in link according to the number of flows
+ /* emulates a degradation in CPU according to the number of tasks
* totally unrealistic but for learning purposes */
capacity = n > 1 ? capacity / 2 : capacity;
XBT_INFO("Host %s, %d concurrent tasks, new capacity %lf", host->get_cname(), n, capacity);
Host* set_cpu(kernel::resource::CpuImpl* cpu);
kernel::resource::CpuImpl* get_cpu() const { return pimpl_cpu_; }
kernel::routing::NetPoint* get_netpoint() const { return pimpl_netpoint_; }
+ /**
+ * @brief Callback to set CPU factor
+ *
+ * This callback offers a flexible way to create variability in CPU executions
+ *
+ * @param flops Execution size in flops
+ * @return Multiply factor
+ */
+ using CpuFactorCb = double(sg_size_t flops);
+ /**
+ * @brief Configure the factor callback to the CPU associated to this host
+ */
+ Host* set_factor_cb(const std::function<CpuFactorCb>& cb);
size_t get_actor_count() const;
std::vector<ActorPtr> get_all_actors() const;
surf_action_ =
disk_->get_host()->get_netpoint()->get_englobing_zone()->get_disk_model()->io_start(disk_, size_, type_);
surf_action_->set_activity(this);
- const auto& factor_cb = disk_->get_factor_cb();
- if (factor_cb) { // handling disk variability
- surf_action_->set_rate_factor(factor_cb(size_, type_));
- }
XBT_DEBUG("Create IO synchro %p %s", this, get_cname());
return this->pimpl_cpu_->get_pstate();
}
+Host* Host::set_factor_cb(const std::function<CpuFactorCb>& cb)
+{
+ kernel::actor::simcall([this, &cb] { pimpl_cpu_->set_factor_cb(cb); });
+ return this;
+}
+
Host* Host::set_coordinates(const std::string& coords)
{
if (not coords.empty())
if (user_bound > 0 && user_bound < action->get_bound()) {
get_model()->get_maxmin_system()->update_variable_bound(action->get_variable(), user_bound);
}
+ if (factor_cb_) {
+ action->set_rate_factor(factor_cb_(size));
+ }
return action;
}
return action;
}
+void CpuCas01::set_factor_cb(const std::function<s4u::Host::CpuFactorCb>& cb)
+{
+ xbt_assert(not is_sealed(), "Cannot set CPU factor callback in an already sealed CPU(%s)", get_cname());
+ factor_cb_ = cb;
+}
+
/**********
* Action *
**********/
CpuAction* execution_start(double size, double user_bound) override;
CpuAction* execution_start(double size, int requested_cores, double user_bound) override;
CpuAction* sleep(double duration) override;
+ void set_factor_cb(const std::function<s4u::Host::CpuFactorCb>& cb) override;
bool is_used() const override;
protected:
void on_speed_change() override;
+
+private:
+ std::function<s4u::Host::CpuFactorCb> factor_cb_ = {};
};
/**********
void set_sharing_policy(s4u::Host::SharingPolicy policy, const s4u::NonLinearResourceCb& cb);
s4u::Host::SharingPolicy get_sharing_policy() const;
+ /**
+ * @brief Sets factor callback
+ * Implemented only for cas01
+ */
+ virtual void set_factor_cb(const std::function<s4u::Host::CpuFactorCb>& cb) { THROW_UNIMPLEMENTED; }
+
/**
* @brief Execute some quantity of computation
*
default:
THROW_UNIMPLEMENTED;
}
+ const auto& factor_cb = disk->get_factor_cb();
+ if (factor_cb) { // handling disk variability
+ action->set_rate_factor(factor_cb(size, type));
+ }
return action;
}