See this page:
Parallel overhead. There is overhead in calling parfor instead of for. If function evaluations are fast, this overhead could become appreciable. In particular, solving a problem in parallel can be slower than solving the problem serially.
The tip is not to use parfor when each iteration is not time-consuming; the limit of processing cost is of course dependant of your hardware.
EDIT: if you remove the if-else block, the behavior of the loop changes. sum_all
is now detected as a reduction variable, as it is explained in this page. The loop is then correctly broken into independent parts; the partial results are merged at the end. With the if-else block, sum_even
and sum_odd
are not considered as reduction variables (I think), so it will behave like a classic for-loop plus the parallel computing overhead.