[PATCH] [lld][Core] Implement parallel_for_each
Shankar Kalpathi Easwaran
shankarke at gmail.com
Sun Mar 15 18:12:23 PDT 2015
Updating the code sent for review, with my latest changes. Have a seperate constant for parallel_for_each functionality.
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
@@ -293,11 +293,36 @@
concurrency::parallel_for_each(begin, end, func);
}
#else
+namespace detail {
+const ptrdiff_t minParallelForEachSize = 512;
+template <class Iterator, class Func>
+void parallel_for_each(Iterator begin, Iterator end, Func &func, TaskGroup &tg,
+ size_t depth) {
+
+ size_t len = std::distance(begin, end);
+
+ if (len < detail::minParallelForEachSize || depth == 0) {
+ std::for_each(begin, end, func);
+ return;
+ }
+
+ auto pivot = begin + len / 2;
+
+ // Recurse.
+ tg.spawn([=, &func, &tg] {
+ parallel_for_each(begin, pivot, func, tg, depth - 1);
+ });
+ parallel_for_each(pivot, end, func, tg, depth - 1);
+}
+}
+
template <class Iterator, class Func>
void parallel_for_each(Iterator begin, Iterator end, Func func) {
- // TODO: Make this parallel.
- std::for_each(begin, end, func);
+ TaskGroup tg;
+ detail::parallel_for_each(begin, end, func, tg,
+ llvm::Log2_64(std::distance(begin, end)) + 1);
}
+
#endif
} // end namespace lld
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8348.22008.patch
Type: text/x-patch
Size: 1211 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150316/80358f62/attachment.bin>
More information about the llvm-commits
mailing list