[all-commits] [llvm/llvm-project] 10a796: [Support] Avoid using main thread for llvm::parall...

avl-llvm via All-commits all-commits at lists.llvm.org
Wed Jan 25 03:48:05 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 10a796a0beb22ec604b3038b544cc9058facea79
      https://github.com/llvm/llvm-project/commit/10a796a0beb22ec604b3038b544cc9058facea79
  Author: Alexey Lapshin <a.v.lapshin at mail.ru>
  Date:   2023-01-25 (Wed, 25 Jan 2023)

  Changed paths:
    M llvm/lib/Support/Parallel.cpp

  Log Message:
  -----------
  [Support] Avoid using main thread for llvm::parallelFor().

The llvm::parallelFor() uses threads created by ThreadPoolExecutor as well as main thread.
The index for the main thread matches with the index for the first thread created by ThreadPoolExecutor.
It results in that getThreadIndex returns the same value for different threads.
To avoid thread index clashing - do not use main thread for llvm::parallelFor():

parallel::TaskGroup TG;
for (; Begin + TaskSize < End; Begin += TaskSize) {
  TG.spawn([=, &Fn] {
    for (size_t I = Begin, E = Begin + TaskSize; I != E; ++I)
      Fn(I);
  });
}
for (; Begin != End; ++Begin)    <<<< executed by main thread.
  Fn(Begin);                     <<<<
return;                          <<<<

Differential Revision: https://reviews.llvm.org/D142317




More information about the All-commits mailing list