[PATCH] [lld][Core] Implement parallel_for_each
Shankar Kalpathi Easwaran
shankarke at gmail.com
Mon Mar 16 12:27:44 PDT 2015
Implement a non-recursive version as per davide/ruiu.
http://reviews.llvm.org/D8348
Files:
include/lld/Core/Parallel.h
Index: include/lld/Core/Parallel.h
===================================================================
--- include/lld/Core/Parallel.h
+++ include/lld/Core/Parallel.h
@@ -295,7 +295,16 @@
#else
template <class Iterator, class Func>
void parallel_for_each(Iterator begin, Iterator end, Func func) {
- // TODO: Make this parallel.
+ TaskGroup tg;
+ const ptrdiff_t minParallelSizeForEach = 1024;
+ int64_t length = distance(begin, end);
+ int64_t taskSize = (length < minParallelSizeForEach)
+ ? length
+ : length / minParallelSizeForEach;
+ while (taskSize <= distance(begin, end)) {
+ tg.spawn([=, &func, &tg] { std::for_each(begin, begin + taskSize, func); });
+ begin += taskSize;
+ }
std::for_each(begin, end, func);
}
#endif
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8348.22039.patch
Type: text/x-patch
Size: 798 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150316/468abd50/attachment.bin>
More information about the llvm-commits
mailing list