Expand description
Splitting work across threads. [pieces] cuts a call’s items into pieces of the sizes its caller gives, and ranges into as many pieces as the time of its first unit justifies. The pieces run on a Rayon pool with Rayon’s default number of threads: RAYON_NUM_THREADS where it’s set, and otherwise one for each core. set_threads changes that number for the whole process. A call made on one of a pool’s threads, such as a function that another call’s piece runs, doesn’t split again. In the browser build, which has no threads, every call runs its pieces in turn on the calling thread.
Structs§
- Instant
- The clock that
parallel‘s rounds and the speed tests’ timings read: the browser’s in a browser build, wherestd::time::Instantpanics. A measurement of a monotonically nondecreasing clock. Opaque and useful only withDuration. - Shared
- An output slice shared only through disjoint ranges.
- Slots
- The slots of a vector that a writer fills in order: one call’s part of an
extendedvector, or the items thatSlots::appendadds.
Constants§
- PIECE_
TIME - The time on one thread that each piece of a
rangescall is given at least. A call whose pieces would be shorter splits into fewer of them, because waking a thread for a shorter piece costs more than the piece saves. On an M5 Max,v+won a million items, about 200 µs on one thread, took 0.51 copies split across 4 threads and 0.81 across all 18.
Traits§
- Outputs
- A stack’s outputs: a tuple of one to three
Vecs, each holding its own number of items for every cell in turn.stackgives each cell its part of each output, as a QR stack writes Q and R and an SVD stack U, S and V.
Functions§
- each
f(i, scratch)of each celliof a stack ofcountcells, in order, as [each_cell] runs them:stackfor a result of any type, one for each cell.- extended
- Appends
nitems toout, and gives whether every call ofwritesaidtrue.write(range, slots)fillsslotswith the items inrange, in order. The calls split across threads assplitsplits a call, in units ofunititems. A call that leaves any of its slots unfilled panics, andoutkeeps its length. - pieces_
of - Runs
writeon each piece ofsizeitems that cutsout, the last one shorter, across at mostmostthreads as [pieces] runs its ranges, and gives whether every call saidtrue.write(start, items)writesitems, the piece ofoutfromstart. - ranges
- Runs
runon disjoint ranges covering0..n, and gives whether every call saidtrue. Every range runs, even after a failure. Each range contains whole units ofunititems, except that the last unit may be shorter. A call of at most one unit, or one whose calls run on this thread, runs whole on this thread. A longer call times its first unit on this thread, then cuts the rest into as many pieces as that estimate givesPIECE_TIMEeach, at most four for each of this thread’sthreads. It runs them as [pieces] does, or runs the rest in one call on this thread where that gives fewer than two pieces. This non-generic, out-of-line scheduler keeps Rayon’s machinery out of its callers. An empty call runs0..0once. Panics ifunitis zero. - set_
threads - Sets how many threads calls split their work across, for the whole process, and gives the number it replaces. 0 restores the default. 1 runs every call on its calling thread, as the speed tests do for their budgets.
- split
- Runs
write(start, items)over disjoint pieces ofout, usingrangesin units ofunititems, and gives whether every call saidtrue. An empty output callswriteonce. Panics ifunitis zero. - stack
- Runs
write(i, parts, scratch)on each celliof a stack ofcountcells, as [each_cell] runs them, and gives the outputs with whether every call saidtrue.partsis celli’s part of each outputk:per[k]items fromi * per[k]. - summed
- Adds the sums of every piece of
0..nintosums, wherepiece(range, sums)adds the sums of the piecerangeinto thesumsit’s given.0..nsplits into one piece of at leastleastitems for each of this thread’sthreads. With too few items for two pieces,0..nruns as one piece on this thread. Otherwise the first piece adds intosums, each later one into its own part ofparts, and the parts then add intosumson this thread. - summed_
of summedover the units ofitems, each ofunititems, wherepiece(first, items, sums)gets the items of the piece whose first unit isfirst.- thread_
setting - The number that
set_threadslast set. It starts at 0, the default. - threads
- How many threads the calls made on this thread split their work across: the process’s
set_threadscount, or 1 on a pool’s worker thread.