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)
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)
--- /dev/null
+/* 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;
+}
--- /dev/null
+#!/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