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()
@brief Find the S4U example fitting your needs in the archive.
- @ref s4u_ex_basics
+ - @ref s4u_ex_actors
- @ref s4u_ex_synchro
+ - @ref s4u_ex_actions
@section s4u_ex_basics Basics of SimGrid simulation
Shows how to implement a classical communication pattern, where a token is exchanged along a ring to reach every
participant.
- - <b>Master Workers:</b> @ref examples/s4u/app-token-ring/s4u_app-token-ring.cpp \n
+ - <b>Master Workers:</b> @ref examples/s4u/app-masterworker/s4u_app-masterworker.cpp \n
Another good old example, where one Master process has a bunch of task to dispatch to a set of several Worker
processes.
+@section s4u_ex_actors Acting on Actors
+
+ - <b>Migrating Actors</b>.
+ @ref examples/s4u/actor-migration/s4u_actor-migration.cpp \n
+ Actors can move or be moved from a host to another with the @ref migrate method.
+
@section s4u_ex_synchro Inter-Actor Synchronization
- <b>Mutex: </b> @ref examples/s4u/mutex/s4u_mutex.cpp \n
Shows how to use simgrid::s4u::Mutex synchronization objects.
-
+
+@section s4u_ex_actions Following Workload Traces
+
+This section details how to run trace-driven simulations. It is very
+handy when you want to test an algorithm or protocol that only react
+to external events. For example, many P2P protocols react to user
+requests, but do nothing if there is no such event.
+
+In such situations, you should write your protocol in C++, and separate
+the workload that you want to play onto your protocol in a separate
+text file. Declare a function handling each type of the events in your
+trace, register them using @ref xbt_replay_action_register in your
+main, and then run the simulation.
+
+Then, you can either have one trace file containing all your events,
+or a file per simulated process: the former may be easier to work
+with, but the second is more efficient on very large traces. Check
+also the tesh files in the example directories for details.
+
+ - <b>Communication replay</b>.
+ @ref examples/s4u/actions-comm/s4u_actions-comm.cpp \n
+ Presents a set of event handlers reproducing classical communication
+ primitives (asynchronous send/receive at the moment).
+
+ - <b>I/O replay</b>.
+ @ref examples/s4u/actions-storage/s4u_actions-storage.cpp \n
+ Presents a set of event handlers reproducing classical I/O
+ primitives (open, read, close).
+
*/
/**
-@example examples/s4u/launching/s4u_launching.cpp
+@example examples/s4u/actions-comm/s4u_actions-comm.cpp
+@example examples/s4u/actions-storage/s4u_actions-storage.cpp
+@example examples/s4u/actor-migration/s4u_actor-migration.cpp
@example examples/s4u/app-token-ring/s4u_app-token-ring.cpp
@example examples/s4u/app-master-worker/s4u_app-master-worker.cpp
@example examples/s4u/launching/deployment.xml
+@example examples/s4u/launching/s4u_launching.cpp
@example examples/s4u/mutex/s4u_mutex.cpp
*/
\ No newline at end of file
xbt_replay_action_register("send", Replayer::send);
xbt_replay_action_register("recv", Replayer::recv);
- /* Actually do the simulation using MSG_action_trace_run */
if (argv[3]) {
simgrid::xbt::action_fs = new std::ifstream(argv[3], std::ifstream::in);
}
xbt_replay_action_register("read", Replayer::read);
xbt_replay_action_register("close", Replayer::close);
- /* Actually do the simulation using MSG_action_trace_run */
if (argv[3]) {
simgrid::xbt::action_fs = new std::ifstream(argv[3], std::ifstream::in);
}
--- /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();
+
+ simgrid::s4u::this_actor::suspend();
+
+ 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");
+ controlled_process->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] (maestro@) Simulation time 7
+> [ 7.000000] (emigrant@Jacquelin) I've been moved on this new host: Jacquelin
+> [ 7.000000] (emigrant@Jacquelin) Uh, nothing to do here. Stopping now
+> [ 7.000000] (policeman@Boivin) I moved the emigrant
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 PPID of that actor */
int ppid();
+ /** Suspend an actor by suspending the task on which it was waiting for the completion. */
+ void suspend();
+
+ /** Resume a suspended process by resuming the task on which it was waiting for the completion. */
+ void resume();
+
/** If set to true, the actor will automatically restart when its host reboots */
void setAutoRestart(bool autorestart);
/** Sets the time at which that actor should be killed */
/** 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();
+
+ /** @brief Suspend the actor. */
+ XBT_PUBLIC(void) suspend();
+
+ /** @brief Resume the actor. */
+ XBT_PUBLIC(void) resume();
+
+ /** @brief Migrate the actor to a new 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)
setlocale(LC_NUMERIC,"C");
if (jargs)
- argc = (int) env->GetArrayLength(jargs);
+ argc = static_cast<int>(env->GetArrayLength(jargs));
argc++;
argv = xbt_new(char *, argc + 1);
JAVA_HOST_LEVEL = simgrid::s4u::Host::extension_create(__JAVA_host_priv_free);
JAVA_STORAGE_LEVEL = xbt_lib_add_level(storage_lib, __JAVA_storage_priv_free);
- for (index = 0; index < argc; index++)
+ for (index = 0; index < argc - 1; index++) {
+ env->SetObjectArrayElement(jargs, index, (jstring)env->NewStringUTF(argv[index + 1]));
free(argv[index]);
-
+ }
+ free(argv[argc]);
free(argv);
}
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 this->pimpl_->ppid;
}
+void Actor::suspend()
+{
+ simcall_process_suspend(pimpl_);
+}
+
+void Actor::resume()
+{
+ simcall_process_resume(pimpl_);
+}
+
void Actor::setKillTime(double time) {
simcall_process_set_kill_time(pimpl_,time);
}
{
return SIMIX_process_self()->name;
}
+
+Host* host()
+{
+ return SIMIX_process_self()->host;
+}
+
+void suspend()
+{
+ simcall_process_suspend(SIMIX_process_self());
+}
+
+void resume()
+{
+ simcall_process_resume(SIMIX_process_self());
+}
+
+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");
#define COLL_TAG_GATHERV -2223
#define COLL_TAG_BCAST -3334
#define COLL_TAG_ALLREDUCE -4445
-#define SMPI_RMA_TAG -1234
+//SMPI_RMA_TAG has to be the smallest one, as it will be decremented for accumulate ordering.
+#define SMPI_RMA_TAG -6666
extern XBT_PRIVATE MPI_Comm MPI_COMM_UNINITIALIZED;
(static_cast<simgrid::smpi::Process*>((static_cast<simgrid::MsgActorExt*>(comm->dst_proc->data)->data))->index()));
}
+ XBT_DEBUG("Copying %zu bytes from %p to %p", buff_size, tmpbuff,comm->dst_buff);
memcpy(comm->dst_buff, tmpbuff, buff_size);
if (comm->detached) {
// if this is a detached send, the source buffer was duplicated by SMPI
if(! is_fortran_op_)
this->func_(invec, inoutvec, len, &datatype);
else{
+ XBT_DEBUG("Applying operation of length %d from %p and from/to %p", *len, invec, inoutvec);
int tmp = datatype->c2f();
/* Unfortunately, the C and Fortran version of the MPI standard do not agree on the type here,
thus the reinterpret_cast. */
static int sort_accumulates(MPI_Request a, MPI_Request b)
{
- return (a->tag() < b->tag());
+ return (a->tag() > b->tag());
}
int Request::waitall(int count, MPI_Request requests[], MPI_Status status[])
void* recv_addr = static_cast<void*>(static_cast<char*>(recv_win->base_) + target_disp * recv_win->disp_unit_);
XBT_DEBUG("Entering MPI_Accumulate to %d", target_rank);
- //As the tag will be used for ordering of the operations, add count to it
+ //As the tag will be used for ordering of the operations, substract count from it (to avoid collisions with other SMPI tags, SMPI_RMA_TAG is set below all the other ones we use )
//prepare send_request
+
MPI_Request sreq = Request::rma_send_init(origin_addr, origin_count, origin_datatype,
- smpi_process()->index(), comm_->group()->index(target_rank), SMPI_RMA_TAG+3+count_, comm_, op);
+ smpi_process()->index(), comm_->group()->index(target_rank), SMPI_RMA_TAG-3-count_, comm_, op);
//prepare receiver request
MPI_Request rreq = Request::rma_recv_init(recv_addr, target_count, target_datatype,
- smpi_process()->index(), comm_->group()->index(target_rank), SMPI_RMA_TAG+3+count_, recv_win->comm_, op);
+ smpi_process()->index(), comm_->group()->index(target_rank), SMPI_RMA_TAG-3-count_, recv_win->comm_, op);
count_++;
//push request to receiver's win
#define XDIM 1024
#define YDIM 1024
-#define ITERATIONS 10
+#define ITERATIONS 3
int main(int argc, char **argv)
{