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>
Tue, 21 Mar 2017 13:33:40 +0000 (14:33 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 21 Mar 2017 13:33:40 +0000 (14:33 +0100)
20 files changed:
.gitignore
examples/s4u/CMakeLists.txt
examples/s4u/README.doc
examples/s4u/actions-comm/s4u_actions-comm.cpp
examples/s4u/actions-storage/s4u_actions-storage.cpp
examples/s4u/actor-migration/s4u_actor-migration.cpp [new file with mode: 0644]
examples/s4u/actor-migration/s4u_actor-migration.tesh [new file with mode: 0644]
examples/s4u/app-masterworker/s4u_app-masterworker.cpp
include/simgrid/s4u/Actor.hpp
include/simgrid/s4u/conditionVariable.hpp
src/bindings/java/jmsg.cpp
src/s4u/s4u_actor.cpp
src/s4u/s4u_conditionVariable.cpp
src/simix/ActorImpl.cpp
src/smpi/private.h
src/smpi/smpi_global.cpp
src/smpi/smpi_op.cpp
src/smpi/smpi_request.cpp
src/smpi/smpi_win.cpp
teshsuite/smpi/mpich3-test/rma/strided_acc_onelock.c

index feeb1ee..9c402a9 100644 (file)
@@ -190,6 +190,7 @@ examples/msg/trace-host-user-variables/trace-host-user-variables
 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
index 13d30b0..9c6c9b0 100644 (file)
@@ -1,4 +1,4 @@
-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})
@@ -20,6 +20,6 @@ set(txt_files     ${txt_files}    ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u_a
                                   ${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()
index 9cdcf7a..6ecf35c 100644 (file)
@@ -14,7 +14,9 @@ documentation, but it should remain readable directly.
  @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
 
@@ -26,23 +28,60 @@ documentation, but it should remain readable directly.
     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
index 1cbdbfb..44b42d1 100644 (file)
@@ -104,7 +104,6 @@ int main(int argc, char *argv[])
   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);
   }
index 0c10ded..21f9e13 100644 (file)
@@ -120,7 +120,6 @@ int main(int argc, char* argv[])
   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);
   }
diff --git a/examples/s4u/actor-migration/s4u_actor-migration.cpp b/examples/s4u/actor-migration/s4u_actor-migration.cpp
new file mode 100644 (file)
index 0000000..5db96c6
--- /dev/null
@@ -0,0 +1,76 @@
+/* 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;
+}
diff --git a/examples/s4u/actor-migration/s4u_actor-migration.tesh b/examples/s4u/actor-migration/s4u_actor-migration.tesh
new file mode 100644 (file)
index 0000000..19b9f97
--- /dev/null
@@ -0,0 +1,14 @@
+#! ./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
index 69539ae..bc5d34a 100644 (file)
@@ -78,7 +78,7 @@ public:
         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);
     }
index b5047d9..9e34530 100644 (file)
@@ -134,7 +134,6 @@ namespace s4u {
 /** @brief Simulation Agent */
 XBT_PUBLIC_CLASS Actor : public simgrid::xbt::Extendable<Actor>
 {
-
   friend Mailbox;
   friend simgrid::simix::ActorImpl;
   friend simgrid::kernel::activity::MailboxImpl;
@@ -213,6 +212,12 @@ public:
   /** 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 */
@@ -220,6 +225,7 @@ public:
   /** 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).
@@ -298,6 +304,18 @@ namespace this_actor {
 
   /** @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);
 };
 
 /** @} */
index d3e777e..47451e6 100644 (file)
@@ -48,6 +48,7 @@ public:
 
   //  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)
index b6c1701..7ffbb23 100644 (file)
@@ -115,7 +115,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, j
   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);
@@ -134,9 +134,11 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, j
   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);
 }
 
index abc984a..16479c0 100644 (file)
@@ -52,6 +52,11 @@ void Actor::setAutoRestart(bool autorestart) {
   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;
@@ -77,6 +82,16 @@ int Actor::ppid()
   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);
 }
@@ -173,6 +188,26 @@ std::string name()
 {
   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);
+}
 }
 }
 }
index 3074f12..be528ba 100644 (file)
@@ -20,6 +20,11 @@ ConditionVariablePtr ConditionVariable::createConditionVariable()
 /**
  * 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_);
 }
index 502ffea..bcce486 100644 (file)
@@ -553,6 +553,7 @@ void simcall_HANDLER_process_set_host(smx_simcall_t simcall, smx_actor_t process
 {
   process->new_host = dest;
 }
+
 void SIMIX_process_change_host(smx_actor_t process, sg_host_t dest)
 {
   xbt_assert((process != nullptr), "Invalid parameters");
index 8d23af3..2ddc806 100644 (file)
@@ -62,7 +62,8 @@ enum smpi_process_state{
 #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;
 
index 8459d4e..db497bf 100644 (file)
@@ -127,6 +127,7 @@ void smpi_comm_copy_buffer_callback(smx_activity_t synchro, void *buff, size_t b
            (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
index 22ac499..96dd941 100644 (file)
@@ -241,6 +241,7 @@ void Op::apply(void *invec, void *inoutvec, int *len, MPI_Datatype datatype)
     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. */
index 397a8cc..aa1bf22 100644 (file)
@@ -876,7 +876,7 @@ int Request::waitany(int count, MPI_Request requests[], MPI_Status * status)
 
 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[])
index b522dcf..5f81998 100644 (file)
@@ -273,14 +273,15 @@ int Win::accumulate( void *origin_addr, int origin_count, MPI_Datatype origin_da
 
   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
index 529d628..dc78e21 100644 (file)
@@ -21,7 +21,7 @@
 
 #define XDIM 1024
 #define YDIM 1024
-#define ITERATIONS 10
+#define ITERATIONS 3
 
 int main(int argc, char **argv)
 {