Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
deal with dependencies for Io too
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 27 Jan 2020 08:50:15 +0000 (09:50 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 27 Jan 2020 09:00:08 +0000 (10:00 +0100)
add an example that chains Exec and Io

MANIFEST.in
examples/s4u/CMakeLists.txt
examples/s4u/io-dependent/s4u-io-dependent.cpp [new file with mode: 0644]
examples/s4u/io-dependent/s4u-io-dependent.tesh [new file with mode: 0644]
src/kernel/activity/IoImpl.cpp
src/s4u/s4u_Io.cpp

index b088a00..0e36cdd 100644 (file)
@@ -384,6 +384,8 @@ include examples/s4u/exec-waitfor/s4u-exec-waitfor.cpp
 include examples/s4u/exec-waitfor/s4u-exec-waitfor.tesh
 include examples/s4u/io-async/s4u-io-async.cpp
 include examples/s4u/io-async/s4u-io-async.tesh
+include examples/s4u/io-dependent/s4u-io-dependent.cpp
+include examples/s4u/io-dependent/s4u-io-dependent.tesh
 include examples/s4u/io-disk-raw/s4u-io-disk-raw.cpp
 include examples/s4u/io-disk-raw/s4u-io-disk-raw.tesh
 include examples/s4u/io-file-remote/s4u-io-file-remote.cpp
index e87da01..0fb122d 100644 (file)
@@ -10,7 +10,7 @@ foreach (example actor-create actor-daemon actor-exiting actor-join actor-kill
                  energy-exec energy-boot energy-link energy-vm energy-exec-ptask
                  engine-filtering
                  exec-async exec-basic exec-dvfs exec-ptask exec-remote exec-waitany exec-waitfor exec-dependent
-                 io-async io-file-system io-file-remote io-disk-raw
+                 io-async io-file-system io-file-remote io-disk-raw io-dependent
                  platform-failures platform-profile platform-properties
                  plugin-hostload
                  replay-comm replay-io
diff --git a/examples/s4u/io-dependent/s4u-io-dependent.cpp b/examples/s4u/io-dependent/s4u-io-dependent.cpp
new file mode 100644 (file)
index 0000000..ba18226
--- /dev/null
@@ -0,0 +1,61 @@
+/* Copyright (c) 2007-2019. 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/s4u.hpp"
+#include <simgrid/plugins/file_system.h>
+#include <vector>
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+
+static void test()
+{
+  simgrid::s4u::ExecPtr bob_compute = simgrid::s4u::this_actor::exec_init(1e9);
+  simgrid::s4u::IoPtr bob_write =
+      simgrid::s4u::Host::current()->get_disks().front()->io_init(4000000, simgrid::s4u::Io::OpType::WRITE);
+  simgrid::s4u::IoPtr carl_read =
+      simgrid::s4u::Host::by_name("carl")->get_disks().front()->io_init(4000000, simgrid::s4u::Io::OpType::READ);
+  simgrid::s4u::ExecPtr carl_compute = simgrid::s4u::Host::by_name("carl")->exec_async(1e9);
+
+  // Name the activities (for logging purposes only)
+  bob_compute->set_name("bob compute");
+  bob_write->set_name("bob write");
+  carl_read->set_name("carl read");
+  carl_compute->set_name("carl compute");
+
+  // Create the dependencies:
+  // 'bob_write' is a successor of 'bob_compute'
+  // 'carl_read' is a successor of 'bob_write'
+  // 'carl_compute' is a successor of 'carl_read'
+  bob_compute->add_successor(bob_write.get());
+  bob_write->add_successor(carl_read.get());
+  carl_read->add_successor(carl_compute.get());
+
+  // Start the activities.
+  bob_compute->start();
+  bob_write->vetoable_start();
+  carl_read->vetoable_start();
+  carl_compute->vetoable_start();
+
+  // Wait for their completion (should be replaced by a wait_any_for at some point)
+  bob_compute->wait();
+  bob_write->wait();
+  carl_read->wait();
+  carl_compute->wait();
+}
+
+int main(int argc, char* argv[])
+{
+  simgrid::s4u::Engine e(&argc, argv);
+  sg_storage_file_system_init();
+  e.load_platform(argv[1]);
+
+  simgrid::s4u::Actor::create("bob", simgrid::s4u::Host::by_name("bob"), test);
+
+  e.run();
+
+  XBT_INFO("Simulation time %g", e.get_clock());
+
+  return 0;
+}
diff --git a/examples/s4u/io-dependent/s4u-io-dependent.tesh b/examples/s4u/io-dependent/s4u-io-dependent.tesh
new file mode 100644 (file)
index 0000000..26fb3b3
--- /dev/null
@@ -0,0 +1,11 @@
+#!/usr/bin/env tesh
+
+! output sort
+$ ${bindir:=.}/s4u-io-dependent ${platfdir}/hosts_with_disks.xml --log=s4u_activity.t:debug "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  1.000000] (1:bob@bob) All dependencies are solved, let's start 'bob write'
+> [  1.000000] (1:bob@bob) Remove a dependency from 'bob compute' on 'bob write'
+> [  1.100000] (1:bob@bob) All dependencies are solved, let's start 'carl read'
+> [  1.100000] (1:bob@bob) Remove a dependency from 'bob write' on 'carl read'
+> [  1.166667] (1:bob@bob) All dependencies are solved, let's start 'carl compute'
+> [  1.166667] (1:bob@bob) Remove a dependency from 'carl read' on 'carl compute'
+> [  2.166667] (0:maestro@) Simulation time 2.16667
index ce4254f..8125e0e 100644 (file)
@@ -34,6 +34,7 @@ void simcall_HANDLER_io_wait(smx_simcall_t simcall, simgrid::kernel::activity::I
       synchro->state_ = simgrid::kernel::activity::State::TIMEOUT;
     }
     synchro->finish();
+    return;
   }
 
   /* If the synchro is already finished then perform the error handling */
index 9b363ce..73149eb 100644 (file)
@@ -61,23 +61,28 @@ Io* Io::wait()
 
 Io* Io::wait_for(double timeout)
 {
+  if (state_ == State::INITED)
+    vetoable_start();
   simcall_io_wait(pimpl_, timeout);
   state_ = State::FINISHED;
+  this->release_dependencies();
   return this;
 }
 
 bool Io::test()
 {
-  xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::FINISHED);
+  xbt_assert(state_ == State::INITED || state_ == State::STARTED || state_ == State::STARTING ||
+             state_ == State::FINISHED);
 
   if (state_ == State::FINISHED)
     return true;
 
-  if (state_ == State::INITED)
-    this->start();
+  if (state_ == State::INITED || state_ == State::STARTING)
+    this->vetoable_start();
 
   if (simcall_io_test(pimpl_)) {
     state_ = State::FINISHED;
+    this->release_dependencies();
     return true;
   }