examples/s4u/app-masterworker/s4u_app-masterworker
examples/s4u/app-token-ring/s4u_app-token-ring
examples/s4u/actions-comm/s4u_actions-comm
+examples/s4u/actions-storage/s4u_actions-storage
examples/s4u/basic/s4u_basic
examples/s4u/basic/s4u_basic_deployment
examples/s4u/basic/s4u_basic_function
-foreach (example app-masterworker app-token-ring io launching mutex actions-comm actions-storage)
+foreach (example actor-migration app-masterworker app-token-ring io launching mutex actions-comm actions-storage)
add_executable (s4u_${example} ${example}/s4u_${example}.cpp)
target_link_libraries(s4u_${example} simgrid)
set_target_properties(s4u_${example} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${example})
${CMAKE_CURRENT_SOURCE_DIR}/actions-storage/s4u_actions-storage.txt
${CMAKE_CURRENT_SOURCE_DIR}/README.doc PARENT_SCOPE)
-foreach(example app-masterworker app-token-ring io launching mutex actions-comm actions-storage)
+foreach(example actor-migration app-masterworker app-token-ring io launching mutex actions-comm actions-storage)
ADD_TESH_FACTORIES(s4u-${example} "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_CURRENT_BINARY_DIR}/${example} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_HOME_DIRECTORY}/examples/s4u/${example} s4u_${example}.tesh)
endforeach()
--- /dev/null
+/* Copyright (c) 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/s4u/Mutex.hpp>
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_migration, "Messages specific for this s4u example");
+
+simgrid::s4u::MutexPtr checkpoint = nullptr;
+simgrid::s4u::ConditionVariablePtr identification = nullptr;
+static simgrid::s4u::ActorPtr controlled_process = nullptr;
+
+/* The Emigrant process will be moved from host to host. */
+static void emigrant()
+{
+ XBT_INFO("I'll look for a new job on another machine ('Boivin') where the grass is greener.");
+ simgrid::s4u::this_actor::migrate(
+ simgrid::s4u::Host::by_name("Boivin")); /* - First, move to another host by myself */
+
+ XBT_INFO("Yeah, found something to do");
+ simgrid::s4u::this_actor::execute(98095000);
+ simgrid::s4u::this_actor::sleep_for(2);
+
+ XBT_INFO("Moving back home after work");
+ simgrid::s4u::this_actor::migrate(simgrid::s4u::Host::by_name("Jacquelin")); /* - Move back to original location */
+
+ simgrid::s4u::this_actor::migrate(simgrid::s4u::Host::by_name("Boivin")); /* - Go back to the other host to sleep*/
+ simgrid::s4u::this_actor::sleep_for(4);
+
+ checkpoint->lock(); /* - Get controlled at checkpoint */
+ controlled_process = simgrid::s4u::Actor::self(); /* - and get moved back by the policeman process */
+ identification->notify_all();
+ checkpoint->unlock();
+
+ // TODO simgrid::s4u::this_actor::suspend(); to replace the sleep below
+ simgrid::s4u::this_actor::sleep_for(4);
+ XBT_INFO("I've been moved on this new host: %s", simgrid::s4u::this_actor::host()->cname());
+ XBT_INFO("Uh, nothing to do here. Stopping now");
+}
+
+/* The policeman check for emigrants and move them back to 'Jacquelin' */
+static void policeman()
+{
+ checkpoint->lock();
+
+ XBT_INFO("Wait at the checkpoint."); /* - block on the mutex+condition */
+ while (controlled_process == nullptr)
+ identification->wait(checkpoint);
+
+ controlled_process->migrate(simgrid::s4u::Host::by_name("Jacquelin")); /* - Move an emigrant to Jacquelin */
+ XBT_INFO("I moved the emigrant");
+ // TODO simgrid::s4u::this_actor::resume()
+
+ checkpoint->unlock();
+}
+
+int main(int argc, char* argv[])
+{
+ simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv);
+ xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
+ e->loadPlatform(argv[1]); /* - Load the platform description */
+
+ /* - Create and deploy the emigrant and policeman processes */
+ simgrid::s4u::Actor::createActor("emigrant", simgrid::s4u::Host::by_name("Jacquelin"), emigrant);
+ simgrid::s4u::Actor::createActor("policeman", simgrid::s4u::Host::by_name("Boivin"), policeman);
+
+ checkpoint = simgrid::s4u::Mutex::createMutex(); /* - Initiate the mutex and conditions */
+ identification = simgrid::s4u::ConditionVariable::createConditionVariable();
+ e->run();
+
+ XBT_INFO("Simulation time %g", e->getClock());
+
+ return 0;
+}
--- /dev/null
+#! ./tesh
+
+p Testing the migration feature of MSG
+
+! output sort 19
+$ $SG_TEST_EXENV ${bindir:=.}/s4u_actor-migration ${srcdir:=.}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n"
+> [ 0.000000] (emigrant@Jacquelin) I'll look for a new job on another machine ('Boivin') where the grass is greener.
+> [ 0.000000] (emigrant@Boivin) Yeah, found something to do
+> [ 0.000000] (policeman@Boivin) Wait at the checkpoint.
+> [ 3.000000] (emigrant@Boivin) Moving back home after work
+> [ 7.000000] (policeman@Boivin) I moved the emigrant
+> [ 11.000000] (emigrant@Jacquelin) I've been moved on this new host: Jacquelin
+> [ 11.000000] (emigrant@Jacquelin) Uh, nothing to do here. Stopping now
+> [ 11.000000] (maestro@) Simulation time 11
break;
}
/* - Otherwise, process the task */
- double comp_size = xbt_str_parse_double(res, nullptr);
+ double comp_size = std::stod(res);
xbt_free(res);
simgrid::s4u::this_actor::execute(comp_size);
}
/** @brief Simulation Agent */
XBT_PUBLIC_CLASS Actor : public simgrid::xbt::Extendable<Actor>
{
-
friend Mailbox;
friend simgrid::simix::ActorImpl;
friend simgrid::kernel::activity::MailboxImpl;
/** Retrieves the time at which that actor will be killed (or -1 if not set) */
double killTime();
+ void migrate(Host * new_host);
/** Ask the actor to die.
*
* It will only notice your request when doing a simcall next time (a communication or similar).
/** @brief Returns the name of the current actor. */
XBT_PUBLIC(std::string) name();
+
+ /** @brief Returns the name of the host on which the process is running. */
+ XBT_PUBLIC(Host*) host();
+
+ XBT_PUBLIC(void) migrate(Host* new_host);
};
/** @} */
// Wait functions without time:
+ void wait(MutexPtr lock);
void wait(std::unique_lock<Mutex>& lock);
template<class P>
void wait(std::unique_lock<Mutex>& lock, P pred)
simcall_process_auto_restart_set(pimpl_,autorestart);
}
+void Actor::migrate(Host* new_host)
+{
+ simcall_process_set_host(pimpl_, new_host);
+}
+
s4u::Host* Actor::host()
{
return this->pimpl_->host;
{
return SIMIX_process_self()->name;
}
+
+Host* host()
+{
+ return SIMIX_process_self()->host;
+}
+
+void migrate(Host* new_host)
+{
+ simcall_process_set_host(SIMIX_process_self(), new_host);
+}
}
}
}
/**
* Wait functions
*/
+void ConditionVariable::wait(MutexPtr lock)
+{
+ simcall_cond_wait(cond_, lock->mutex_);
+}
+
void ConditionVariable::wait(std::unique_lock<Mutex>& lock) {
simcall_cond_wait(cond_, lock.mutex()->mutex_);
}
{
process->new_host = dest;
}
+
void SIMIX_process_change_host(smx_actor_t process, sg_host_t dest)
{
xbt_assert((process != nullptr), "Invalid parameters");