Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add C version of exec-async
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 6 Mar 2020 16:23:41 +0000 (17:23 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 6 Mar 2020 16:25:22 +0000 (17:25 +0100)
MANIFEST.in
examples/c/CMakeLists.txt
examples/c/exec-async/exec-async.c [new file with mode: 0644]
examples/c/exec-async/exec-async.tesh [new file with mode: 0644]

index 3189977..51f8340 100644 (file)
@@ -74,6 +74,8 @@ include examples/c/energy-exec/energy-exec.c
 include examples/c/energy-exec/energy-exec.tesh
 include examples/c/energy-vm/energy-vm.c
 include examples/c/energy-vm/energy-vm.tesh
+include examples/c/exec-async/exec-async.c
+include examples/c/exec-async/exec-async.tesh
 include examples/c/exec-basic/exec-basic.c
 include examples/c/exec-basic/exec-basic.tesh
 include examples/c/exec-dvfs/exec-dvfs.c
index 173b87c..dff3d89 100644 (file)
@@ -7,7 +7,7 @@ foreach(x
         app-pingpong app-token-ring 
         async-wait async-waitall async-waitany
         cloud-capping cloud-migration cloud-simple
-        exec-basic exec-dvfs exec-remote
+        exec-async exec-basic exec-dvfs exec-remote
         energy-exec energy-exec-ptask energy-vm
         io-disk-raw io-file-remote
         plugin-hostload)
@@ -62,7 +62,7 @@ foreach(x
         app-chainsend app-pingpong app-token-ring
         async-wait async-waitall async-waitany
         cloud-capping cloud-migration cloud-simple
-        exec-basic exec-dvfs exec-remote
+        exec-async exec-basic exec-dvfs exec-remote
         energy-exec energy-exec-ptask energy-vm
         io-disk-raw io-file-remote
         plugin-hostload)
diff --git a/examples/c/exec-async/exec-async.c b/examples/c/exec-async/exec-async.c
new file mode 100644 (file)
index 0000000..c795d9b
--- /dev/null
@@ -0,0 +1,79 @@
+/* Copyright (c) 2007-2020. 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. */
+
+#include "simgrid/actor.h"
+#include "simgrid/engine.h"
+#include "simgrid/exec.h"
+#include "simgrid/host.h"
+
+#include "xbt/asserts.h"
+#include "xbt/log.h"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(exec_async, "Messages specific for this example");
+
+/* This actor simply waits for its task completion after starting it.
+ * That's exactly equivalent to synchronous execution. */
+static void waiter(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
+{
+  double computation_amount = sg_host_speed(sg_host_self());
+  XBT_INFO("Execute %g flops, should take 1 second.", computation_amount);
+  sg_exec_t activity = sg_actor_exec_init(computation_amount);
+  sg_exec_start(activity);
+  sg_exec_wait(activity);
+
+  XBT_INFO("Goodbye now!");
+}
+
+/* This actor tests the ongoing execution until its completion, and don't wait before it's terminated. */
+static void monitor(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
+{
+  double computation_amount = sg_host_speed(sg_host_self());
+  XBT_INFO("Execute %g flops, should take 1 second.", computation_amount);
+  sg_exec_t activity = sg_actor_exec_init(computation_amount);
+  sg_exec_start(activity);
+
+  while (!sg_exec_test(activity)) {
+    XBT_INFO("Remaining amount of flops: %g (%.0f%%)", sg_exec_get_remaining(activity),
+             100 * sg_exec_get_remaining_ratio(activity));
+    sg_actor_sleep_for(0.3);
+  }
+
+  XBT_INFO("Goodbye now!");
+}
+
+/* This actor cancels the ongoing execution after a while. */
+static void canceller(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
+{
+  double computation_amount = sg_host_speed(sg_host_self());
+
+  XBT_INFO("Execute %g flops, should take 1 second.", computation_amount);
+  sg_exec_t activity = sg_actor_exec_init(computation_amount);
+  sg_exec_start(activity);
+  sg_actor_sleep_for(0.5);
+  XBT_INFO("I changed my mind, cancel!");
+  sg_exec_cancel(activity);
+
+  XBT_INFO("Goodbye now!");
+}
+
+int main(int argc, char* argv[])
+{
+  simgrid_init(&argc, argv);
+  simgrid_load_platform(argv[1]);
+
+  sg_host_t fafard  = sg_host_by_name("Fafard");
+  sg_host_t ginette = sg_host_by_name("Ginette");
+  sg_host_t boivin  = sg_host_by_name("Boivin");
+
+  sg_actor_create("wait", fafard, waiter, 0, NULL);
+  sg_actor_create("monitor", ginette, monitor, 0, NULL);
+  sg_actor_create("cancel", boivin, canceller, 0, NULL);
+
+  simgrid_run();
+
+  XBT_INFO("Simulation time %g", simgrid_get_clock());
+
+  return 0;
+}
diff --git a/examples/c/exec-async/exec-async.tesh b/examples/c/exec-async/exec-async.tesh
new file mode 100644 (file)
index 0000000..d15abe3
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/env tesh
+
+$ ${bindir:=.}/exec-async-c ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (1:wait@Fafard) Execute 7.6296e+07 flops, should take 1 second.
+> [  0.000000] (2:monitor@Ginette) Execute 4.8492e+07 flops, should take 1 second.
+> [  0.000000] (3:cancel@Boivin) Execute 9.8095e+07 flops, should take 1 second.
+> [  0.000000] (2:monitor@Ginette) Remaining amount of flops: 4.8492e+07 (100%)
+> [  0.300000] (2:monitor@Ginette) Remaining amount of flops: 3.39444e+07 (70%)
+> [  0.500000] (3:cancel@Boivin) I changed my mind, cancel!
+> [  0.500000] (3:cancel@Boivin) Goodbye now!
+> [  0.600000] (2:monitor@Ginette) Remaining amount of flops: 1.93968e+07 (40%)
+> [  0.900000] (2:monitor@Ginette) Remaining amount of flops: 4.8492e+06 (10%)
+> [  1.000000] (1:wait@Fafard) Goodbye now!
+> [  1.200000] (2:monitor@Ginette) Goodbye now!
+> [  1.200000] (0:maestro@) Simulation time 1.2