I use to compute primes using linear code which took a long time. As I've an 8 cores processor I thought about multi-threading.
At first I use to put a huge number of int in a vector then share the vector between the threads which takeout each number which is not a prime. The first thread processed the 1st/nthread part, the second processed the 2nd/nthread and so on. Which leads me to a resource issue due to concurrent access.
Then I tried to split the vector in nthread vectors to give one vector to each thread, removing concurrent access issue. But I'm not convinced that it's the best way to do it since processing the primes from 1 to 10 000 is faster than processing primes form 10 001 to 20 000.
- Is there a better way to take profit of the multi-threading ?
- If no, what is the best way to split vectors so the thread would take the same time ?