Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New example for MSG_process_yield()
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 26 Jan 2017 21:41:36 +0000 (22:41 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Thu, 26 Jan 2017 21:41:36 +0000 (22:41 +0100)
.gitignore
examples/msg/CMakeLists.txt
examples/msg/async-yield/async-yield.c [new file with mode: 0644]
examples/msg/async-yield/async-yield.tesh [new file with mode: 0644]
examples/msg/async-yield/async-yield_d.xml [new file with mode: 0644]

index d353406..9b56f91 100644 (file)
@@ -121,6 +121,7 @@ doc/msg-tuto-src/masterworker3
 doc/msg-tuto-src/masterworker4
 examples/msg/actions-comm/actions-comm
 examples/msg/actions-storage/actions-storage
+examples/msg/async-yield/async-yield
 examples/msg/async-wait/async-wait
 examples/msg/async-waitall/async-waitall
 examples/msg/async-waitany/async-waitany
index 5fa4f26..a427f2d 100644 (file)
@@ -1,5 +1,5 @@
 # C examples
-foreach(x actions-comm actions-storage app-masterworker app-pingpong app-pmm app-token-ring async-wait async-waitall 
+foreach(x actions-comm actions-storage app-masterworker app-pingpong app-pmm app-token-ring async-yield async-wait async-waitall 
           async-waitany cloud-capping cloud-masterworker cloud-migration cloud-simple cloud-two-tasks
           dht-chord dht-pastry energy-consumption energy-onoff energy-pstate energy-ptask energy-vm platform-failures 
           io-file io-remote io-storage task-priority process-create process-kill process-migration process-suspend 
@@ -49,7 +49,7 @@ foreach (file answer dht-kademlia node routing_table task)
   set(examples_src  ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/${file}.c  ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/${file}.h)
 endforeach()
 
-foreach (file actions-comm actions-storage app-bittorrent app-chainsend app-masterworker app-pingpong async-wait
+foreach (file actions-comm actions-storage app-bittorrent app-chainsend app-masterworker app-pingpong async-yield async-wait
          async-waitall async-waitany dht-chord dht-kademlia io-remote platform-properties
          task-priority)
   set(xml_files    ${xml_files}     ${CMAKE_CURRENT_SOURCE_DIR}/${file}/${file}_d.xml)
@@ -94,7 +94,7 @@ set(xml_files    ${xml_files}     ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/actio
                                   ${CMAKE_CURRENT_SOURCE_DIR}/process-startkilltime/start_kill_d.xml       PARENT_SCOPE)
 
 foreach(x actions-comm actions-storage app-bittorrent app-chainsend app-masterworker app-pingpong app-token-ring
-          async-wait async-waitall async-waitany cloud-capping cloud-masterworker cloud-migration cloud-simple 
+          async-yield async-wait async-waitall async-waitany cloud-capping cloud-masterworker cloud-migration cloud-simple 
           cloud-two-tasks dht-chord dht-pastry dht-kademlia platform-failures io-file io-remote io-storage task-priority 
           process-create process-kill process-migration process-suspend platform-properties synchro-semaphore 
           process-startkilltime)
diff --git a/examples/msg/async-yield/async-yield.c b/examples/msg/async-yield/async-yield.c
new file mode 100644 (file)
index 0000000..ada22e3
--- /dev/null
@@ -0,0 +1,46 @@
+/* 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/msg.h"
+
+/* This example does not much: It just spans over-polite processes that yield a large amount
+ * of time before ending.
+ *
+ * This serves as an example for the MSG_process_yield() function, with which a process can request
+ * to be rescheduled after the other processes that are ready at the current timestamp.
+ *
+ * It can also be used to benchmark our context-switching mechanism.
+ */
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_async_yield, "Messages specific for this msg example");
+
+/* Main function of the Yielder process */
+static int yielder(int argc, char* argv[])
+{
+  xbt_assert(argc == 2, "The sender function expects 1 arguments from the XML deployment file");
+  long number_of_yields = xbt_str_parse_int(argv[1], "Invalid amount of yields: %s"); /* - number of yields */
+
+  for (int i = 0; i < number_of_yields; i++)
+    MSG_process_yield();
+  XBT_INFO("I yielded %ld times. Goodbye now!", number_of_yields);
+  return 0;
+}
+
+int main(int argc, char* argv[])
+{
+  MSG_init(&argc, argv);
+  xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
+                       "\tExample: %s msg_platform.xml msg_deployment.xml\n",
+             argv[0], argv[0]);
+
+  MSG_create_environment(argv[1]); /* - Load the platform description */
+
+  MSG_function_register("yielder", yielder);
+  MSG_launch_application(argv[2]); /* - Deploy the sender and receiver processes */
+
+  msg_error_t res = MSG_main(); /* - Run the simulation */
+
+  return res != MSG_OK;
+}
diff --git a/examples/msg/async-yield/async-yield.tesh b/examples/msg/async-yield/async-yield.tesh
new file mode 100644 (file)
index 0000000..e5aef16
--- /dev/null
@@ -0,0 +1,5 @@
+#! ./tesh
+
+$ $SG_TEST_EXENV ${bindir:=.}/async-yield ${srcdir:=.}/small_platform_fatpipe.xml ${srcdir:=.}/../msg/async-yield/async-yield_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (1:yielder@Tremblay) I yielded 10 times. Goodbye now!
+> [  0.000000] (2:yielder@Ruby) I yielded 15 times. Goodbye now!
diff --git a/examples/msg/async-yield/async-yield_d.xml b/examples/msg/async-yield/async-yield_d.xml
new file mode 100644 (file)
index 0000000..0b1b17a
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
+<platform version="4">
+  <process host="Tremblay" function="yielder">
+    <argument value="10"/>       <!-- Number of yields to do  -->
+  </process>
+  <process host="Ruby" function="yielder">
+    <argument value="15"/>       <!-- Number of yields to do  -->
+  </process>
+</platform>