-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from bluescarni/pr/fork_island
Fork island
- Loading branch information
Showing
33 changed files
with
981 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,7 @@ Implemented islands | |
:maxdepth: 1 | ||
|
||
islands/thread_island | ||
islands/fork_island | ||
|
||
Utilities | ||
^^^^^^^^^ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
Fork island | ||
=========== | ||
|
||
.. versionadded:: 2.9 | ||
|
||
*#include <pagmo/islands/fork_island.hpp>* | ||
|
||
.. note:: | ||
|
||
The :cpp:class:`~pagmo::fork_island` class is available only on POSIX platforms (e.g., Linux, OSX, | ||
the BSDs, but *not* Microsoft Windows, unless some POSIX compatibility layer has been installed | ||
on the system). | ||
|
||
.. cpp:namespace-push:: pagmo | ||
|
||
.. cpp:class:: fork_island | ||
|
||
This user-defined island (UDI) will use the POSIX ``fork()`` system call to offload the evolution | ||
of a population to a child process. | ||
|
||
Generally speaking, users are encouraged to use :cpp:class:`~pagmo::thread_island` rather than | ||
:cpp:class:`~pagmo::fork_island`: :cpp:class:`~pagmo::thread_island` performs better, | ||
it works also with problems and algorithms which are not serialisable, and it is available on all | ||
platforms. | ||
|
||
:cpp:class:`~pagmo::fork_island` should however be preferred when dealing with problems and algorithms | ||
which do not offer the basic :cpp:type:`~pagmo::thread_safety` guarantee. By offloading the optimisation | ||
to a separate process (rather than a separate thread), :cpp:class:`~pagmo::fork_island` can ensure | ||
that thread-unsafe problems and algorithms are always run in only one thread at a time. | ||
This capability is particularly useful when wrapping in pagmo third-party code which does not support execution | ||
in multithreaded contexts (a notable example is the :cpp:class:`~pagmo::ipopt` algorithm, | ||
which uses the thread-unsafe IPOPT optimiser). | ||
|
||
:cpp:class:`~pagmo::fork_island` is the UDI type automatically selected by the constructors of :cpp:class:`~pagmo::island` | ||
on POSIX platforms when the island's problem and/or algorithm do not provide the basic :cpp:type:`~pagmo::thread_safety` | ||
guarantee. | ||
|
||
.. note:: | ||
|
||
:cpp:class:`~pagmo::fork_island` is not exposed in the Python bindings. Instead, pygmo provides a | ||
:py:class:`process-based island <pygmo.mp_island>` via Python's :py:mod:`multiprocessing` module. | ||
|
||
.. note:: | ||
|
||
When using memory checking tools such as valgrind, or the address/memory sanitizers from GCC/clang, be aware | ||
that memory leaks in the child process may be flagged by such tools. These are spurious warnings due to the | ||
fact that the child process is exited via ``std::exit()`` (which does not invoke the destructors | ||
of objects with automatic storage duration). Thus, such warnings can be safely ignored. | ||
|
||
.. cpp:function:: fork_island() | ||
.. cpp:function:: fork_island(const fork_island &) | ||
.. cpp:function:: fork_island(fork_island &&) noexcept | ||
|
||
:cpp:class:`~pagmo::fork_island` is default, copy and move-constructible. | ||
|
||
.. cpp:function:: void run_evolve(island &isl) const | ||
|
||
This method will fork the calling process, and, in the child process, the :cpp:class:`~pagmo::population` of *isl* will be | ||
evolved using the :cpp:class:`~pagmo::algorithm` of *isl*. At the end of the evolution, the evolved population and the | ||
algorithm used for the evolution will be sent back to the parent process, where they will replace, in *isl*, the original | ||
population and algorithm. The child process will then terminate via ``std::exit(0)``. | ||
|
||
If any exception is raised during the evolution, the error message from the exception will be transferred back to the parent | ||
process, where a ``std::runtime_error`` containing the error message from the child will be raised. | ||
|
||
:param isl: the :cpp:class:`~pagmo::island` that will be evolved. | ||
|
||
:exception std\:\:runtime_error: if any error arises from the use of POSIX primitives (``fork()``, pipes, etc.), or if any | ||
error is generated in the child process. | ||
:exception unspecified: any exception raised by: | ||
|
||
- the serialisation of :cpp:class:`~pagmo::population` or :cpp:class:`~pagmo::algorithm`, | ||
- :cpp:func:`pagmo::island::set_population()` or :cpp:func:`pagmo::island::set_algorithm()`. | ||
|
||
.. cpp:function:: std::string get_name() const | ||
|
||
:return: the string ``"Fork island"``. | ||
|
||
.. cpp:function:: std::string get_extra_info() const | ||
|
||
:return: if an evolution is ongoing, this method will return a string | ||
representation of the ID of the child process. Otherwise, the ``"No active child."`` string will be returned. | ||
|
||
.. cpp:function:: pid_t get_child_pid() const | ||
|
||
:return: a signed integral value representing the process ID of the child process, if an evolution is ongoing. Otherwise, | ||
``0`` will be returned. | ||
|
||
.. cpp:function:: template <typename Archive> void serialize(Archive &) | ||
|
||
Serialisation support. | ||
|
||
Note that :cpp:class:`~pagmo::fork_island` is stateless, and thus this (de)serialisation function is empty and performs no work. | ||
|
||
.. cpp:namespace-pop:: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
Thread island | ||
============= | ||
|
||
*#include <pagmo/islands/thread_island.hpp>* | ||
|
||
.. doxygenclass:: pagmo::thread_island | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* Copyright 2017-2018 PaGMO development team | ||
This file is part of the PaGMO library. | ||
The PaGMO library is free software; you can redistribute it and/or modify | ||
it under the terms of either: | ||
* the GNU Lesser General Public License as published by the Free | ||
Software Foundation; either version 3 of the License, or (at your | ||
option) any later version. | ||
or | ||
* the GNU General Public License as published by the Free Software | ||
Foundation; either version 3 of the License, or (at your option) any | ||
later version. | ||
or both in parallel, as here. | ||
The PaGMO library is distributed in the hope that it will be useful, but | ||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
for more details. | ||
You should have received copies of the GNU General Public License and the | ||
GNU Lesser General Public License along with the PaGMO library. If not, | ||
see https://www.gnu.org/licenses/. */ | ||
|
||
#ifndef PAGMO_DETAIL_EIGEN_HPP | ||
#define PAGMO_DETAIL_EIGEN_HPP | ||
|
||
// NOTE: we have experimental evidence that on some platform/compiler combinations | ||
// Eigen is failing to include necessary header files. As a workaround, we use this header | ||
// to wrap any Eigen functionality that might be needed in pagmo, and we pre-emptively | ||
// include the missing headers as necessary. | ||
#if defined(__apple_build_version__) | ||
|
||
// NOTE: on OSX and if the _POSIX_C_SOURCE definition is active (or at least for some specific | ||
// values of this definition), Eigen uses the alloca() function without including the header | ||
// that declares it. | ||
#include <alloca.h> | ||
|
||
#endif | ||
|
||
#include <Eigen/Dense> | ||
#include <unsupported/Eigen/MatrixFunctions> | ||
|
||
#endif |
Oops, something went wrong.