# Why are there significant differences in efficiency between various instances of ParallelSum?

These four commands

ParallelSum[Prime[i]^2, {i, 1, 10000} ] // AbsoluteTiming
ParallelSum[Prime[i] + Prime[i + 1], {i, 1, 10000} ] // AbsoluteTiming
ParallelSum[ Prime[i] + Prime[i + 1] + Prime[i + 2], {i, 1,  10000} ] //
AbsoluteTiming
ParallelSum[Prime[i] + Prime[i + 1] + Prime[i + 2] + Prime[i + 3], {i, 1,
10000} ] // AbsoluteTiming


gives out nearly the same time.

but when I change 10000 to 100000

ParallelSum[Prime[i]^2, {i, 1, 100000} ] // AbsoluteTiming
ParallelSum[Prime[i] + Prime[i + 1], {i, 1, 100000} ] // AbsoluteTiming
ParallelSum[
Prime[i] + Prime[i + 1] + Prime[i + 2], {i, 1,  100000} ] // AbsoluteTiming
ParallelSum[Prime[i] + Prime[i + 1] + Prime[i + 2] + Prime[i + 3], {i, 1,
100000} ] // AbsoluteTiming


what makes the difference?

• I guess that coupling ParalellSum and Prime is not especially constructive in order to understand the underlying issues. Prime is based on PrimePi which uses so called Lagaris Miller Odlyzko method finding primes. This is a sophisticated algorithm using sparse caching and sieving. You should perform extensive analysis for much larger numbers. There is yet another issue related to Prime which has quite different timings. You should carefully test this post What is so special about Prime? Feb 6, 2020 at 12:07
• Many parameters are automatically chosen in Parallel.... The argument might have a great influence on the parameters. I would suggest forcing as many parameters as possible to ensure a fair comparison. See e.g. mathematica.stackexchange.com/questions/55242/… Feb 6, 2020 at 13:53

Are you interested in rapidly summing primes? or was that just an example to illustrate a ParallelSum question?

If you want fast methods for summing primes please see this question and its answers.

Please note that the following is a much faster way to sum the sequence of 4 adjacent primes, the fourth example in your question.

With[{m = 10000}, AbsoluteTiming[
4*ParallelSum[Prime[i], {i, 1, m + 3}] -
3*(Prime[1] + Prime[m + 3]) -
2*(Prime[2] + Prime[m + 2]) -
(Prime[3] + Prime[m + 1])
]]

• An example to illustrate a ParallelSum question. btw, thx for your code, quite fast. Feb 7, 2020 at 4:14