pub fn hash_multithreaded(mode: Mode<'_>, input: &[Block], len: usize) -> HashExpand description
hash, eligible to use other CPU cores above the split threshold:
always the same Hash as single-threaded hash. For a
message whose bytes are not in blocks (a mapped file, say),
update_multithreaded into a Hasher takes any slice, at the same
speed on the i7-12700K from 512 KiB to 1 GiB (about 1% slower at 1 MiB).
use blake3_servil::{Mode, throughput::{self, Block}};
let message = vec![Block::ZERO; 1 << 14];
let hash = throughput::hash_multithreaded(Mode::Plain, &message, 1 << 20);
assert_eq!(hash, blake3_servil::convenience::hash(&[0u8; 1 << 20]));Speed, on an Apple M4 Max (16 cores): below 512 KiB (an
implementation heuristic, not a frozen contract) it hashes on the
calling thread, at hash’s speed; from 512 KiB it is eligible to
use available worker threads too: about 14 GB/s at 1 MiB, 21 GB/s
at 4 MiB, and 26 to 29 GB/s from 16 MiB, 2 to 5 times
hash. Idle workers park between calls
and use no CPU once parked.
Several callers at once: calls from several threads of one program
share the cores in turn, each getting a fair part; a call that finds the
cores all busy hashes on its own thread, at hash’s speed.
CPUs with performance and efficiency cores (Intel’s since Alder
Lake): a multithreaded call or stream uses every core, and afterwards
the OS sometimes leaves the calling thread on an efficiency core for a
while, where single-threaded hashing runs at about half speed (AVX2’s
256-bit operations run as two halves there). Measured on an i7-12700K
under Linux 7.0: beside nonstop multithreaded streams, 7% of 16 KiB
single-threaded hashes ran partly on an efficiency core, 2.2 times
slower, about 6% on their average. A program that alternates the two
and needs its single-threaded speed steady can keep that thread on the
performance cores (sched_setaffinity on Linux).
The program calls initialize_multithreaded first; a call before it
panics.