(*Here is an comparison*)
data = {};
For[n = 1, n < 10, n++,
t1 = Timing[ParallelSum[1/i^2, {i, 1, n*100000}]];
t2 = Timing[HarmonicNumber[n*100000, 2]];
AppendTo[data, {t1[[1]], t2[[1]]}]]

The result is as following which shows the built-in functions always win here.

{{0.432000, 0.192000}, {0.896000, 0.500000}, {1.476000, 
0.860000}, {2.228000, 1.236000}, {3.048000, 1.664000}, {3.956000, 
2.128000}, {4.920000, 2.540000}, {5.932000, 2.936000}, {7.140000, 

The question is: If we rewrite a built-in function with parallelized functions, e.g. rewrite

HarmonicNumber[n*100000, 2]


ParallelSum[1/i^2, {i, 1, n*100000}]

Could we win (in more general case)? If not, then why? And what is the advantage of parallelization? Any help will be appreciated!

  • 2
    $\begingroup$ If you read documentation of core language they have clearly specified that if some API exists to provide some functionality, they are so much so optimized that anything you write will be slower than it.Secondly, is it not possible that if required it can switch to parallel processing own its own. Parallel processing is not helpful in all scenarios, hence used only if problem is breakable."Built-in functions will usually run faster than any compiled Mathematica programs you can create."..reference is reference.wolfram.com/mathematica/tutorial/… $\endgroup$ Aug 11, 2013 at 12:41
  • $\begingroup$ Somewhat related: (1418), (17360) $\endgroup$
    – Mr.Wizard
    Aug 11, 2013 at 13:21
  • $\begingroup$ @Blackbird You should consider posting a excerpt from that tutorial as an answer. $\endgroup$
    – Mr.Wizard
    Aug 11, 2013 at 13:24
  • $\begingroup$ @Mr.Wizard:I agree but it will be repetition of information.I doubt I can write it better than them.Link shall help. $\endgroup$ Aug 11, 2013 at 13:36
  • 2
    $\begingroup$ @Blackbird "We" try to discourage answering in comments; there's nothing wrong with giving a documentation excerpt as an answer if it the most appropriate one available. Of course you can embellish it with additional resources if you find them. $\endgroup$
    – Mr.Wizard
    Aug 11, 2013 at 13:38

1 Answer 1


You are not comparing similar operations. If you do compare same functions, then ParallelSum is clearly faster:

data = {};
For[n = 1, n < 5, n++, 
 t1 = AbsoluteTiming[1/ParallelSum[1/i^2, {i, 1, n*100000}]];
 t2 = AbsoluteTiming[1/Sum[1/i^2, {i, 1, n*100000}]];
 AppendTo[data, {t1[[1]], t2[[1]]}]]

gives (for 4 kernels)

    {{0.554032, 2.482142}, {1.297074, 9.613550}, {2.040117, 
  21.586235}, {2.843163, 37.915397}}
  • $\begingroup$ That's true. But the point is that if we have two ways for a computation on a multicore computer, to use parallelization or to use the built-in function, which one should we choose? Will the built-in functions always be better? $\endgroup$ Aug 11, 2013 at 12:06
  • $\begingroup$ i think your question would be more of a general question on when to use parallel computing. When performing the same operation (e.g., sum vs parallel sum), the parallel version should always win in performance unless the operation involved in each parallel step is too small - this is due to the fact that each parallel call has a small overhead (which is also affected by how your OS distributes the cores and processing power). $\endgroup$
    – Jonie
    Aug 11, 2013 at 12:53
  • $\begingroup$ @EdenHarder:Parallelized version of the built-in function will be better.But if you break it in steps than it will not be. $\endgroup$ Aug 11, 2013 at 12:55
  • $\begingroup$ Yeah, maybe I confused you all. I have updated the question. Thanks all. $\endgroup$ Aug 11, 2013 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.