Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename create to init. add init with name only. add setters
authorAdrien Gougeon <adrien.gougeon@ens-rennes.fr>
Sun, 16 Apr 2023 08:41:16 +0000 (10:41 +0200)
committerAdrien Gougeon <adrien.gougeon@ens-rennes.fr>
Sun, 16 Apr 2023 08:41:16 +0000 (10:41 +0200)
examples/cpp/operation-simple/s4u-operation-simple.cpp
examples/cpp/operation-switch-host/s4u-operation-switch-host.cpp
examples/cpp/operation-variable-load/s4u-operation-variable-load.cpp
include/simgrid/plugins/operation.hpp
src/plugins/operation.cpp

index 69773e3..70656e8 100644 (file)
@@ -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);
index 63271ce..f8c183d 100644 (file)
@@ -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);
index 2144807..9eea3da 100644 (file)
@@ -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);
index 939543d..bf6a4ed 100644 (file)
@@ -46,7 +46,7 @@ protected:
   simgrid::s4u::ActivityPtr current_activity_;
   std::function<void(Operation*)> end_func_   = [](Operation*) {};
   std::function<void(Operation*)> 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
index 68977c4..a250332 100644 (file)
@@ -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 <API_s4u_Exec>`.
 A CommOp is a Communication Operation. Its underlying Activity is a :ref:`Comm <API_s4u_Comm>`.
 
@@ -29,7 +29,7 @@ namespace simgrid::plugins {
 xbt::signal<void(Operation*)> Operation::on_start;
 xbt::signal<void(Operation*)> 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<simgrid::s4u::Activity, simgrid::plugins::ExtendedAttributeActivity>