MCPcopy Create free account
hub / github.com/aui-framework/aui / parallel

Method parallel

aui.core/src/AUI/Thread/AThreadPool.h:260–281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

258
259template <typename Iterator, typename Functor>
260auto AThreadPool::parallel(Iterator begin, Iterator end, Functor&& functor) {
261 using ResultType = decltype(std::declval<Functor>()(std::declval<Iterator>(), std::declval<Iterator>()));
262 AFutureSet<ResultType> futureSet;
263
264 size_t itemCount = end - begin;
265 size_t affinity = (glm::min) (AThreadPool::global().getTotalWorkerCount(), itemCount);
266 if (affinity == 0)
267 return futureSet;
268 size_t itemsPerThread = itemCount / affinity;
269
270 for (size_t threadIndex = 0; threadIndex < affinity; ++threadIndex) {
271 auto forThreadBegin = begin;
272 begin += itemsPerThread;
273 auto forThreadEnd = threadIndex + 1 == affinity ? end : begin;
274 futureSet.push_back(
275 *this * [functor = std::forward<Functor>(functor), forThreadBegin, forThreadEnd]() -> decltype(auto) {
276 return functor(forThreadBegin, forThreadEnd);
277 });
278 }
279
280 return futureSet;
281}
282
283#include <AUI/Reflect/AReflect.h>

Callers 2

parallelFunction · 0.80
TESTFunction · 0.80

Calls 1

push_backMethod · 0.45

Tested by 1

TESTFunction · 0.64