From: Martin Quinson Date: Thu, 27 Dec 2018 09:27:51 +0000 (+0100) Subject: Merge branch 'master' of github.com:simgrid/simgrid X-Git-Tag: v3_22~750 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/8937f1426cc4c3bbe77178ce3a9cdc0687263a8e?hp=65dec2e3393eebad6c9d7a9c778a030e66fe78a7 Merge branch 'master' of github.com:simgrid/simgrid --- diff --git a/.gitignore b/.gitignore index f1d759073d..5af3b34990 100644 --- a/.gitignore +++ b/.gitignore @@ -14,10 +14,14 @@ *.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 diff --git a/.travis.yml b/.travis.yml index 2c17bb8f7b..3c814f5892 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,6 +27,7 @@ addons: - libdw-dev - libevent-dev - libunwind8-dev + - pybind11-dev homebrew: packages: - python diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d9417b9e2..02a0859d10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 index 0000000000..ad7a89a015 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 index 0000000000..585bc0d340 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 index 0000000000..01121601a0 --- /dev/null +++ b/examples/python/CMakeLists.txt @@ -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 index 0000000000..0d609653d3 --- /dev/null +++ b/examples/python/exec-basic/exec-basic.py @@ -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 index 0000000000..07e77b9633 --- /dev/null +++ b/examples/python/exec-basic/exec-basic.tesh @@ -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. diff --git a/examples/s4u/README.rst b/examples/s4u/README.rst index b1b996da8b..e730f217b9 100644 --- a/examples/s4u/README.rst +++ b/examples/s4u/README.rst @@ -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 `_ + |br| |cpp| `examples/s4u/exec-basic/s4u-exec-basic.cpp `_ + |br| |py| `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
+ +.. |cpp| image:: /img/lang_cpp.png + :align: middle + :width: 12 + +.. |py| image:: /img/lang_python.png + :align: middle + :width: 12 diff --git a/include/simgrid/Exception.hpp b/include/simgrid/Exception.hpp index a259e2be01..ff59edf2b0 100644 --- a/include/simgrid/Exception.hpp +++ b/include/simgrid/Exception.hpp @@ -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) diff --git a/include/simgrid/kernel/routing/ClusterZone.hpp b/include/simgrid/kernel/routing/ClusterZone.hpp index 167b2c10bc..4f6878ebaa 100644 --- a/include/simgrid/kernel/routing/ClusterZone.hpp +++ b/include/simgrid/kernel/routing/ClusterZone.hpp @@ -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): * limiter(A)_UP, private(A)_UP, backbone, private(B)_DOWN, limiter(B)_DOWN. * 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: * limiter(A)_UP, private(A)_UP, backbone * (because the private router is directly connected to the cluster core). */ diff --git a/include/simgrid/kernel/routing/NetZoneImpl.hpp b/include/simgrid/kernel/routing/NetZoneImpl.hpp index 260661c2d8..8b24af29cb 100644 --- a/include/simgrid/kernel/routing/NetZoneImpl.hpp +++ b/include/simgrid/kernel/routing/NetZoneImpl.hpp @@ -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* speed_per_pstate, int core_count, std::map* props); /** @brief Creates a new route in this NetZone */ diff --git a/include/simgrid/kernel/routing/VivaldiZone.hpp b/include/simgrid/kernel/routing/VivaldiZone.hpp index 820ff1098b..ecbe7187cc 100644 --- a/include/simgrid/kernel/routing/VivaldiZone.hpp +++ b/include/simgrid/kernel/routing/VivaldiZone.hpp @@ -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: * private(A)_UP, private(B)_DOWN, 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. diff --git a/include/simgrid/s4u.hpp b/include/simgrid/s4u.hpp index d3182a50ba..0bc419cb97 100644 --- a/include/simgrid/s4u.hpp +++ b/include/simgrid/s4u.hpp @@ -20,6 +20,7 @@ #include #include #include +#include #include diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index 4013808fbe..3167cfd973 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -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 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. */ diff --git a/include/simgrid/s4u/ConditionVariable.hpp b/include/simgrid/s4u/ConditionVariable.hpp index 12e0be189a..05f5c411e5 100644 --- a/include/simgrid/s4u/ConditionVariable.hpp +++ b/include/simgrid/s4u/ConditionVariable.hpp @@ -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: diff --git a/include/simgrid/s4u/Engine.hpp b/include/simgrid/s4u/Engine.hpp index 7a06b5175d..b7616a407a 100644 --- a/include/simgrid/s4u/Engine.hpp +++ b/include/simgrid/s4u/Engine.hpp @@ -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 on_time_advance; /** Callback fired when the time cannot advance because of inter-actors deadlock */ extern XBT_PUBLIC xbt::signal on_deadlock; +#ifndef DOXYGEN /* Internal use only, no need to expose it */ template XBT_PRIVATE void get_filtered_netzones_recursive(s4u::NetZone* current, std::vector* whereto) { static_assert(std::is_base_of::value, @@ -307,6 +310,7 @@ template XBT_PRIVATE void get_filtered_netzones_recursive(s4u::NetZone whereto->push_back(dynamic_cast(elem->get_impl())); } } +#endif } } // namespace simgrid::s4u diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index ac19803522..332ae45c94 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -52,7 +52,7 @@ private: public: /*** Called on each newly created host */ static simgrid::xbt::signal on_creation; - /*** Called just before destructing an host */ + /*** Called just before destructing a host */ static simgrid::xbt::signal on_destruction; /*** Called when the machine is turned on or off (called AFTER the change) */ static simgrid::xbt::signal 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 get_attached_storages() const; XBT_ATTRIB_DEPRECATED_v323("Please use Host::get_attached_storages() instead.") void getAttachedStorages( std::vector* 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 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 const& getMountedStorages() { return get_mounted_storages(); } +#endif void route_to(Host* dest, std::vector& links, double* latency); void route_to(Host* dest, std::vector& links, double* latency); diff --git a/include/simgrid/s4u/Mailbox.hpp b/include/simgrid/s4u/Mailbox.hpp index 630d238aab..6f595450c2 100644 --- a/include/simgrid/s4u/Mailbox.hpp +++ b/include/simgrid/s4u/Mailbox.hpp @@ -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 diff --git a/include/simgrid/s4u/Mutex.hpp b/include/simgrid/s4u/Mutex.hpp index 4c8b9207fa..5ad1bbe6c9 100644 --- a/include/simgrid/s4u/Mutex.hpp +++ b/include/simgrid/s4u/Mutex.hpp @@ -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 diff --git a/include/simgrid/s4u/NetZone.hpp b/include/simgrid/s4u/NetZone.hpp index 8156699c38..552ff1ca55 100644 --- a/include/simgrid/s4u/NetZone.hpp +++ b/include/simgrid/s4u/NetZone.hpp @@ -74,6 +74,7 @@ public: static simgrid::xbt::signal on_creation; static simgrid::xbt::signal 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 diff --git a/include/simgrid/s4u/Storage.hpp b/include/simgrid/s4u/Storage.hpp index 7559611c7f..9a65fd349b 100644 --- a/include/simgrid/s4u/Storage.hpp +++ b/include/simgrid/s4u/Storage.hpp @@ -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; diff --git a/include/simgrid/s4u/VirtualMachine.hpp b/include/simgrid/s4u/VirtualMachine.hpp index 69221c8b78..d2410febf3 100644 --- a/include/simgrid/s4u/VirtualMachine.hpp +++ b/include/simgrid/s4u/VirtualMachine.hpp @@ -60,6 +60,7 @@ public: static simgrid::xbt::signal on_migration_start; static simgrid::xbt::signal 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 diff --git a/src/bindings/java/jxbt_utilities.hpp b/src/bindings/java/jxbt_utilities.hpp index 3a9a64c47c..164131c235 100644 --- a/src/bindings/java/jxbt_utilities.hpp +++ b/src/bindings/java/jxbt_utilities.hpp @@ -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); diff --git a/src/bindings/lua/lua_host.cpp b/src/bindings/lua/lua_host.cpp index 02b55834fe..3943a7019b 100644 --- a/src/bindings/lua/lua_host.cpp +++ b/src/bindings/lua/lua_host.cpp @@ -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 index 0000000000..b7ddd8f295 --- /dev/null +++ b/src/bindings/python/simgrid_python.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include + +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); + +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(&simgrid::s4u::this_actor::execute), + "Block the actor, computing the given amount of flops"); + m.def("execute", py::overload_cast(&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_(m, "Engine") + .def(py::init([](std::vector args) -> simgrid::s4u::Engine* { + static char noarg[] = {'\0'}; + int argc = args.size(); + std::unique_ptr 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)> f) { + simgrid::simix::register_function(name, + [f](std::vector 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_>(m, "Host").def( + "by_name", &Host::by_name, "Retrieve a host from its name, or die"); + + py::class_(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) = &Actor::create; + + m.def("create_actor", create_actor, "Create an actor"); + m.def("create_actor", [](std::string name, Host* host) -> std::function)> { + return [name, host](std::function f) -> ActorPtr { + return simgrid::s4u::Actor::create(name, host, std::move(f)); + }; + }, "Create an actor"); +} diff --git a/src/kernel/routing/RoutedZone.cpp b/src/kernel/routing/RoutedZone.cpp index 9ff45720de..461ebb74e9 100644 --- a/src/kernel/routing/RoutedZone.cpp +++ b/src/kernel/routing/RoutedZone.cpp @@ -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()); diff --git a/src/plugins/vm/s4u_VirtualMachine.cpp b/src/plugins/vm/s4u_VirtualMachine.cpp index 2e3a673c1b..b8f09e689b 100644 --- a/src/plugins/vm/s4u_VirtualMachine.cpp +++ b/src/plugins/vm/s4u_VirtualMachine.cpp @@ -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()); diff --git a/src/s4u/s4u_Engine.cpp b/src/s4u/s4u_Engine.cpp index 5cb1a9839a..eb3ff86f30 100644 --- a/src/s4u/s4u_Engine.cpp +++ b/src/s4u/s4u_Engine.cpp @@ -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); diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index b44b000b23..6c27ca36db 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -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 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 diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 850f15defc..7bf0ed312a 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -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. diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index ff6f1931b5..8cf43e04fb 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -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() { diff --git a/src/surf/ns3/ns3_simulator.cpp b/src/surf/ns3/ns3_simulator.cpp index 1ee844733c..3e45e50813 100644 --- a/src/surf/ns3/ns3_simulator.cpp +++ b/src/surf/ns3/ns3_simulator.cpp @@ -90,7 +90,11 @@ static void datasent_cb(ns3::Ptr socket, uint32_t dataSent) static void normalClose_callback(ns3::Ptr 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); } diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index aaf5bfa517..b3eaf619cf 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -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 props; @@ -633,13 +633,13 @@ void sg_platf_new_Zone_seal() current_routing = static_cast(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(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); diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 754f638558..d2654e6e21 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -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 diff --git a/tools/docker/Dockerfile.build-deps b/tools/docker/Dockerfile.build-deps index 3a296f3311..4e76b830e1 100644 --- a/tools/docker/Dockerfile.build-deps +++ b/tools/docker/Dockerfile.build-deps @@ -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 \