-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef3ab1f
commit 326957b
Showing
27 changed files
with
1,789 additions
and
1,158 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 |
---|---|---|
@@ -1,32 +1,48 @@ | ||
# Algorithms | ||
|
||
The header [`algorithm.h`](/futures/reference/Files/algorithm_8h.md) includes implementations of common STL algorithms using the | ||
library primitives. | ||
The header [`algorithm.h`](/futures/reference/Files/algorithm_8h.md) and the corresponding | ||
[Algorithms Module](reference/Modules/group__algorithms/) includes parallel implementations of common STL algorithms | ||
using the library primitives. | ||
|
||
{{ code_snippet("algorithm/algorithms.cpp", "algorithm") }} | ||
|
||
Like the C++20 [ranges library](https://en.cppreference.com/w/cpp/ranges), these algorithms accept both iterators or | ||
ranges as parameters. | ||
|
||
Unless a policy is explicitly stated, all algorithms are parallel by default. These algorithms give us access to | ||
parallel algorithms that rely only on executors. This allows us to avoid of more complex libraries, such | ||
as [TBB](https://github.com/oneapi-src/oneTBB), to execute efficient parallel algorithms. | ||
{{ code_snippet("algorithm/algorithms.cpp", "algorithm_range") }} | ||
|
||
## Executors | ||
|
||
Like other parallel functions defined in this library, these algorithms allow simple execution policies to be replaced | ||
by concrete executors. | ||
|
||
{{ code_snippet("algorithm/algorithms.cpp", "executor") }} | ||
|
||
!!! warning "Parallel by default" | ||
## Parallel by default | ||
|
||
Unless an alternative policy or [executor] is provided, all algorithms are executed in parallel by default whenever it | ||
is "reasonably safe" to do so. A parallel algorithm is considered "reasonably safe" if there are no implicit data races | ||
and deadlocks in its provided functors. | ||
|
||
To execute algorithms sequentially, an appropriate executor or policy should be provided: | ||
|
||
{{ code_snippet("algorithm/algorithms.cpp", "inline_executor") }} | ||
|
||
{{ code_snippet("algorithm/algorithms.cpp", "seq_policy") }} | ||
|
||
Unless a policy is explicitly stated, all algorithms are parallel by default. These algorithms give us access to | ||
parallel algorithms that rely only on executors. This allows us to avoid of more complex libraries, such | ||
as [TBB](https://github.com/oneapi-src/oneTBB), to execute efficient parallel algorithms. | ||
|
||
## Compile time algorithms | ||
|
||
Unless an alternative policy or [executor] is provided, all algorithms are executed in parallel by default whenever | ||
it is "reasonably safe" to do so. A parallel algorithms is considered "reasonably safe" if there are no implicit | ||
data races and deadlocks in its provided functors. | ||
Like in [C++20](https://en.cppreference.com/w/cpp/algorithm), these algorithms can also be used in | ||
`constexpr` contexts with the default inline executor for these contexts. | ||
|
||
!!! hint "[constexpr]" | ||
{{ code_snippet("algorithm/algorithms.cpp", "constexpr") }} | ||
|
||
Unlike [C++ algorithms](https://en.cppreference.com/w/cpp/algorithm), async algorithms using runtime executors and | ||
schedulers cannot be executed as [constexpr]. However, in C++20, algorithms might still be declared [constexpr] and | ||
make use of [std::is_constant_evaluated]. | ||
This feature depends on an internal library implementation equivalent to [std::is_constant_evaluated]. This | ||
implementation is available in most compilers (MSVC 1925, GCC 6, Clang 9), even when C++20 is not available. The macro | ||
`FUTURES_HAS_CONSTANT_EVALUATED` can be used to identify if the feature is available. | ||
|
||
--8<-- "docs/references.md" |
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
Oops, something went wrong.