Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
TESH: msg to s4u - act 1
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 24 Mar 2017 16:23:33 +0000 (17:23 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 24 Mar 2017 16:23:33 +0000 (17:23 +0100)
include/simgrid/s4u/Actor.hpp
src/s4u/s4u_actor.cpp
teshsuite/msg/CMakeLists.txt
teshsuite/msg/pid/pid.c [deleted file]
teshsuite/msg/pid/pid.tesh [deleted file]
teshsuite/s4u/pid/pid.cpp [new file with mode: 0644]
teshsuite/s4u/pid/pid.tesh [new file with mode: 0644]
tools/cmake/DefinePackages.cmake

index e57c185..58e1b4b 100644 (file)
@@ -220,6 +220,12 @@ public:
 
   /** If set to true, the actor will automatically restart when its host reboots */
   void setAutoRestart(bool autorestart);
+
+  /** Add a function to the list of "on_exit" functions for the current actor. The on_exit functions are the functions
+   * executed when your actor is killed. You should use them to free the data used by your process.
+   */
+  void onExit(int_f_pvoid_pvoid_t fun, void* data);
+
   /** Sets the time at which that actor should be killed */
   void setKillTime(double time);
   /** Retrieves the time at which that actor will be killed (or -1 if not set) */
@@ -249,6 +255,7 @@ public:
 
   /** Ask kindly to all actors to die. Only the issuer will survive. */
   static void killAll();
+  static void killAll(int resetPid);
 
   /** Returns the internal implementation of this actor */
   simix::ActorImpl* getImpl();
@@ -317,6 +324,9 @@ namespace this_actor {
   /** @brief kill the actor. */
   XBT_PUBLIC(void) kill();
 
+  /** @brief Add a function to the list of "on_exit" functions. */
+  XBT_PUBLIC(void) onExit(int_f_pvoid_pvoid_t fun, void* data);
+
   /** @brief Migrate the actor to a new host. */
   XBT_PUBLIC(void) migrate(Host* new_host);
 };
index 1c171d5..4a3141e 100644 (file)
@@ -52,6 +52,11 @@ void Actor::setAutoRestart(bool autorestart) {
   simcall_process_auto_restart_set(pimpl_,autorestart);
 }
 
+void Actor::onExit(int_f_pvoid_pvoid_t fun, void* data)
+{
+  simcall_process_on_exit(pimpl_, fun, data);
+}
+
 void Actor::migrate(Host* new_host)
 {
   simcall_process_set_host(pimpl_, new_host);
@@ -131,10 +136,16 @@ ActorPtr Actor::byPid(int pid)
     return ActorPtr();
 }
 
-void Actor::killAll() {
+void Actor::killAll()
+{
   simcall_process_killall(1);
 }
 
+void Actor::killAll(int resetPid)
+{
+  simcall_process_killall(resetPid);
+}
+
 // ***** this_actor *****
 
 namespace this_actor {
@@ -209,6 +220,11 @@ void kill()
   simcall_process_kill(SIMIX_process_self());
 }
 
+void onExit(int_f_pvoid_pvoid_t fun, void* data)
+{
+  simcall_process_on_exit(SIMIX_process_self(), fun, data);
+}
+
 void migrate(Host* new_host)
 {
   simcall_process_set_host(SIMIX_process_self(), new_host);
index 24df232..eb33734 100644 (file)
@@ -1,5 +1,5 @@
 # C examples
-foreach(x concurrent_rw get_sender host_on_off host_on_off_recv host_on_off_processes host_on_off_wait listen_async pid
+foreach(x concurrent_rw get_sender host_on_off host_on_off_recv host_on_off_processes host_on_off_wait listen_async
           storage_client_server trace_integration)
   add_executable       (${x}  ${x}/${x}.c)
   target_link_libraries(${x}  simgrid)
@@ -34,7 +34,7 @@ set(xml_files     ${xml_files}     ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration
                                    ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration/test-hbp1-c1s1-c3s2.xml
                                    ${CMAKE_CURRENT_SOURCE_DIR}/trace_integration/test-hbp2.5-hbp1.5.xml    PARENT_SCOPE)
 
-foreach(x concurrent_rw get_sender host_on_off host_on_off_processes host_on_off_recv host_on_off_wait listen_async pid
+foreach(x concurrent_rw get_sender host_on_off host_on_off_processes host_on_off_recv host_on_off_wait listen_async
           process storage_client_server task_destroy_cancel trace_integration)
   ADD_TESH_FACTORIES(tesh-msg-${x} "thread;boost;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x} --cd ${CMAKE_BINARY_DIR}/teshsuite/msg/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x}/${x}.tesh)
 endforeach()
diff --git a/teshsuite/msg/pid/pid.c b/teshsuite/msg/pid/pid.c
deleted file mode 100644 (file)
index ebe6b3a..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/* Copyright (c) 2009-2010, 2013-2015. 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/msg.h"
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
-
-const char* mailbox = "mailbox";
-#define task_comp_size 1000
-#define task_comm_size 100000
-
-static int my_onexit(smx_process_exit_status_t status, int *pid){
-  XBT_INFO("Process \"%d\" killed.", *pid);
-  return 0;
-}
-
-static int sendpid(int argc, char *argv[])
-{
-  int pid = MSG_process_self_PID();
-  MSG_process_on_exit((int_f_pvoid_pvoid_t)my_onexit, &pid);
-  msg_task_t task = MSG_task_create("pid", task_comp_size, task_comm_size, &pid);
-  XBT_INFO("Sending pid of \"%d\".", pid);
-  MSG_task_send(task, mailbox);
-  XBT_INFO("Send of pid \"%d\" done.", pid);
-  MSG_process_suspend(MSG_process_self());
-  return 0;
-}
-
-static int killall(int argc, char *argv[]){
-  msg_task_t task = NULL;
-
-  for (int i=0; i<3;i++) {
-    MSG_task_receive(&(task), mailbox);
-    int pid = *(int*)MSG_task_get_data(task);
-    MSG_task_destroy(task);
-    XBT_INFO("Killing process \"%d\".", pid);
-    MSG_process_kill(MSG_process_from_PID(pid));
-    task = NULL;
-  }
-  return 0;
-}
-
-int main(int argc, char* argv[])
-{
-  MSG_init(&argc, argv);
-
-  xbt_assert(argc >= 2, "Usage: pid platform pid_to_kill");
-
-  MSG_process_killall(atoi(argv[2]));
-
-  MSG_create_environment(argv[1]);
-  MSG_process_create("sendpid", sendpid, NULL, MSG_get_host_by_name("Tremblay"));
-  MSG_process_create("sendpid", sendpid, NULL, MSG_get_host_by_name("Tremblay"));
-  MSG_process_create("sendpid", sendpid, NULL, MSG_get_host_by_name("Tremblay"));
-  MSG_process_create("killall", killall, NULL, MSG_get_host_by_name("Tremblay"));
-
-  return MSG_main() != MSG_OK;
-}
diff --git a/teshsuite/msg/pid/pid.tesh b/teshsuite/msg/pid/pid.tesh
deleted file mode 100644 (file)
index 6752d80..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-$ ./pid ${srcdir:=.}/../../../examples/platforms/small_platform.xml 0 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [  0.000000] (1:sendpid@Tremblay) Sending pid of "1".
-> [  0.000000] (2:sendpid@Tremblay) Sending pid of "2".
-> [  0.000000] (3:sendpid@Tremblay) Sending pid of "3".
-> [  0.000402] (4:killall@Tremblay) Killing process "1".
-> [  0.000402] (1:sendpid@Tremblay) Send of pid "1" done.
-> [  0.000402] (1:sendpid@Tremblay) Process "1" killed.
-> [  0.000804] (2:sendpid@Tremblay) Send of pid "2" done.
-> [  0.000804] (4:killall@Tremblay) Killing process "2".
-> [  0.000804] (2:sendpid@Tremblay) Process "2" killed.
-> [  0.001206] (3:sendpid@Tremblay) Send of pid "3" done.
-> [  0.001206] (4:killall@Tremblay) Killing process "3".
-> [  0.001206] (3:sendpid@Tremblay) Process "3" killed.
-
-$ ./pid ${srcdir:=.}/../../../examples/platforms/small_platform.xml 2 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [  0.000000] (2:sendpid@Tremblay) Sending pid of "2".
-> [  0.000000] (3:sendpid@Tremblay) Sending pid of "3".
-> [  0.000000] (4:sendpid@Tremblay) Sending pid of "4".
-> [  0.000402] (5:killall@Tremblay) Killing process "2".
-> [  0.000402] (2:sendpid@Tremblay) Send of pid "2" done.
-> [  0.000402] (2:sendpid@Tremblay) Process "2" killed.
-> [  0.000804] (3:sendpid@Tremblay) Send of pid "3" done.
-> [  0.000804] (5:killall@Tremblay) Killing process "3".
-> [  0.000804] (3:sendpid@Tremblay) Process "3" killed.
-> [  0.001206] (4:sendpid@Tremblay) Send of pid "4" done.
-> [  0.001206] (5:killall@Tremblay) Killing process "4".
-> [  0.001206] (4:sendpid@Tremblay) Process "4" killed.
diff --git a/teshsuite/s4u/pid/pid.cpp b/teshsuite/s4u/pid/pid.cpp
new file mode 100644 (file)
index 0000000..4b45749
--- /dev/null
@@ -0,0 +1,60 @@
+/* Copyright (c) 2009-2010, 2013-2015. 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"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this msg example");
+
+simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName("mailbox");
+double comp_size                 = 1000;
+double comm_size                 = 100000;
+
+static int my_onexit(smx_process_exit_status_t status, int* pid)
+{
+  XBT_INFO("Process \"%d\" killed.", *pid);
+  return 0;
+}
+
+static void sendpid()
+{
+  int pid = simgrid::s4u::this_actor::pid();
+  simgrid::s4u::this_actor::onExit((int_f_pvoid_pvoid_t)my_onexit, &pid);
+
+  XBT_INFO("Sending pid of \"%d\".", pid);
+  simgrid::s4u::this_actor::send(mailbox, &pid, comm_size);
+  XBT_INFO("Send of pid \"%d\" done.", pid);
+
+  simgrid::s4u::this_actor::suspend();
+}
+
+static void killall()
+{
+  for (int i = 0; i < 3; i++) {
+    int* pid = static_cast<int*>(simgrid::s4u::this_actor::recv(mailbox));
+    XBT_INFO("Killing process \"%d\".", *pid);
+    simgrid::s4u::Actor::byPid(*pid)->kill();
+  }
+}
+
+int main(int argc, char* argv[])
+{
+  simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv);
+  e->loadPlatform(argv[1]);
+
+  if (argc > 2)
+    simgrid::s4u::Actor::killAll(atoi(argv[2]));
+  else
+    simgrid::s4u::Actor::killAll();
+
+  simgrid::s4u::Actor::createActor("sendpid", simgrid::s4u::Host::by_name("Tremblay"), sendpid);
+  simgrid::s4u::Actor::createActor("sendpid", simgrid::s4u::Host::by_name("Tremblay"), sendpid);
+  simgrid::s4u::Actor::createActor("sendpid", simgrid::s4u::Host::by_name("Tremblay"), sendpid);
+  simgrid::s4u::Actor::createActor("killall", simgrid::s4u::Host::by_name("Tremblay"), killall);
+
+  e->run();
+
+  return 0;
+}
diff --git a/teshsuite/s4u/pid/pid.tesh b/teshsuite/s4u/pid/pid.tesh
new file mode 100644 (file)
index 0000000..5826a28
--- /dev/null
@@ -0,0 +1,27 @@
+$ ./pid ${srcdir:=.}/../../../examples/platforms/small_platform.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n"
+> [  0.000000] (sendpid@Tremblay) Sending pid of "1".
+> [  0.000000] (sendpid@Tremblay) Sending pid of "2".
+> [  0.000000] (sendpid@Tremblay) Sending pid of "3".
+> [  0.000402] (killall@Tremblay) Killing process "1".
+> [  0.000402] (sendpid@Tremblay) Send of pid "1" done.
+> [  0.000402] (sendpid@Tremblay) Process "1" killed.
+> [  0.000804] (sendpid@Tremblay) Send of pid "2" done.
+> [  0.000804] (killall@Tremblay) Killing process "2".
+> [  0.000804] (sendpid@Tremblay) Process "2" killed.
+> [  0.001206] (sendpid@Tremblay) Send of pid "3" done.
+> [  0.001206] (killall@Tremblay) Killing process "3".
+> [  0.001206] (sendpid@Tremblay) Process "3" killed.
+
+$ ./pid ${srcdir:=.}/../../../examples/platforms/small_platform.xml 2 "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n"
+> [  0.000000] (sendpid@Tremblay) Sending pid of "2".
+> [  0.000000] (sendpid@Tremblay) Sending pid of "3".
+> [  0.000000] (sendpid@Tremblay) Sending pid of "4".
+> [  0.000402] (killall@Tremblay) Killing process "2".
+> [  0.000402] (sendpid@Tremblay) Send of pid "2" done.
+> [  0.000402] (sendpid@Tremblay) Process "2" killed.
+> [  0.000804] (sendpid@Tremblay) Send of pid "3" done.
+> [  0.000804] (killall@Tremblay) Killing process "3".
+> [  0.000804] (sendpid@Tremblay) Process "3" killed.
+> [  0.001206] (sendpid@Tremblay) Send of pid "4" done.
+> [  0.001206] (killall@Tremblay) Killing process "4".
+> [  0.001206] (sendpid@Tremblay) Process "4" killed.
index eeb58b7..e7ab091 100644 (file)
@@ -972,6 +972,7 @@ set(CMAKEFILES_TXT
   teshsuite/java/CMakeLists.txt
   teshsuite/mc/CMakeLists.txt
   teshsuite/msg/CMakeLists.txt
+  teshsuite/s4u/CMakeLists.txt
   teshsuite/simdag/CMakeLists.txt
   teshsuite/simix/CMakeLists.txt
   teshsuite/smpi/CMakeLists.txt