Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of github.com:simgrid/simgrid
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 27 Dec 2018 09:27:51 +0000 (10:27 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Thu, 27 Dec 2018 09:27:51 +0000 (10:27 +0100)
36 files changed:
.gitignore
.travis.yml
CMakeLists.txt
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
include/simgrid/Exception.hpp
include/simgrid/kernel/routing/ClusterZone.hpp
include/simgrid/kernel/routing/NetZoneImpl.hpp
include/simgrid/kernel/routing/VivaldiZone.hpp
include/simgrid/s4u.hpp
include/simgrid/s4u/Actor.hpp
include/simgrid/s4u/ConditionVariable.hpp
include/simgrid/s4u/Engine.hpp
include/simgrid/s4u/Host.hpp
include/simgrid/s4u/Mailbox.hpp
include/simgrid/s4u/Mutex.hpp
include/simgrid/s4u/NetZone.hpp
include/simgrid/s4u/Storage.hpp
include/simgrid/s4u/VirtualMachine.hpp
src/bindings/java/jxbt_utilities.hpp
src/bindings/lua/lua_host.cpp
src/bindings/python/simgrid_python.cpp [new file with mode: 0644]
src/kernel/routing/RoutedZone.cpp
src/plugins/vm/s4u_VirtualMachine.cpp
src/s4u/s4u_Engine.cpp
src/s4u/s4u_Host.cpp
src/simix/libsmx.cpp
src/surf/HostImpl.cpp
src/surf/ns3/ns3_simulator.cpp
src/surf/sg_platf.cpp
tools/cmake/DefinePackages.cmake
tools/docker/Dockerfile.build-deps

index f1d7590..5af3b34 100644 (file)
 *.class
 .cproject # Eclipse cruft
 CMakeLists.txt.user
+CMakeDoxyfile.in
+CMakeDoxygenDefaults.cmake
 \#*
 .attach_pid*
 .cproject
 smpitmp-*
+simgrid.pc
+__pycache__/
 
 ### cmake
 CTestCustom.cmake
@@ -275,6 +279,7 @@ teshsuite/s4u/actor-autorestart/actor-autorestart
 teshsuite/s4u/actor-migration/actor-migration
 teshsuite/s4u/activity-lifecycle/activity-lifecycle
 teshsuite/s4u/cloud-interrupt-migration/cloud-interrupt-migration
+teshsuite/s4u/cloud-sharing/cloud-sharing
 teshsuite/s4u/comm-pt2pt/comm-pt2pt
 teshsuite/s4u/concurrent_rw/concurrent_rw
 teshsuite/s4u/listen_async/listen_async
@@ -942,6 +947,7 @@ unit-tmgr
 #########################################
 ## files touched to track the dependencies of java examples
 examples/java/*/*/*_compiled
+examples/java/*/*_compiled
 /CMakeCache.txt
 simgrid.jar_finalized
 simgrid_full.jar
index 2c17bb8..3c814f5 100644 (file)
@@ -27,6 +27,7 @@ addons:
     - libdw-dev
     - libevent-dev
     - libunwind8-dev
+    - pybind11-dev
   homebrew:
     packages:
     - python
index 3d9417b..02a0859 100644 (file)
@@ -139,7 +139,7 @@ set(PythonInterp_FIND_VERSION_COUNT 1)
 set(PythonInterp_FIND_VERSION_MAJOR 3)
 include(FindPythonInterp)
 if(NOT PYTHONINTERP_FOUND)
-  message(FATAL_ERROR "Please install Python (version 3 or higher).")
+  message(FATAL_ERROR "Please install Python (version 3 or higher) to compile SimGrid.")
 endif()
 
 SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)
@@ -254,7 +254,7 @@ else()
   endif()
 endif()
 
-# cmake up to 3.12.3 (at least) does not know about stacktrace components. Inform it.
+# cmake before 3.13.1 does not know about stacktrace components. Fix it.
 # Usable components: https://www.boost.org/doc/libs/1_65_1/doc/html/stacktrace/configuration_and_build.html
 set(_Boost_STACKTRACE_HEADERS           "boost/stacktrace.hpp")
 set(_Boost_STACKTRACE_BACKTRACE_HEADERS "boost/stacktrace.hpp")
@@ -847,6 +847,23 @@ if(enable_java)
   include(${CMAKE_HOME_DIRECTORY}/tools/cmake/Java.cmake)
 endif()
 
+# Python binding, generated with pybind11
+set(PYBIND11_CPP_STANDARD -std=c++11)
+find_package(pybind11)
+option(enable_python "Whether the Python bindings are activated." ${pybind11_FOUND}) # ON by default if dependencies are met
+
+if(enable_python)
+  if(pybind11_FOUND)
+    pybind11_add_module(simgrid_python src/bindings/python/simgrid_python.cpp)
+    set_source_files_properties(src/bindings/python/simgrid_python.cpp PROPERTIES COMPILE_FLAGS -Wno-attributes)
+    set_source_files_properties(src/bindings/python/simgrid_python.cpp PROPERTIES COMPILE_FLAGS -std=gnu++14)
+    target_link_libraries(simgrid_python PUBLIC simgrid)
+    set_target_properties(simgrid_python PROPERTIES LIBRARY_OUTPUT_NAME simgrid)
+  else()
+    message(FATAL_ERROR "Please install pybind11-dev to build the Python bindings (or disable that option).")
+  endif()
+endif()
+
 ### Make tests
 if(enable_memcheck_xml)
   set(enable_memcheck true)
@@ -938,6 +955,12 @@ if (${Java_FOUND})
 else()
   message("        Compile Java ................: NO")
 endif()
+if(pybind11_FOUND)
+  message("        Compile Python bindings .....: ${enable_python}")
+  message("          module ....................: ${PYTHON_MODULE_PREFIX}simgrid${PYTHON_MODULE_EXTENSION}")
+else()
+  message("        Compile Python bindings .....: NO (disabled, or pybind11 not found)")
+endif()
 message("        Compile Lua .................: ${SIMGRID_HAVE_LUA}")
 message("        Compile Smpi ................: ${HAVE_SMPI}")
 message("          Smpi fortran ..............: ${SMPI_FORTRAN}")
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..0112160
--- /dev/null
@@ -0,0 +1,15 @@
+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)
+
+  if(enable_python)
+    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)
+  endif()
+endforeach()
+
+set(tesh_files    ${tesh_files}    PARENT_SCOPE)
+set(examples_src  ${examples_src}  PARENT_SCOPE)
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. 
 
-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
@@ -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.
-    |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
@@ -340,3 +341,11 @@ Distributed Hash Tables (DHT)
 .. |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 a259e2b..ff59edf 100644 (file)
@@ -115,7 +115,7 @@ public:
   }
 };
 
-/** Exception raised when an host fails */
+/** Exception raised when a host fails */
 class HostFailureException : public xbt_ex {
 public:
   HostFailureException(simgrid::xbt::ThrowPoint throwpoint, std::string message) : xbt_ex(throwpoint, message)
index 167b2c1..4f6878e 100644 (file)
@@ -52,7 +52,7 @@ namespace routing {
  * host0 host1 host2
  * \endverbatim
 
- *  So, a communication from an host A to an host B goes through the following links (if they exist):
+ *  So, a communication from a host A to a host B goes through the following links (if they exist):
  *   <tt>limiter(A)_UP, private(A)_UP, backbone, private(B)_DOWN, limiter(B)_DOWN.</tt>
  *  link_UP and link_DOWN usually share the exact same characteristics, but their
  *  performance are not shared, to model the fact that TCP links are full-duplex.
@@ -60,7 +60,7 @@ namespace routing {
  *  A cluster is connected to the outer world through a router that is connected
  *  directly to the cluster's backbone (no private link).
  *
- *  A communication from an host A to the outer world goes through the following links:
+ *  A communication from a host A to the outer world goes through the following links:
  *   <tt>limiter(A)_UP, private(A)_UP, backbone</tt>
  *  (because the private router is directly connected to the cluster core).
  */
index 260661c..8b24af2 100644 (file)
@@ -57,7 +57,7 @@ protected:
 public:
   s4u::NetZone* get_iface() { return &piface_; }
 
-  /** @brief Make an host within that NetZone */
+  /** @brief Make a host within that NetZone */
   simgrid::s4u::Host* create_host(const char* name, std::vector<double>* speed_per_pstate, int core_count,
                                   std::map<std::string, std::string>* props);
   /** @brief Creates a new route in this NetZone */
index 820ff10..ecbe718 100644 (file)
@@ -29,7 +29,7 @@ namespace routing {
  *
  *  The resulting value is assumed to be in milliseconds.
  *
- *  So, to go from an host A to an host B, the following links would be used:
+ *  So, to go from a host A to a host B, the following links would be used:
  *  <tt>private(A)_UP, private(B)_DOWN</tt>, with the additional latency computed above.
  *  The bandwidth of the UP and DOWN links is not symmetric (in contrary to usual SimGrid
  *  links), but naturally correspond to the values provided when the peer was created.
index d3182a5..0bc419c 100644 (file)
@@ -20,6 +20,7 @@
 #include <simgrid/s4u/NetZone.hpp>
 #include <simgrid/s4u/Semaphore.hpp>
 #include <simgrid/s4u/Storage.hpp>
+#include <simgrid/s4u/VirtualMachine.hpp>
 
 #include <simgrid/Exception.hpp>
 
index 4013808..3167cfd 100644 (file)
@@ -229,7 +229,7 @@ public:
    * executed when your actor is killed. You should use them to free the data used by your actor.
    *
    * Please note that functions registered in this signal cannot do any simcall themselves. It means that they cannot
-   * send or receive messages, acquire or release mutexes, nor even modify an host property or something. Not only are
+   * send or receive messages, acquire or release mutexes, nor even modify a host property or something. Not only are
    * blocking functions forbidden in this setting, but also modifications to the global state.
    */
   void on_exit(std::function<void(int, void*)> fun, void* data);
@@ -502,7 +502,7 @@ XBT_PUBLIC Host* get_host();
 /** @brief Suspend the actor. */
 XBT_PUBLIC void suspend();
 
-/** @brief yield the actor. */
+/** @brief Yield the actor. */
 XBT_PUBLIC void yield();
 
 /** @brief Resume the actor. */
index 12e0be1..05f5c41 100644 (file)
@@ -36,11 +36,13 @@ public:
 
   static ConditionVariablePtr create();
 
+#ifndef DOXYGEN
   /** @deprecated See Comm::get_mailbox() */
   XBT_ATTRIB_DEPRECATED_v323("Please use Comm::get_mailbox()") ConditionVariablePtr createConditionVariable()
   {
     return create();
   }
+#endif
 
   //  Wait functions without time:
 
index 7a06b51..b7616a4 100644 (file)
@@ -159,6 +159,7 @@ private:
   static s4u::Engine* instance_;
 
   //////////////// Deprecated functions
+#ifndef DOXYGEN
 public:
   /** @deprecated See Engine::load_platform() */
   XBT_ATTRIB_DEPRECATED_v323("Please use Engine::load_platform()") void loadPlatform(std::string platf)
@@ -278,6 +279,7 @@ public:
   }
   /** @deprecated See Engine::set_config() */
   XBT_ATTRIB_DEPRECATED_v323("Please use Engine::set_config()") void setConfig(std::string str) { set_config(str); }
+#endif
 };
 
 /** Callback fired when the platform is created (ie, the xml file parsed),
@@ -297,6 +299,7 @@ extern XBT_PUBLIC xbt::signal<void(double)> on_time_advance;
 /** Callback fired when the time cannot advance because of inter-actors deadlock */
 extern XBT_PUBLIC xbt::signal<void(void)> on_deadlock;
 
+#ifndef DOXYGEN /* Internal use only, no need to expose it */
 template <class T> XBT_PRIVATE void get_filtered_netzones_recursive(s4u::NetZone* current, std::vector<T*>* whereto)
 {
   static_assert(std::is_base_of<kernel::routing::NetZoneImpl, T>::value,
@@ -307,6 +310,7 @@ template <class T> XBT_PRIVATE void get_filtered_netzones_recursive(s4u::NetZone
       whereto->push_back(dynamic_cast<T*>(elem->get_impl()));
   }
 }
+#endif
 }
 } // namespace simgrid::s4u
 
index ac19803..332ae45 100644 (file)
@@ -52,7 +52,7 @@ private:
 public:
   /*** Called on each newly created host */
   static simgrid::xbt::signal<void(Host&)> on_creation;
-  /*** Called just before destructing an host */
+  /*** Called just before destructing a host */
   static simgrid::xbt::signal<void(Host&)> on_destruction;
   /*** Called when the machine is turned on or off (called AFTER the change) */
   static simgrid::xbt::signal<void(Host&)> on_state_change;
@@ -65,11 +65,11 @@ public:
   Host(Host const&) = delete;
   Host& operator=(Host const&) = delete;
 
-  /** Retrieves an host from its name, or return nullptr */
+  /** Retrieve a host from its name, or return nullptr */
   static Host* by_name_or_null(std::string name);
-  /** Retrieves an host from its name, or die */
+  /** Retrieve a host from its name, or die */
   static s4u::Host* by_name(std::string name);
-  /** Retrieves the host on which the current actor is running */
+  /** Retrieve the host on which the current actor is running */
   static s4u::Host* current();
 
   /** Retrieves the name of that host as a C++ string */
@@ -127,22 +127,24 @@ public:
   {
     return get_pstate_speed(pstate_index);
   }
-#endif
 
   std::vector<const char*> get_attached_storages() const;
   XBT_ATTRIB_DEPRECATED_v323("Please use Host::get_attached_storages() instead.") void getAttachedStorages(
       std::vector<const char*>* storages);
+#endif
 
   /** Get an associative list [mount point]->[Storage] of all local mount points.
    *
    *  This is defined in the platform file, and cannot be modified programatically (yet).
    */
   std::unordered_map<std::string, Storage*> const& get_mounted_storages();
+#ifndef DOXYGEN
   /** @deprecated See Host::get_mounted_storages() */
   XBT_ATTRIB_DEPRECATED_v323("Please use Host::get_mounted_storages() instead.") std::unordered_map<std::string, Storage*> const& getMountedStorages()
   {
     return get_mounted_storages();
   }
+#endif
 
   void route_to(Host* dest, std::vector<Link*>& links, double* latency);
   void route_to(Host* dest, std::vector<kernel::resource::LinkImpl*>& links, double* latency);
index 630d238..6f59545 100644 (file)
@@ -27,6 +27,7 @@ class XBT_PUBLIC Mailbox {
   friend void intrusive_ptr_add_ref(Mailbox*) {}
   /** private function to manage the mailboxes' lifetime (see @ref s4u_raii) */
   friend void intrusive_ptr_release(Mailbox*) {}
+
 public:
   /** private function, do not use. FIXME: make me protected */
   kernel::activity::MailboxImpl* get_impl() { return pimpl_; }
@@ -97,6 +98,7 @@ public:
   void* get(double timeout);
 
   // Deprecated functions
+#ifndef DOXYGEN
   /** @deprecated Mailbox::set_receiver() */
   XBT_ATTRIB_DEPRECATED_v323("Please use Mailbox::set_receiver()") void setReceiver(ActorPtr actor)
   {
@@ -126,6 +128,7 @@ public:
   {
     return by_name(name);
   }
+#endif
 };
 
 }} // namespace simgrid::s4u
index 4c8b920..5ad1bbe 100644 (file)
@@ -51,9 +51,11 @@ public:
   void unlock();
   bool try_lock();
 
+#ifndef DOXYGEN
   // deprecated
   /** @deprecated Mutex::create() */
   XBT_ATTRIB_DEPRECATED_v323("Please use Mutex::create()") static MutexPtr createMutex() { return create(); }
+#endif
 };
 
 }} // namespace simgrid::s4u
index 8156699..552ff1c 100644 (file)
@@ -74,6 +74,7 @@ public:
   static simgrid::xbt::signal<void(NetZone&)> on_creation;
   static simgrid::xbt::signal<void(NetZone&)> on_seal;
 
+#ifndef DOXYGEN
   // Deprecation wrappers
   /** @deprecated NetZone::get_father() */
   XBT_ATTRIB_DEPRECATED_v323("Please use NetZone::get_father()") NetZone* getFather() { return get_father(); }
@@ -130,6 +131,7 @@ public:
       res->push_back(child);
     return res;
   }
+#endif
 };
 }
 }; // Namespace simgrid::s4u
index 7559611..9a65fd3 100644 (file)
@@ -73,6 +73,7 @@ public:
   surf::StorageImpl* get_impl() { return pimpl_; }
 
   // Deprecated functions
+#ifndef DOXYGEN
   /** @deprecated Storage::by_name() */
   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::by_name()") Storage* byName(std::string name)
   {
@@ -109,6 +110,7 @@ public:
   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::set_data()") void setUserdata(void* data) { set_data(data); }
   /** @deprecated Storage::get_data() */
   XBT_ATTRIB_DEPRECATED_v323("Please use Storage::get_data()") void* getUserdata() { return get_data(); }
+#endif
 
 private:
   Host* attached_to_              = nullptr;
index 69221c8..d2410fe 100644 (file)
@@ -60,6 +60,7 @@ public:
   static simgrid::xbt::signal<void(VirtualMachine&)> on_migration_start;
   static simgrid::xbt::signal<void(VirtualMachine&)> on_migration_end;
 
+#ifndef DOXYGEN
   // Deprecated methods
   /** @deprecated See VirtualMachine::get_state() */
   XBT_ATTRIB_DEPRECATED_v323("Please use VirtualMachine::get_state()") VirtualMachine::state getState()
@@ -84,6 +85,7 @@ public:
   }
   /** @deprecated See VirtualMachine::set_bound() */
   XBT_ATTRIB_DEPRECATED_v323("Please use VirtualMachine::set_bound()") void setBound(double bound) { set_bound(bound); }
+#endif
 };
 }
 } // namespace simgrid::s4u
index 3a9a64c..164131c 100644 (file)
@@ -59,9 +59,9 @@ void jxbt_throw_null(JNIEnv* env, std::string msg);
 
 /** Thrown on illegal arguments */
 void jxbt_throw_illegal(JNIEnv* env, std::string msg);
-/** Thrown when looking for an host from name does not lead to anything */
+/** Thrown when looking for a host from name does not lead to anything */
 void jxbt_throw_host_not_found(JNIEnv* env, std::string invalid_name);
-/** Thrown when looking for an host from name does not lead to anything */
+/** Thrown when looking for a host from name does not lead to anything */
 void jxbt_throw_process_not_found(JNIEnv* env, std::string invalid_name);
 /** Thrown when a transfer failure accure while Sending task */
 void jxbt_throw_transfer_failure(JNIEnv* env, std::string detail);
index 02b5583..3943a70 100644 (file)
@@ -17,7 +17,7 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(lua_host, "Lua Host module");
 /*                                simgrid.host API                                   */
 /* ********************************************************************************* */
 
-/** @brief Ensures that the pointed stack value is an host userdatum and returns it.
+/** @brief Ensures that the pointed stack value is a host userdatum and returns it.
  *
  * @param L a Lua state
  * @param index an index in the Lua stack
diff --git a/src/bindings/python/simgrid_python.cpp b/src/bindings/python/simgrid_python.cpp
new file mode 100644 (file)
index 0000000..b7ddd8f
--- /dev/null
@@ -0,0 +1,96 @@
+#include <functional>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include <pybind11/functional.h>
+#include <pybind11/pybind11.h>
+#include <pybind11/stl.h>
+
+#include <simgrid/config.h>
+#include <xbt/log.h>
+#include <xbt/string.hpp>
+
+#include <simgrid/s4u/Actor.hpp>
+#include <simgrid/s4u/Engine.hpp>
+#include <simgrid/s4u/Host.hpp>
+
+#include <boost/intrusive_ptr.hpp>
+
+namespace py = pybind11;
+using simgrid::s4u::Actor;
+using simgrid::s4u::ActorPtr;
+using simgrid::s4u::Engine;
+using simgrid::s4u::Host;
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(python, "python");
+
+PYBIND11_DECLARE_HOLDER_TYPE(T, boost::intrusive_ptr<T>);
+
+namespace {
+
+static std::string get_simgrid_version()
+{
+  int major, minor, patch;
+  sg_version_get(&major, &minor, &patch);
+  return simgrid::xbt::string_printf("%i.%i.%i", major, minor, patch);
+}
+
+static std::string simgrid_version = get_simgrid_version();
+
+} // namespace
+
+PYBIND11_MODULE(simgrid, m)
+{
+
+  m.doc() = "SimGrid userspace API";
+
+  m.attr("simgrid_version") = simgrid_version;
+
+  m.def("info", [](char* s) { XBT_INFO("%s", s); }, "Display a logging message of default priority.");
+
+  /* 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 */
+  py::class_<Engine>(m, "Engine")
+      .def(py::init([](std::vector<std::string> args) -> simgrid::s4u::Engine* {
+        static char noarg[] = {'\0'};
+        int argc            = args.size();
+        std::unique_ptr<char* []> argv(new char*[argc + 1]);
+        for (int i = 0; i != argc; ++i)
+          argv[i] = args[i].empty() ? noarg : &args[i].front();
+        argv[argc] = nullptr;
+        // Currently this can be dangling, we should wrap this somehow.
+        return new simgrid::s4u::Engine(&argc, argv.get());
+      }))
+      .def("load_platform", &Engine::load_platform, "Load a platform file describing the environment")
+      .def("load_deployment", &Engine::load_deployment, "Load a deployment file and launch the actors that it contains")
+      .def("run", &Engine::run, "Run the simulation")
+      .def("register_function", [](Engine*, std::string name, std::function<void(std::vector<std::string>)> f) {
+        simgrid::simix::register_function(name,
+            [f](std::vector<std::string> args) -> simgrid::simix::ActorCode {
+          return [args, f]() { f(args); };
+        });
+      }, "Registers the main function of an actor that will be launched from the deployment file");
+
+  // Currently, Host lead to segfault:
+  py::class_<simgrid::s4u::Host, std::unique_ptr<Host, py::nodelete>>(m, "Host").def(
+      "by_name", &Host::by_name, "Retrieve a host from its name, or die");
+
+  py::class_<simgrid::s4u::Actor, ActorPtr>(m, "Actor", "An actor is an independent stream of execution in your distributed application");
+
+  // Select the right template instantiation
+  simgrid::s4u::ActorPtr (*create_actor)(std::string, Host*, std::function<void()>) = &Actor::create;
+
+  m.def("create_actor", create_actor, "Create an actor");
+  m.def("create_actor", [](std::string name, Host* host) -> std::function<ActorPtr(std::function<void()>)> {
+    return [name, host](std::function<void()> f) -> ActorPtr {
+      return simgrid::s4u::Actor::create(name, host, std::move(f));
+    };
+  }, "Create an actor");
+}
index 9ff4572..461ebb7 100644 (file)
@@ -188,9 +188,9 @@ void RoutedZone::add_route_check_params(NetPoint* src, NetPoint* dst, NetPoint*
     xbt_assert(dst->is_netzone(), "When defining a NetzoneRoute, dst must be a netzone but '%s' is not", dstName);
 
     xbt_assert(gw_src->is_host() || gw_src->is_router(),
-               "When defining a NetzoneRoute, gw_src must be an host or a router but '%s' is not.", srcName);
+               "When defining a NetzoneRoute, gw_src must be a host or a router but '%s' is not.", srcName);
     xbt_assert(gw_dst->is_host() || gw_dst->is_router(),
-               "When defining a NetzoneRoute, gw_dst must be an host or a router but '%s' is not.", dstName);
+               "When defining a NetzoneRoute, gw_dst must be a host or a router but '%s' is not.", dstName);
 
     xbt_assert(gw_src != gw_dst, "Cannot define an NetzoneRoute from '%s' to itself", gw_src->get_cname());
 
index 2e3a673..b8f09e6 100644 (file)
@@ -33,7 +33,7 @@ VirtualMachine::VirtualMachine(std::string name, s4u::Host* physical_host, int c
     : Host(name), pimpl_vm_(new vm::VirtualMachineImpl(this, physical_host, core_amount, ramsize))
 {
   // xbt_assert(s4u::Host::by_name(name) == nullptr,
-  //           "Cannot create a VM named %s: this name is already used by an host or a VM", name.c_str());
+  //           "Cannot create a VM named %s: this name is already used by a host or a VM", name.c_str());
 
   XBT_DEBUG("Create VM %s", name.c_str());
 
index 5cb1a98..eb3ff86 100644 (file)
@@ -127,7 +127,7 @@ void Engine::host_unregister(std::string name)
   pimpl->hosts_.erase(name);
 }
 
-/** @brief Find an host from its name.
+/** @brief Find a host from its name.
  *
  *  @throw std::invalid_argument if the searched host does not exist.
  */
@@ -138,7 +138,7 @@ simgrid::s4u::Host* Engine::host_by_name(std::string name)
   return pimpl->hosts_.at(name);
 }
 
-/** @brief Find an host from its name (or nullptr if that host does not exist) */
+/** @brief Find a host from its name (or nullptr if that host does not exist) */
 simgrid::s4u::Host* Engine::host_by_name_or_null(std::string name)
 {
   auto host = pimpl->hosts_.find(name);
index b44b000..6c27ca3 100644 (file)
@@ -49,7 +49,7 @@ Host::~Host()
 
 /** @brief Fire the required callbacks and destroy the object
  *
- * Don't delete directly an Host, call h->destroy() instead.
+ * Don't delete directly a host, call h->destroy() instead.
  *
  * This is cumbersome but this is the simplest solution to ensure that the
  * onDestruction() callback receives a valid object (because of the destructor
@@ -259,7 +259,7 @@ int Host::get_pstate() const
 
 /**
  * @ingroup simix_storage_management
- * @brief Returns the list of storages attached to an host.
+ * @brief Returns the list of storages attached to a host.
  * @return a vector containing all storages attached to the host
  */
 std::vector<const char*> Host::get_attached_storages() const
@@ -518,7 +518,7 @@ int sg_host_is_off(sg_host_t host)
   return host->is_off();
 }
 
-/** @brief Get the properties of an host */
+/** @brief Get the properties of a host */
 xbt_dict_t sg_host_get_properties(sg_host_t host)
 {
   xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
@@ -611,7 +611,7 @@ void sg_host_dump(sg_host_t host)
   }
 }
 
-/** @brief Return the list of actors attached to an host.
+/** @brief Return the list of actors attached to a host.
  *
  * @param host a host
  * @param whereto a dynar in which we should push actors living on that host
index 850f15d..7bf0ed3 100644 (file)
@@ -28,7 +28,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix);
 
 /**
  * @ingroup simix_process_management
- * @brief Creates a synchro that executes some computation of an host.
+ * @brief Creates a synchro that executes some computation of a host.
  *
  * This function creates a SURF action and allocates the data necessary
  * to create the SIMIX synchro. It can raise a HostFailureException exception if the host crashed.
index ff6f193..8cf43e0 100644 (file)
@@ -97,7 +97,7 @@ HostImpl::~HostImpl()
 
 /** Re-starts all the actors that are marked as restartable.
  *
- * Weird things will happen if you turn on an host that is already on. S4U is fool-proof, not this.
+ * Weird things will happen if you turn on a host that is already on. S4U is fool-proof, not this.
  */
 void HostImpl::turn_on()
 {
index 1ee8447..3e45e50 100644 (file)
@@ -90,7 +90,11 @@ static void datasent_cb(ns3::Ptr<ns3::Socket> socket, uint32_t dataSent)
 static void normalClose_callback(ns3::Ptr<ns3::Socket> socket)
 {
   SgFlow* flow = getFlowFromSocket(socket);
-  XBT_DEBUG("normalClose_cb of F[%p, %p, %u]", flow, flow->action_, flow->total_bytes_);
+  XBT_DEBUG("normalClose_cb of F[%p, %p] total: %u; sent: %u", flow, flow->action_, flow->total_bytes_,
+            flow->sent_bytes_);
+  // xbt_assert(flow->total_bytes_ == flow->sent_bytes_,
+  //    "total_bytes (=%u) is not sent_bytes(=%u)", flow->total_bytes_ , flow->sent_bytes_);
+  // xbt_assert(flow->remaining_ == 0, "Remaining is not 0 but %u", flow->remaining_);
   receive_callback(socket);
 }
 
index aaf5bfa..b3eaf61 100644 (file)
@@ -63,7 +63,7 @@ void sg_platf_exit() {
   surf_parse_lex_destroy();
 }
 
-/** @brief Add an host to the current AS */
+/** @brief Add a host to the current AS */
 void sg_platf_new_host(simgrid::kernel::routing::HostCreationArgs* args)
 {
   std::map<std::string, std::string> props;
@@ -633,13 +633,13 @@ void sg_platf_new_Zone_seal()
   current_routing = static_cast<simgrid::kernel::routing::NetZoneImpl*>(current_routing->get_father());
 }
 
-/** @brief Add a link connecting an host to the rest of its AS (which must be cluster or vivaldi) */
+/** @brief Add a link connecting a host to the rest of its AS (which must be cluster or vivaldi) */
 void sg_platf_new_hostlink(simgrid::kernel::routing::HostLinkCreationArgs* hostlink)
 {
   simgrid::kernel::routing::NetPoint* netpoint = sg_host_by_name(hostlink->id.c_str())->pimpl_netpoint;
   xbt_assert(netpoint, "Host '%s' not found!", hostlink->id.c_str());
   xbt_assert(dynamic_cast<simgrid::kernel::routing::ClusterZone*>(current_routing),
-             "Only hosts from Cluster and Vivaldi ASes can get an host_link.");
+             "Only hosts from Cluster and Vivaldi ASes can get a host_link.");
 
   simgrid::s4u::Link* linkUp   = simgrid::s4u::Link::by_name_or_null(hostlink->link_up);
   simgrid::s4u::Link* linkDown = simgrid::s4u::Link::by_name_or_null(hostlink->link_down);
index 754f638..d2654e6 100644 (file)
@@ -2,6 +2,7 @@
 
 set(EXTRA_DIST
   src/bindings/java/MANIFEST.in
+  src/bindings/python/simgrid_python.cpp
   src/include/mc/datatypes.h
   src/include/mc/mc.h
   src/include/simgrid/sg_config.hpp
@@ -904,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/lang_cpp.png
+  docs/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
@@ -1007,6 +1010,7 @@ set(CMAKEFILES_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
index 3a296f3..4e76b83 100644 (file)
@@ -4,7 +4,7 @@ FROM debian:testing
 # - Install SimGrid's dependencies
 RUN apt update && \
     apt install -y \
-       g++ gcc gfortran default-jdk \
+       g++ gcc gfortran default-jdk pybind11-dev \
        git \
        valgrind \
        libboost-dev libboost-all-dev \