Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 7 Dec 2017 14:09:43 +0000 (15:09 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Thu, 7 Dec 2017 14:09:43 +0000 (15:09 +0100)
examples/s4u/CMakeLists.txt
examples/s4u/execute-priority/s4u-execute-priority.cpp [new file with mode: 0644]
examples/s4u/execute-priority/s4u-execute-priority.tesh [new file with mode: 0644]
include/simgrid/s4u/Exec.hpp
src/s4u/s4u_exec.cpp [new file with mode: 0644]
tools/cmake/DefinePackages.cmake

index 7ce2000..eda4aa1 100644 (file)
@@ -4,6 +4,7 @@ foreach (example actions-comm actions-storage
                  async-wait async-waitany async-waitall
                  cloud-progress-monitor
                  energy-link energy-pstate energy-ptask energy-vm
+                 execute-priority
                  io-file-system io-file-remote io-storage-raw
                  platform-properties plugin-hostload mutex)
   add_executable       (s4u-${example}  ${example}/s4u-${example}.cpp)
@@ -71,6 +72,7 @@ foreach(example actions-comm actions-storage
                 cloud-progress-monitor
                 dht-chord 
                 energy-link energy-pstate energy-ptask energy-vm
+                execute-priority
                 platform-properties plugin-hostload mutex
                 io-file-system io-file-remote io-storage-raw)
   ADD_TESH_FACTORIES(s4u-${example} "thread;ucontext;raw;boost" 
diff --git a/examples/s4u/execute-priority/s4u-execute-priority.cpp b/examples/s4u/execute-priority/s4u-execute-priority.cpp
new file mode 100644 (file)
index 0000000..5813a4e
--- /dev/null
@@ -0,0 +1,35 @@
+/* Copyright (c) 2007-2017. 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/forward.h"
+#include "simgrid/s4u/forward.hpp"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+
+static void test(double computation_amount, double priority)
+{
+  XBT_INFO("Hello! Execute %g flops with priority %g", computation_amount, priority);
+  simgrid::s4u::ExecPtr activity = simgrid::s4u::Actor::self()->exec_init(computation_amount);
+  activity->setPriority(priority);
+  activity->start();
+  activity->wait();
+
+  XBT_INFO("Goodbye now!");
+}
+
+int main(int argc, char* argv[])
+{
+  simgrid::s4u::Engine e(&argc, argv);
+  e.loadPlatform(argv[1]);
+  simgrid::s4u::Actor::createActor("test", simgrid::s4u::Host::by_name("Fafard"), test, 7.6296e+07, 1.0);
+  simgrid::s4u::Actor::createActor("test", simgrid::s4u::Host::by_name("Fafard"), test, 7.6296e+07, 2.0);
+
+  e.run();
+
+  XBT_INFO("Simulation time %g", e.getClock());
+
+  return 0;
+}
diff --git a/examples/s4u/execute-priority/s4u-execute-priority.tesh b/examples/s4u/execute-priority/s4u-execute-priority.tesh
new file mode 100644 (file)
index 0000000..a0e31be
--- /dev/null
@@ -0,0 +1,9 @@
+#! ./tesh
+
+! output sort 19
+$ $SG_TEST_EXENV ${bindir:=.}/s4u-execute-priority$EXEEXT ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (1:test@Fafard) Hello! Execute 7.6296e+07 flops with priority 1
+> [  0.000000] (2:test@Fafard) Hello! Execute 7.6296e+07 flops with priority 2
+> [  1.500000] (2:test@Fafard) Goodbye now!
+> [  2.000000] (0:maestro@) Simulation time 2
+> [  2.000000] (1:test@Fafard) Goodbye now!
index 84b0ea0..f24e3a9 100644 (file)
@@ -6,10 +6,12 @@
 #ifndef SIMGRID_S4U_EXEC_HPP
 #define SIMGRID_S4U_EXEC_HPP
 
-#include "src/kernel/activity/ExecImpl.hpp"
 #include <simgrid/forward.h>
+#include <simgrid/s4u/Activity.hpp>
 #include <simgrid/s4u/forward.hpp>
 
+#include <atomic>
+
 namespace simgrid {
 namespace s4u {
 
@@ -17,39 +19,25 @@ XBT_PUBLIC_CLASS Exec : public Activity
 {
   Exec() : Activity() {}
 public:
-  friend void intrusive_ptr_release(simgrid::s4u::Exec * e)
-  {
-    if (e->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
-      std::atomic_thread_fence(std::memory_order_acquire);
-      delete e;
-    }
-  }
-
-  friend void intrusive_ptr_add_ref(simgrid::s4u::Exec * e) { e->refcount_.fetch_add(1, std::memory_order_relaxed); }
-
+  friend void intrusive_ptr_release(simgrid::s4u::Exec * e);
+  friend void intrusive_ptr_add_ref(simgrid::s4u::Exec * e);
   friend Actor; // Factory of Exec
 
   ~Exec() = default;
 
-  void start() override
-  {
-    pimpl_ = simcall_execution_start(nullptr, flops_amount_, 1 / priority_, 0.);
-    state_ = started;
-  }
-  void wait() override { this->wait(-1); }
-  void wait(double timeout) override { simcall_execution_wait(pimpl_); }
+  void start() override;
+  void wait() override;
+  void wait(double timeout) override;
+  bool test();
+
+  ExecPtr setPriority(double priority);
 
-  double getRemains()
-  {
-    return simgrid::simix::kernelImmediate(
-        [this]() { return boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(pimpl_)->remains(); });
-  }
+  double getRemains();
 
 private:
   smx_actor_t runner_  = nullptr;
   double flops_amount_ = 0.0;
   double priority_     = 1.0;
-  double bound_        = 0.0;
 
   std::atomic_int_fast32_t refcount_{0};
 }; // class
diff --git a/src/s4u/s4u_exec.cpp b/src/s4u/s4u_exec.cpp
new file mode 100644 (file)
index 0000000..bc78b1e
--- /dev/null
@@ -0,0 +1,72 @@
+/* Copyright (c) 2006-2017. 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 "xbt/log.h"
+
+#include "simgrid/s4u/Actor.hpp"
+#include "simgrid/s4u/Exec.hpp"
+#include "src/kernel/activity/ExecImpl.hpp"
+
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_exec, s4u_activity, "S4U asynchronous executions");
+
+namespace simgrid {
+namespace s4u {
+
+void Exec::start()
+{
+  pimpl_ = simcall_execution_start(nullptr, flops_amount_, 1 / priority_, 0.);
+  state_ = started;
+}
+
+void Exec::wait()
+{
+  this->wait(-1);
+}
+
+void Exec::wait(double timeout)
+{
+  simcall_execution_wait(pimpl_);
+}
+
+bool Exec::test()
+{
+  xbt_assert(state_ == inited || state_ == started || state_ == finished);
+
+  if (state_ == finished) {
+    return true;
+  }
+
+  if (state_ == inited) {
+    this->start();
+  }
+
+  return false;
+}
+
+ExecPtr Exec::setPriority(double priority)
+{
+  priority_ = priority;
+  return this;
+}
+
+double Exec::getRemains()
+{
+  return simgrid::simix::kernelImmediate(
+      [this]() { return boost::static_pointer_cast<simgrid::kernel::activity::ExecImpl>(pimpl_)->remains(); });
+}
+
+void intrusive_ptr_release(simgrid::s4u::Exec* e)
+{
+  if (e->refcount_.fetch_sub(1, std::memory_order_release) == 1) {
+    std::atomic_thread_fence(std::memory_order_acquire);
+    delete e;
+  }
+}
+
+void intrusive_ptr_add_ref(simgrid::s4u::Exec* e)
+{
+  e->refcount_.fetch_add(1, std::memory_order_relaxed);
+}
+}
+}
index 5a2b006..38517be 100644 (file)
@@ -427,7 +427,8 @@ set(S4U_SRC
   src/s4u/s4u_conditionVariable.cpp
   src/s4u/s4u_comm.cpp
   src/s4u/s4u_engine.cpp  
-   src/s4u/s4u_host.cpp  
+  src/s4u/s4u_exec.cpp  
+  src/s4u/s4u_host.cpp  
   src/s4u/s4u_link.cpp
   src/s4u/s4u_mailbox.cpp
   src/s4u/s4u_mutex.cpp