From 24760d83c71aa79e6aab9d3922d30a607a6cf7da Mon Sep 17 00:00:00 2001 From: Adrien Gougeon Date: Sun, 16 Apr 2023 10:41:16 +0200 Subject: [PATCH] rename create to init. add init with name only. add setters --- .../operation-simple/s4u-operation-simple.cpp | 6 +- .../s4u-operation-switch-host.cpp | 12 ++-- .../s4u-operation-variable-load.cpp | 4 +- include/simgrid/plugins/operation.hpp | 16 +++-- src/plugins/operation.cpp | 60 +++++++++++++++---- 5 files changed, 70 insertions(+), 28 deletions(-) diff --git a/examples/cpp/operation-simple/s4u-operation-simple.cpp b/examples/cpp/operation-simple/s4u-operation-simple.cpp index 69773e38db..70656e864c 100644 --- a/examples/cpp/operation-simple/s4u-operation-simple.cpp +++ b/examples/cpp/operation-simple/s4u-operation-simple.cpp @@ -29,9 +29,9 @@ int main(int argc, char* argv[]) auto jupiter = e.host_by_name("Jupiter"); // Create operations - auto exec1 = simgrid::plugins::ExecOp::create("exec1", 1e9, tremblay); - auto exec2 = simgrid::plugins::ExecOp::create("exec2", 1e9, jupiter); - auto comm = simgrid::plugins::CommOp::create("comm", 1e7, tremblay, jupiter); + auto exec1 = simgrid::plugins::ExecOp::init("exec1", 1e9, tremblay); + auto exec2 = simgrid::plugins::ExecOp::init("exec2", 1e9, jupiter); + auto comm = simgrid::plugins::CommOp::init("comm", 1e7, tremblay, jupiter); // Create the graph by defining dependencies between operations exec1->add_successor(comm); diff --git a/examples/cpp/operation-switch-host/s4u-operation-switch-host.cpp b/examples/cpp/operation-switch-host/s4u-operation-switch-host.cpp index 63271ce150..f8c183db9f 100644 --- a/examples/cpp/operation-switch-host/s4u-operation-switch-host.cpp +++ b/examples/cpp/operation-switch-host/s4u-operation-switch-host.cpp @@ -33,11 +33,13 @@ int main(int argc, char* argv[]) auto fafard = e.host_by_name("Fafard"); // Create operations - auto comm0 = simgrid::plugins::CommOp::create("comm0", 1e7, tremblay, jupiter); - auto exec1 = simgrid::plugins::ExecOp::create("exec1", 1e9, jupiter); - auto exec2 = simgrid::plugins::ExecOp::create("exec2", 1e9, fafard); - auto comm1 = simgrid::plugins::CommOp::create("comm1", 1e7, jupiter, tremblay); - auto comm2 = simgrid::plugins::CommOp::create("comm2", 1e7, fafard, tremblay); + auto comm0 = simgrid::plugins::CommOp::init("comm0"); + comm0->set_bytes(1e7); + comm0->set_source(tremblay); + auto exec1 = simgrid::plugins::ExecOp::init("exec1", 1e9, jupiter); + auto exec2 = simgrid::plugins::ExecOp::init("exec2", 1e9, fafard); + auto comm1 = simgrid::plugins::CommOp::init("comm1", 1e7, jupiter, tremblay); + auto comm2 = simgrid::plugins::CommOp::init("comm2", 1e7, fafard, tremblay); // Create the initial graph by defining dependencies between operations comm0->add_successor(exec2); diff --git a/examples/cpp/operation-variable-load/s4u-operation-variable-load.cpp b/examples/cpp/operation-variable-load/s4u-operation-variable-load.cpp index 2144807b9b..9eea3da856 100644 --- a/examples/cpp/operation-variable-load/s4u-operation-variable-load.cpp +++ b/examples/cpp/operation-variable-load/s4u-operation-variable-load.cpp @@ -44,8 +44,8 @@ int main(int argc, char* argv[]) auto jupiter = e.host_by_name("Jupiter"); // Create operations - auto comm = simgrid::plugins::CommOp::create("comm", 1e7, tremblay, jupiter); - auto exec = simgrid::plugins::ExecOp::create("exec", 1e9, jupiter); + auto comm = simgrid::plugins::CommOp::init("comm", 1e7, tremblay, jupiter); + auto exec = simgrid::plugins::ExecOp::init("exec", 1e9, jupiter); // Create the graph by defining dependencies between operations comm->add_successor(exec); diff --git a/include/simgrid/plugins/operation.hpp b/include/simgrid/plugins/operation.hpp index 939543da2a..bf6a4ed057 100644 --- a/include/simgrid/plugins/operation.hpp +++ b/include/simgrid/plugins/operation.hpp @@ -46,7 +46,7 @@ protected: simgrid::s4u::ActivityPtr current_activity_; std::function end_func_ = [](Operation*) {}; std::function start_func_ = [](Operation*) {}; - Operation(const std::string& name, double amount); + Operation(const std::string& name); virtual ~Operation() = default; virtual void execute() = 0; @@ -77,12 +77,14 @@ class ExecOp : public Operation { private: simgrid::s4u::Host* host_; - ExecOp(const std::string& name, double flops, simgrid::s4u::Host* host); + ExecOp(const std::string& name); void execute(); public: - static ExecOpPtr create(const std::string& name, double flops, simgrid::s4u::Host* host); + static ExecOpPtr init(const std::string& name); + static ExecOpPtr init(const std::string& name, double flops, simgrid::s4u::Host* host); void set_host(simgrid::s4u::Host* host); + void set_flops(double flops); }; class CommOp : public Operation { @@ -90,14 +92,16 @@ private: simgrid::s4u::Host* source_; simgrid::s4u::Host* destination_; - CommOp(const std::string& name, double bytes, simgrid::s4u::Host* source, simgrid::s4u::Host* destination); + CommOp(const std::string& name); void execute(); public: - static CommOpPtr create(const std::string& name, double bytes, simgrid::s4u::Host* source, - simgrid::s4u::Host* destination); + static CommOpPtr init(const std::string& name); + static CommOpPtr init(const std::string& name, double bytes, simgrid::s4u::Host* source, + simgrid::s4u::Host* destination); void set_source(simgrid::s4u::Host* source); void set_destination(simgrid::s4u::Host* destination); + void set_bytes(double bytes); }; } // namespace simgrid::plugins #endif \ No newline at end of file diff --git a/src/plugins/operation.cpp b/src/plugins/operation.cpp index 68977c4093..a250332be2 100644 --- a/src/plugins/operation.cpp +++ b/src/plugins/operation.cpp @@ -16,7 +16,7 @@ To activate this plugin, first call :cpp:func:`Operation::init`. Operations are designed to represent workflows, i.e, graphs of Operations. Operations can only be instancied using either -:cpp:func:`simgrid::plugins::ExecOp::create` or :cpp:func:`simgrid::plugins::CommOp::create` +:cpp:func:`simgrid::plugins::ExecOp::init` or :cpp:func:`simgrid::plugins::CommOp::init` An ExecOp is an Execution Operation. Its underlying Activity is an :ref:`Exec `. A CommOp is a Communication Operation. Its underlying Activity is a :ref:`Comm `. @@ -29,7 +29,7 @@ namespace simgrid::plugins { xbt::signal Operation::on_start; xbt::signal Operation::on_end; -Operation::Operation(const std::string& name, double amount) : name_(name), amount_(amount) {} +Operation::Operation(const std::string& name) : name_(name) {} std::string Operation::get_name() { @@ -208,21 +208,32 @@ int Operation::get_count() /** * @brief Default constructor. */ -ExecOp::ExecOp(const std::string& name, double flops, simgrid::s4u::Host* host) : Operation(name, flops), host_(host) {} +ExecOp::ExecOp(const std::string& name) : Operation(name) {} /** @ingroup plugin_operation * @brief Smart Constructor. */ -ExecOpPtr ExecOp::create(const std::string& name, double flops, simgrid::s4u::Host* host) +ExecOpPtr ExecOp::init(const std::string& name) { - auto op = ExecOpPtr(new ExecOp(name, flops, host)); + auto op = ExecOpPtr(new ExecOp(name)); + return op; +} + +/** @ingroup plugin_operation + * @brief Smart Constructor. + */ +ExecOpPtr ExecOp::init(const std::string& name, double flops, simgrid::s4u::Host* host) +{ + auto op = ExecOpPtr(new ExecOp(name)); + op->set_flops(flops); + op->set_host(host); return op; } /** * @brief Do one execution of the Operation. * @note Call the on_this_start() func. Set its working status as true. - * Create and start the underlying Activity. + * Init and start the underlying Activity. */ void ExecOp::execute() { @@ -251,28 +262,45 @@ void ExecOp::set_host(simgrid::s4u::Host* host) simgrid::kernel::actor::simcall_answered([this, host] { host_ = host; }); } +/** @ingroup plugin_operation + * @param flops The amount of flops to set. + */ +void ExecOp::set_flops(double flops) +{ + simgrid::kernel::actor::simcall_answered([this, flops] { amount_ = flops; }); +} + /** * @brief Default constructor. */ -CommOp::CommOp(const std::string& name, double bytes, simgrid::s4u::Host* source, simgrid::s4u::Host* destination) - : Operation(name, bytes), source_(source), destination_(destination) +CommOp::CommOp(const std::string& name) : Operation(name) {} + +/** @ingroup plugin_operation + * @brief Smart constructor. + */ +CommOpPtr CommOp::init(const std::string& name) { + auto op = CommOpPtr(new CommOp(name)); + return op; } /** @ingroup plugin_operation * @brief Smart constructor. */ -CommOpPtr CommOp::create(const std::string& name, double bytes, simgrid::s4u::Host* source, - simgrid::s4u::Host* destination) +CommOpPtr CommOp::init(const std::string& name, double bytes, simgrid::s4u::Host* source, + simgrid::s4u::Host* destination) { - auto op = CommOpPtr(new CommOp(name, bytes, source, destination)); + auto op = CommOpPtr(new CommOp(name)); + op->set_bytes(bytes); + op->set_source(source); + op->set_destination(destination); return op; } /** * @brief Do one execution of the Operation. * @note Call the on_this_start() func. Set its working status as true. - * Create and start the underlying Activity. + * Init and start the underlying Activity. */ void CommOp::execute() { @@ -309,6 +337,14 @@ void CommOp::set_destination(simgrid::s4u::Host* destination) simgrid::kernel::actor::simcall_answered([this, destination] { destination_ = destination; }); } +/** @ingroup plugin_operation + * @param bytes The amount of bytes to set. + */ +void CommOp::set_bytes(double bytes) +{ + simgrid::kernel::actor::simcall_answered([this, bytes] { amount_ = bytes; }); +} + } // namespace simgrid::plugins simgrid::xbt::Extension -- 2.20.1