Parallelization of Prime Generation Slows Performance
In the src/test.rs
file, the is_prime_mem()
function has the issue that when using parallelization it runs significantly slower than it would otherwise. The code is as follows:
// parallel
let compound = primes.par_iter().take(pp).any(|x| n % x == 0);
// sequential
let compound = primes.iter().take(pp).any(|x| n % x == 0);
This function is primarily used when generating primes, though also when testing primes, importing previously calculated primes from memory. The problem is likely due to the program having to create threads and destroy them for every single prime test (i.e. for every prime generated). I don't think there's a good solution within this scope, but perhaps by abstracting the parallelization outward so each thread is testing a different prime, we can manage to avoid this bottleneck.