Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add operation examples
authorAdrien Gougeon <adrien.gougeon@ens-rennes.fr>
Tue, 11 Apr 2023 13:48:40 +0000 (15:48 +0200)
committerAdrien Gougeon <adrien.gougeon@ens-rennes.fr>
Wed, 12 Apr 2023 09:20:12 +0000 (11:20 +0200)
examples/cpp/CMakeLists.txt
examples/cpp/operation-simple/s4u-operation-simple.cpp [new file with mode: 0644]
examples/cpp/operation-simple/s4u-operation-simple.tesh [new file with mode: 0644]
examples/cpp/operation-switch-host/s4u-operation-switch-host.cpp [new file with mode: 0644]
examples/cpp/operation-switch-host/s4u-operation-switch-host.tesh [new file with mode: 0644]
examples/cpp/operation-variable-load/s4u-operation-variable-load.cpp [new file with mode: 0644]
examples/cpp/operation-variable-load/s4u-operation-variable-load.tesh [new file with mode: 0644]

index a43cfda..9389a4d 100644 (file)
@@ -155,6 +155,7 @@ foreach (example activity-testany activity-waitany
                  mc-bugged1 mc-bugged1-liveness mc-bugged2 mc-bugged2-liveness mc-centralized-mutex mc-electric-fence mc-failing-assert
                  network-ns3 network-ns3-wifi network-wifi
                  io-async io-priority io-degradation io-file-system io-file-remote io-disk-raw io-dependent
+                 operation-simple operation-variable-load operation-switch-host
                  platform-comm-serialize platform-failures platform-profile platform-properties
                  plugin-host-load plugin-link-load plugin-prodcons
                  replay-comm replay-io
diff --git a/examples/cpp/operation-simple/s4u-operation-simple.cpp b/examples/cpp/operation-simple/s4u-operation-simple.cpp
new file mode 100644 (file)
index 0000000..f540dd3
--- /dev/null
@@ -0,0 +1,53 @@
+/* Copyright (c) 2017-2023. 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 demonstrate basic use of the operation plugin.
+ *
+ * We model the following graph: 
+ * 
+ * exec1 -> comm -> exec2
+ * 
+ * exec1 and exec2 are execution operations.
+ * comm is a communication operation.
+ */
+
+#include "simgrid/s4u.hpp"
+#include "simgrid/plugins/operation.hpp"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(operation_simple, "Messages specific for this operation example");
+
+int main(int argc, char* argv[])
+{
+    simgrid::s4u::Engine e(&argc, argv);
+    e.load_platform(argv[1]);
+    simgrid::plugins::Operation::init();
+
+    // Retrieve hosts
+    auto tremblay = e.host_by_name("Tremblay");
+    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);
+
+    // Create the graph by defining dependencies between operations
+    exec1->add_successor(comm);
+    comm->add_successor(exec2);
+
+    // Add a function to be called when operations end for log purpose
+    std::vector<simgrid::plugins::OperationPtr> ops{exec1,exec2,comm};
+    for (auto op: ops)
+        op->on_end([](simgrid::plugins::Operation* op) {
+            XBT_INFO("Operation %s finished (%d)",op->get_name().c_str(), op->get_count());
+        });
+
+    // Enqueue two executions for operation exec1
+    exec1->enqueue_execs(2);
+
+    // Start the simulation
+    e.run();
+    return 0;
+}
diff --git a/examples/cpp/operation-simple/s4u-operation-simple.tesh b/examples/cpp/operation-simple/s4u-operation-simple.tesh
new file mode 100644 (file)
index 0000000..c9eee76
--- /dev/null
@@ -0,0 +1,9 @@
+#!/usr/bin/env tesh
+
+$ ${bindir:=.}/s4u-operation-simple ${platfdir}/small_platform.xml
+> [10.194200] [operation_simple/INFO] Operation exec1 finished (1)
+> [11.714617] [operation_simple/INFO] Operation comm finished (1)
+> [20.388399] [operation_simple/INFO] Operation exec1 finished (2)
+> [21.908817] [operation_simple/INFO] Operation comm finished (2)
+> [24.821464] [operation_simple/INFO] Operation exec2 finished (1)
+> [37.928311] [operation_simple/INFO] Operation exec2 finished (2)
diff --git a/examples/cpp/operation-switch-host/s4u-operation-switch-host.cpp b/examples/cpp/operation-switch-host/s4u-operation-switch-host.cpp
new file mode 100644 (file)
index 0000000..5803181
--- /dev/null
@@ -0,0 +1,79 @@
+/* Copyright (c) 2017-2023. 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 demonstrates how to dynamically modify a graph of operations.
+ * 
+ * Assuming we have two instances of a service placed on different hosts, 
+ * we want to send data alternatively to thoses instances.
+ *
+ * We consider the following graph:
+ * 
+ * comm0 -> exec1 -> comm1
+ *     ↳-> exec2 ->comm2 
+ * 
+ * With exec1 and exec2 on different hosts.
+ */
+
+#include "simgrid/s4u.hpp"
+#include "simgrid/plugins/operation.hpp"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(operation_switch_host, "Messages specific for this operation example");
+
+int main(int argc, char* argv[])
+{
+    simgrid::s4u::Engine e(&argc, argv);
+    e.load_platform(argv[1]);
+    simgrid::plugins::Operation::init();
+
+    // Retrieve hosts
+    auto tremblay = e.host_by_name("Tremblay");
+    auto jupiter = e.host_by_name("Jupiter");
+    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);
+
+    // Create the initial graph by defining dependencies between operations
+    comm0->add_successor(exec2);
+    exec1->add_successor(comm1);
+    exec2->add_successor(comm2);
+
+    // Add a function to be called when operations end for log purpose
+    std::vector<simgrid::plugins::OperationPtr> v = 
+        {comm0,exec1,exec2,comm1,comm2};
+    for (auto op : v)
+        op->on_end([](simgrid::plugins::Operation* op) {
+            XBT_INFO("Operation %s finished (%d)",op->get_name().c_str(), op->get_count());
+        });
+
+    // Add a function to be called before each executions of comm0
+    // This function modifies the graph of operations by adding or removing
+    // successors to comm0
+    int count = 0;
+    comm0->on_start([&](simgrid::plugins::Operation* op) {
+        if (count % 2 == 0) {
+            comm0->set_destination(jupiter);
+            comm0->add_successor(exec1);
+            comm0->remove_successor(exec2);
+        }
+        else {
+            comm0->set_destination(fafard);
+            comm0->add_successor(exec2);
+            comm0->remove_successor(exec1);
+        }
+        count++;
+    });
+
+    // Enqueue four executions for operation comm0
+    comm0->enqueue_execs(4);
+
+    // Start the simulation
+    e.run();
+    return 0;
+}
diff --git a/examples/cpp/operation-switch-host/s4u-operation-switch-host.tesh b/examples/cpp/operation-switch-host/s4u-operation-switch-host.tesh
new file mode 100644 (file)
index 0000000..20bff40
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/env tesh
+
+$ ${bindir:=.}/s4u-operation-switch-host ${platfdir}/small_platform.xml
+> [1.520418] [operation_switch_host/INFO] Operation comm0 finished (1)
+> [2.873012] [operation_switch_host/INFO] Operation comm0 finished (2)
+> [4.393430] [operation_switch_host/INFO] Operation comm0 finished (3)
+> [5.746025] [operation_switch_host/INFO] Operation comm0 finished (4)
+> [14.627265] [operation_switch_host/INFO] Operation exec1 finished (1)
+> [15.979859] [operation_switch_host/INFO] Operation exec2 finished (1)
+> [16.147682] [operation_switch_host/INFO] Operation comm1 finished (1)
+> [17.332454] [operation_switch_host/INFO] Operation comm2 finished (1)
+> [27.734112] [operation_switch_host/INFO] Operation exec1 finished (2)
+> [29.086707] [operation_switch_host/INFO] Operation exec2 finished (2)
+> [29.254529] [operation_switch_host/INFO] Operation comm1 finished (2)
+> [30.439301] [operation_switch_host/INFO] Operation comm2 finished (2)
\ No newline at end of file
diff --git a/examples/cpp/operation-variable-load/s4u-operation-variable-load.cpp b/examples/cpp/operation-variable-load/s4u-operation-variable-load.cpp
new file mode 100644 (file)
index 0000000..3aa32fd
--- /dev/null
@@ -0,0 +1,66 @@
+/* Copyright (c) 2017-2023. 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 demonstrates how to create a variable load for operations.
+ * 
+ * We consider the following graph:
+ * 
+ * comm -> exec
+ * 
+ * With a small load each comm operation is followed by an exec operation.
+ * With a heavy load there is a burst of comm before the exec operation can even finish once.
+ */
+
+#include "simgrid/s4u.hpp"
+#include "simgrid/plugins/operation.hpp"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(operation_variable_load, "Messages specific for this s4u example");
+
+static void variable_load(simgrid::plugins::OperationPtr op)
+{
+    XBT_INFO("--- Small load ---");
+    for (int i=0; i < 3; i++) {
+        op->enqueue_execs(1);
+        simgrid::s4u::this_actor::sleep_for(100);
+    }
+    simgrid::s4u::this_actor::sleep_until(1000);
+    XBT_INFO("--- Heavy load ---");
+    for (int i=0; i < 3; i++) {
+        op->enqueue_execs(1);
+        simgrid::s4u::this_actor::sleep_for(1);
+    }
+}
+
+int main(int argc, char* argv[])
+{
+    simgrid::s4u::Engine e(&argc, argv);
+    e.load_platform(argv[1]);
+    simgrid::plugins::Operation::init();
+
+    // Retreive hosts
+    auto tremblay = e.host_by_name("Tremblay");
+    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);
+
+    // Create the graph by defining dependencies between operations
+    comm->add_successor(exec);
+
+    // Add a function to be called when operations end for log purpose
+    std::vector<simgrid::plugins::OperationPtr> ops{exec,comm};
+    for (auto op: ops)
+        op->on_end([](simgrid::plugins::Operation* op) {
+            XBT_INFO("Operation %s finished (%d)",op->get_name().c_str(), op->get_count());
+        });
+
+    // Create the actor that will inject load during the simulation
+    simgrid::s4u::Actor::create("input", tremblay, variable_load, comm);
+
+    // Start the simulation
+    e.run();
+    return 0;
+}
diff --git a/examples/cpp/operation-variable-load/s4u-operation-variable-load.tesh b/examples/cpp/operation-variable-load/s4u-operation-variable-load.tesh
new file mode 100644 (file)
index 0000000..b0d5cec
--- /dev/null
@@ -0,0 +1,17 @@
+#!/usr/bin/env tesh
+
+$ ${bindir:=.}/s4u-operation-variable-load ${platfdir}/small_platform.xml
+> [Tremblay:input:(1) 0.000000] [operation_variable_load/INFO] --- Small load ---
+> [1.520418] [operation_variable_load/INFO] Operation comm finished (1)
+> [14.627265] [operation_variable_load/INFO] Operation exec finished (1)
+> [101.520418] [operation_variable_load/INFO] Operation comm finished (2)
+> [114.627265] [operation_variable_load/INFO] Operation exec finished (2)
+> [201.520418] [operation_variable_load/INFO] Operation comm finished (3)
+> [214.627265] [operation_variable_load/INFO] Operation exec finished (3)
+> [Tremblay:input:(1) 1000.000000] [operation_variable_load/INFO] --- Heavy load ---
+> [1001.520418] [operation_variable_load/INFO] Operation comm finished (4)
+> [1003.040835] [operation_variable_load/INFO] Operation comm finished (5)
+> [1004.561253] [operation_variable_load/INFO] Operation comm finished (6)
+> [1014.627265] [operation_variable_load/INFO] Operation exec finished (4)
+> [1027.734112] [operation_variable_load/INFO] Operation exec finished (5)
+> [1040.840959] [operation_variable_load/INFO] Operation exec finished (6)