Skip to main content

Module parallel

Module parallel 

Source
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, where std::time::Instant panics. A measurement of a monotonically nondecreasing clock. Opaque and useful only with Duration.
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 extended vector, or the items that Slots::append adds.

Constants§

PIECE_TIME
The time on one thread that each piece of a ranges call 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+w on 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. stack gives 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 cell i of a stack of count cells, in order, as [each_cell] runs them: stack for a result of any type, one for each cell.
extended
Appends n items to out, and gives whether every call of write said true. write(range, slots) fills slots with the items in range, in order. The calls split across threads as split splits a call, in units of unit items. A call that leaves any of its slots unfilled panics, and out keeps its length.
pieces_of
Runs write on each piece of size items that cuts out, the last one shorter, across at most most threads as [pieces] runs its ranges, and gives whether every call said true. write(start, items) writes items, the piece of out from start.
ranges
Runs run on disjoint ranges covering 0..n, and gives whether every call said true. Every range runs, even after a failure. Each range contains whole units of unit items, 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 gives PIECE_TIME each, at most four for each of this thread’s threads. 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 runs 0..0 once. Panics if unit is 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 of out, using ranges in units of unit items, and gives whether every call said true. An empty output calls write once. Panics if unit is zero.
stack
Runs write(i, parts, scratch) on each cell i of a stack of count cells, as [each_cell] runs them, and gives the outputs with whether every call said true. parts is cell i’s part of each output k: per[k] items from i * per[k].
summed
Adds the sums of every piece of 0..n into sums, where piece(range, sums) adds the sums of the piece range into the sums it’s given. 0..n splits into one piece of at least least items for each of this thread’s threads. With too few items for two pieces, 0..n runs as one piece on this thread. Otherwise the first piece adds into sums, each later one into its own part of parts, and the parts then add into sums on this thread.
summed_of
summed over the units of items, each of unit items, where piece(first, items, sums) gets the items of the piece whose first unit is first.
thread_setting
The number that set_threads last 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_threads count, or 1 on a pool’s worker thread.