On 1/23/23 12:06, H. S. Teoh wrote:

> `.parallel` -- it's basically zero cost.  And for script-like helper
> utilities, .parallel is just the thing you need to get the job done in
> the shortest amount of time possible.  No need for anything more
> elaborate.

Yes! :)

As a heads up to those who haven't tried it yet, there are cases that may benefit from reducing the work unit size from its default value of 100.

Especially when it's about file processing and there are a few files that take disproportionate amount of processing time, then the thread that is working on the largest file(s) would be holding on to 99 others to process them later in serial fashion. This may happen when the other e.g. 20 threads have already finished their tasks.

So, I recommend experimenting with smaller work unit sizes; I currently use 1 for such file processing. Something like this:

  auto tp = new TaskPool(totalCPUs / 2);   // Thread count
  foreach (e; tp.parallel(elements, 1)) {  // Work unit size
    // ...
  }
  tp.finish(); // Don't forget

as seen here:

  https://youtu.be/dRORNQIB2wA?t=1692

Ali

  • D Language Fo... Mike Parker via Digitalmars-d-announce
    • Re: D La... Richard (Rikki) Andrew Cattermole via Digitalmars-d-announce
    • Re: D La... Sergey via Digitalmars-d-announce
      • Re: ... Mike Shah via Digitalmars-d-announce
    • Re: D La... Adam D Ruppe via Digitalmars-d-announce
    • Re: D La... ryuukk_ via Digitalmars-d-announce
    • Re: D La... H. S. Teoh via Digitalmars-d-announce
    • Re: D La... Adam D Ruppe via Digitalmars-d-announce
      • Re: ... H. S. Teoh via Digitalmars-d-announce
      • Re: ... Hipreme via Digitalmars-d-announce
    • Re: D La... Ali Çehreli via Digitalmars-d-announce
    • Re: D La... Siarhei Siamashka via Digitalmars-d-announce
      • Re: ... Walter Bright via Digitalmars-d-announce
    • Re: D La... Johan via Digitalmars-d-announce
      • Re: ... Paul Backus via Digitalmars-d-announce
      • Re: ... Walter Bright via Digitalmars-d-announce

Reply via email to