[PATCH] [lld][Core] Implement parallel_for_each

Phabricator reviews at reviews.llvm.org
Mon Mar 16 14:30:20 PDT 2015


REPOSITORY
  rL LLVM

http://reviews.llvm.org/D8348

Files:
  lld/trunk/include/lld/Core/Parallel.h

Index: lld/trunk/include/lld/Core/Parallel.h
===================================================================
--- lld/trunk/include/lld/Core/Parallel.h
+++ lld/trunk/include/lld/Core/Parallel.h
@@ -295,7 +295,12 @@
 #else
 template <class Iterator, class Func>
 void parallel_for_each(Iterator begin, Iterator end, Func func) {
-  // TODO: Make this parallel.
+  TaskGroup tg;
+  ptrdiff_t taskSize = 1024;
+  while (taskSize <= std::distance(begin, end)) {
+    tg.spawn([=, &func] { 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.22054.patch
Type: text/x-patch
Size: 614 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150316/59ccebee/attachment.bin>


More information about the llvm-commits mailing list