Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'actor-priority' of https://github.com/Takishipp/simgrid into Takishipp...
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 20 Oct 2017 09:05:42 +0000 (11:05 +0200)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 20 Oct 2017 09:05:42 +0000 (11:05 +0200)
examples/s4u/CMakeLists.txt
examples/s4u/README.doc
examples/s4u/actor-priority/s4u-actor-priority.cpp [new file with mode: 0644]
examples/s4u/actor-priority/s4u-actor-priority.tesh [new file with mode: 0644]
examples/s4u/actor-priority/s4u-actor-priority_d.xml [new file with mode: 0644]
include/simgrid/s4u/Actor.hpp
src/s4u/s4u_actor.cpp

index 669aba8..5a9d1cc 100644 (file)
@@ -1,5 +1,6 @@
 foreach (example actions-comm actions-storage 
-                 actor-create actor-daemon actor-execute actor-kill actor-lifetime actor-migration actor-suspend 
+                 actor-create actor-daemon actor-kill actor-migration actor-suspend
+                 actor-create actor-daemon actor-execute actor-kill actor-lifetime actor-migration actor-suspend actor-priority
                  app-masterworker app-pingpong app-token-ring
                 async-wait async-waitany async-waitall
                 plugin-hostload io mutex)
@@ -32,6 +33,7 @@ endforeach()
 set(examples_src  ${examples_src}                                                                          PARENT_SCOPE)
 set(tesh_files    ${tesh_files}   ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/s4u-app-bittorrent.tesh
                                   ${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord.tesh
+                                  ${CMAKE_CURRENT_SOURCE_DIR}/actor-priority/s4u-actor-priority.tesh
                                   ${CMAKE_CURRENT_SOURCE_DIR}/actor-lifetime/s4u-actor-lifetime.tesh
                                   ${CMAKE_CURRENT_SOURCE_DIR}/async-wait/s4u-async-wait.tesh
                                   ${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/s4u-async-waitany.tesh
@@ -42,6 +44,7 @@ set(xml_files     ${xml_files}    ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-a
                                   ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-actions-comm_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/actions-storage/s4u-actions-storage_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/actor-create/s4u-actor-create_d.xml
+                                  ${CMAKE_CURRENT_SOURCE_DIR}/actor-priority/s4u-actor-priority_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/s4u-app-bittorrent_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/app-masterworker/s4u-app-masterworker_d.xml
                                   ${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/s4u-async-waitany_d.xml
@@ -59,7 +62,7 @@ set(txt_files     ${txt_files}    ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-a
 foreach(example actions-comm actions-storage 
                 actor-create actor-daemon actor-execute actor-kill actor-lifetime actor-migration actor-suspend
                 app-bittorrent app-masterworker app-pingpong app-token-ring 
-               async-wait async-waitall async-waitany
+               async-wait async-waitall async-waitany actor-priority
                dht-chord plugin-hostload io mutex)
   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 a3763fb..96691c5 100644 (file)
@@ -82,6 +82,11 @@ documentation, but it should remain readable directly.
     Actors can be suspended and resumed during their executions
     thanks to the @ref suspend and @ref resume methods.
 
+    - <b>Priority actors</b>.
+    @ref examples/s4u/actor-priority/s4u-actor-priority.cpp \n
+    Actors can be launched according their priorities thanks to the @ref
+     execution method.
+
   - <b>Kill actors</b>.
     @ref examples/s4u/actor-kill/s4u-actor-kill.cpp \n
     Actors can forcefully stop other actors with the @ref kill method.
diff --git a/examples/s4u/actor-priority/s4u-actor-priority.cpp b/examples/s4u/actor-priority/s4u-actor-priority.cpp
new file mode 100644 (file)
index 0000000..1564f7e
--- /dev/null
@@ -0,0 +1,45 @@
+/* Copyright (c) 2007-2016. 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 <cstdlib>
+#include <iostream>
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
+
+class test {
+  double computation_amount;
+  double priority;
+
+public:
+  explicit test(std::vector<std::string> args)
+{
+  computation_amount = std::stod(args[1]);
+  priority = std::stod(args[2]);
+}
+void operator()()
+{
+  XBT_INFO("Hello! Running an actor of size %g with priority %g", computation_amount, priority);
+  simgrid::s4u::this_actor::execute(computation_amount, priority);
+
+  XBT_INFO("Goodbye now!");
+}
+};
+
+int main(int argc, char *argv[])
+{
+  simgrid::s4u::Engine e(&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]);
+  
+  e.registerFunction<test>("test");
+
+  e.loadPlatform(argv[1]);
+  e.loadDeployment(argv[2]);
+
+  e.run();
+
+  return 0;
+}
diff --git a/examples/s4u/actor-priority/s4u-actor-priority.tesh b/examples/s4u/actor-priority/s4u-actor-priority.tesh
new file mode 100644 (file)
index 0000000..82916b3
--- /dev/null
@@ -0,0 +1,8 @@
+#! ./tesh
+
+! output sort 19
+$ $SG_TEST_EXENV ${bindir:=.}/s4u-actor-priority$EXEEXT ${srcdir:=.}/small_platform.xml  ${srcdir:=.}/../s4u/actor-priority/s4u-actor-priority_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [  0.000000] (1:test@Fafard) Hello! Running an actor of size 7.6296e+07 with priority 1
+> [  0.000000] (2:test@Fafard) Hello! Running an actor of size 7.6296e+07 with priority 2
+> [  1.500000] (2:test@Fafard) Goodbye now!
+> [  2.000000] (1:test@Fafard) Goodbye now!
diff --git a/examples/s4u/actor-priority/s4u-actor-priority_d.xml b/examples/s4u/actor-priority/s4u-actor-priority_d.xml
new file mode 100644 (file)
index 0000000..5d15f2b
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
+<platform version="4.1">
+  <actor host="Fafard" function="test">
+    <argument value="76296000"/>
+    <argument value="1.0"/>
+  </actor>
+  <actor host="Fafard" function="test">
+    <argument value="76296000"/>
+    <argument value="2.0"/>
+  </actor>
+</platform>
index c17b7a3..f964483 100644 (file)
@@ -302,6 +302,8 @@ XBT_ATTRIB_DEPRECATED_v320("Use sleep_for(): v3.20 will turn this warning into a
 
 /** Block the actor, computing the given amount of flops */
 XBT_PUBLIC(void) execute(double flop);
+/** Block the actor, computing the given amount of flops and priority */
+XBT_PUBLIC(void) execute(double flop, double priority);
 
 /** Block the actor until it gets a message from the given mailbox.
  *
index 80f0c11..1553bb9 100644 (file)
@@ -227,6 +227,12 @@ void execute(double flops)
   simcall_execution_wait(s);
 }
 
+void execute(double flops,double priority)
+{
+  smx_activity_t s = simcall_execution_start(nullptr,flops,1 / priority/*priority*/,0./*bound*/);
+  simcall_execution_wait(s);
+}
+
 void* recv(MailboxPtr chan) // deprecated
 {
   return chan->get();