Bounded, adaptive splitting of independent work over an index range. More...
#include <algorithm>#include <atomic>#include <cstddef>#include <functional>#include <thread>#include <type_traits>#include <utility>#include "donner/base/Utils.h"#include "donner/base/tasks/FalseSharing.h"#include "donner/base/tasks/TaskScope.h"Classes | |
| struct | donner::tasks::detail::ParallelRangeSplitter< F > |
| All tasks in one loop share the body and join the same scope. More... | |
| struct | donner::tasks::detail::ParallelChunkCursor |
| Keep contended claims off the cache line containing read-mostly loop state. More... | |
Namespaces | |
| namespace | donner |
| Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css. | |
Enumerations | |
| enum class | ParallelForStrategy { Adaptive , SharedCursor } |
Functions | |
| constexpr std::size_t | donner::tasks::detail::ParallelForGrain (std::size_t length, std::size_t requested) |
| Caps the number of leaf ranges without rounding the length past SIZE_MAX. | |
| template<typename F> | |
| void | donner::tasks::detail::SharedCursorLoop (TaskScheduler &scheduler, std::size_t begin, std::size_t end, std::size_t grain, std::size_t pieces, const F &body) |
| Claim bounded chunk ordinals so speculative claims after the last chunk cannot wrap an index. | |
| template<typename F> | |
| void | donner::tasks::detail::ParallelForWithStrategy (ParallelForStrategy strategy, TaskScheduler &scheduler, std::size_t begin, std::size_t end, std::size_t grain, const F &body) |
| Selects the partitioner for tests and comparative measurements. | |
| template<typename F> | |
| void | donner::tasks::ParallelFor (TaskScheduler &scheduler, std::size_t begin, std::size_t end, std::size_t grain, F &&body) |
| Invokes one shared, const-callable body on disjoint subranges and joins them before returning. | |
Bounded, adaptive splitting of independent work over an index range.
| void donner::tasks::ParallelFor | ( | TaskScheduler & | scheduler, |
| std::size_t | begin, | ||
| std::size_t | end, | ||
| std::size_t | grain, | ||
| F && | body ) |
Invokes one shared, const-callable body on disjoint subranges and joins them before returning.
An empty range returns immediately. Reversed bounds fail a release assertion. With zero workers in ordinary mode, a nonempty range is passed to the body once on the calling thread.
Worker count and steal timing can change subrange boundaries and visitation order. Deterministic per-index computations that write disjoint outputs give the same results across schedules. A reduction grouped by callback boundaries can produce different results. Seeded adaptive execution uses a fixed four-piece split budget on one thread. The grain, range and capacity bounds still apply, and the seed can change visitation order.
| scheduler | The scheduler used to run the work. |
| begin | The first index in the half-open range. |
| end | The exclusive upper bound. |
| grain | Requested grain; zero means one. The effective grain bounds the loop to 4096 chunks. |
| body | Called with the first and exclusive last index of each subrange. Concurrent calls must write disjoint outputs or provide their own synchronization. |