Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
python: First working example
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Wed, 26 Dec 2018 23:46:44 +0000 (00:46 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 27 Dec 2018 00:14:21 +0000 (01:14 +0100)
docs/source/img/lang_cpp.png [new file with mode: 0644]
docs/source/img/lang_python.png [new file with mode: 0644]
examples/python/CMakeLists.txt [new file with mode: 0644]
examples/python/exec-basic/exec-basic.py [new file with mode: 0644]
examples/python/exec-basic/exec-basic.tesh [new file with mode: 0644]
examples/s4u/README.rst
src/bindings/python/simgrid_python.cpp
tools/cmake/DefinePackages.cmake

diff --git a/docs/source/img/lang_cpp.png b/docs/source/img/lang_cpp.png
new file mode 100644 (file)
index 0000000..ad7a89a
Binary files /dev/null and b/docs/source/img/lang_cpp.png differ
diff --git a/docs/source/img/lang_python.png b/docs/source/img/lang_python.png
new file mode 100644 (file)
index 0000000..585bc0d
Binary files /dev/null and b/docs/source/img/lang_python.png differ
diff --git a/examples/python/CMakeLists.txt b/examples/python/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e38a65f
--- /dev/null
@@ -0,0 +1,10 @@
+foreach(example exec-basic)
+  set(tesh_files    ${tesh_files}   ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.tesh)
+  set(examples_src  ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.py)
+
+  ADD_TESH(python-${example} --setenv srcdir=${example}
+                             --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms
+                            --setenv LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib
+                            --setenv PYTHONPATH=${CMAKE_BINARY_DIR}/lib
+                             ${CMAKE_HOME_DIRECTORY}/examples/python/${example}/${example}.tesh)
+endforeach()
\ No newline at end of file
diff --git a/examples/python/exec-basic/exec-basic.py b/examples/python/exec-basic/exec-basic.py
new file mode 100644 (file)
index 0000000..0d60965
--- /dev/null
@@ -0,0 +1,39 @@
+# Copyright (c) 2018. 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.
+
+import sys
+import simgrid as sg
+
+def executor():
+    # execute() tells SimGrid to pause the calling actor until 
+    # its host has computed the amount of flops passed as a parameter
+    sg.execute(98095)
+    sg.info("Done.")
+    # This simple example does not do anything beyond that
+
+def privileged():
+    #  This version of execute() with two parameters specifies that this execution
+    # gets a larger share of the resource.
+    #
+    # Since the priority is 2, it computes twice as fast as a regular one.
+    #
+    # So instead of a half/half sharing between the two executions,
+    # we get a 1/3 vs 2/3 sharing. 
+    sg.execute(98095, 2);
+    sg.info("Done.");
+
+    # Note that the timings printed when executing this example are a bit misleading,
+    # because the uneven sharing only last until the privileged actor ends.
+    # After this point, the unprivileged one gets 100% of the CPU and finishes
+    # quite quickly.
+
+i = sys.argv.index("--")
+e = sg.Engine(sys.argv[0:i])
+e.load_platform(sys.argv[i+1])
+
+sg.create_actor("executor", sg.Host.by_name("Tremblay"), executor)
+sg.create_actor("privileged", sg.Host.by_name("Tremblay"), privileged)
+
+e.run()
\ No newline at end of file
diff --git a/examples/python/exec-basic/exec-basic.tesh b/examples/python/exec-basic/exec-basic.tesh
new file mode 100644 (file)
index 0000000..07e77b9
--- /dev/null
@@ -0,0 +1,6 @@
+#!/usr/bin/env tesh
+
+p Start remote processes 
+$ python3 ${srcdir}/exec-basic.py -- ${platfdir}/small_platform.xml 
+> [Tremblay:privileged:(2) 0.001500] [python/INFO] Done.
+> [Tremblay:executor:(1) 0.002000] [python/INFO] Done.
index b1b996d..e730f21 100644 (file)
@@ -16,8 +16,8 @@ SimGrid comes with an extensive set of examples, documented on this
 page. Most of them only demonstrate one single feature, with some
 larger examplars listed below. 
 
 page. Most of them only demonstrate one single feature, with some
 larger examplars listed below. 
 
-Each of these examples can be found in a subdirectory under
-examples/s4u in the archive. It contains the source code (also listed
+The C++ examples can be found under examples/s4u while python examples
+are in examples/python. Each such directory contains the source code (also listed
 from this page), and the so-called tesh file containing how to call
 the binary obtained by compiling this example and also the expected
 output. Tesh files are used to turn each of our examples into an
 from this page), and the so-called tesh file containing how to call
 the binary obtained by compiling this example and also the expected
 output. Tesh files are used to turn each of our examples into an
@@ -151,7 +151,8 @@ Executions on the CPU
     the actor until a given amount of flops gets computed on its simulated
     host. Some executions can be given an higher priority so that they
     get more resources.
     the actor until a given amount of flops gets computed on its simulated
     host. Some executions can be given an higher priority so that they
     get more resources.
-    |br| `examples/s4u/exec-basic/s4u-exec-basic.cpp <https://framagit.org/simgrid/simgrid/tree/master/examples/s4u/exec-basic/s4u-exec-basic.cpp>`_
+    |br| |cpp| `examples/s4u/exec-basic/s4u-exec-basic.cpp <https://framagit.org/simgrid/simgrid/tree/master/examples/s4u/exec-basic/s4u-exec-basic.cpp>`_
+    |br|  |py| `examples/python/exec-basic/exec-basic.py <https://framagit.org/simgrid/simgrid/tree/master/examples/python/exec-basic/exec-basic.py>`_
 
   - **Asynchronous execution:**
     You can start asynchronous executions, just like you would fire
 
   - **Asynchronous execution:**
     You can start asynchronous executions, just like you would fire
@@ -340,3 +341,11 @@ Distributed Hash Tables (DHT)
 .. |br| raw:: html
 
    <br />
 .. |br| raw:: html
 
    <br />
+
+.. |cpp| image:: /img/lang_cpp.png
+   :align: middle
+   :width: 12
+
+.. |py| image:: /img/lang_python.png
+   :align: middle
+   :width: 12
index aace9c9..4a9fd87 100644 (file)
@@ -23,7 +23,7 @@ using simgrid::s4u::ActorPtr;
 using simgrid::s4u::Engine;
 using simgrid::s4u::Host;
 
 using simgrid::s4u::Engine;
 using simgrid::s4u::Host;
 
-XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_python, "S4U python");
+XBT_LOG_NEW_DEFAULT_CATEGORY(python, "python");
 
 PYBIND11_DECLARE_HOLDER_TYPE(T, boost::intrusive_ptr<T>);
 
 
 PYBIND11_DECLARE_HOLDER_TYPE(T, boost::intrusive_ptr<T>);
 
@@ -52,6 +52,8 @@ PYBIND11_MODULE(simgrid, m)
   /* this_actor namespace */
   m.def("execute", py::overload_cast<double>(&simgrid::s4u::this_actor::execute),
         "Block the actor, computing the given amount of flops");
   /* this_actor namespace */
   m.def("execute", py::overload_cast<double>(&simgrid::s4u::this_actor::execute),
         "Block the actor, computing the given amount of flops");
+  m.def("execute", py::overload_cast<double, double>(&simgrid::s4u::this_actor::execute),
+        "Block the actor, computing the given amount of flops at the given priority");
   m.def("yield_", &simgrid::s4u::this_actor::yield, "Yield the actor");
 
   /* Class Engine */
   m.def("yield_", &simgrid::s4u::this_actor::yield, "Yield the actor");
 
   /* Class Engine */
index e05bf0f..39c8d01 100644 (file)
@@ -905,6 +905,8 @@ set(DOC_SOURCES
   docs/source/img/extlink.png
   docs/source/img/extlink.svg
   docs/source/img/graphical-toc.svg
   docs/source/img/extlink.png
   docs/source/img/extlink.svg
   docs/source/img/graphical-toc.svg
+  source/img/lang_cpp.png
+  source/img/lang_python.png
   docs/source/img/smpi_simgrid_alltoall_pair_16.png
   docs/source/img/smpi_simgrid_alltoall_ring_16.png
   docs/source/img/zone_hierarchy.png
   docs/source/img/smpi_simgrid_alltoall_pair_16.png
   docs/source/img/smpi_simgrid_alltoall_ring_16.png
   docs/source/img/zone_hierarchy.png
@@ -1008,6 +1010,7 @@ set(CMAKEFILES_TXT
   examples/java/CMakeLists.txt
   examples/msg/CMakeLists.txt
     examples/msg/mc/CMakeLists.txt
   examples/java/CMakeLists.txt
   examples/msg/CMakeLists.txt
     examples/msg/mc/CMakeLists.txt
+  examples/python/CMakeLists.txt
   examples/s4u/CMakeLists.txt
   examples/simdag/CMakeLists.txt
   examples/smpi/CMakeLists.txt
   examples/s4u/CMakeLists.txt
   examples/simdag/CMakeLists.txt
   examples/smpi/CMakeLists.txt