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