-1
$\begingroup$

This question already has an answer here:

Here is two test to understand the parallelize in Mathematica:

Table[{x,y,x}, {x,300}, {y,300}, {z,300}];//AbsoluteTiming
{2.39232, Null}

Parallelize[Table[{x,y,x}, {x,300}, {y,300}, {z,300}]];//AbsoluteTiming
{11.5578, Null}

ParallelTable[{x,y,z}, {x,300}, {y,300}, {z,300}]; // AbsoluteTiming
{11.5914, Null}

Here the parallelize get more time! Why and how to parallelize a loop?

$\endgroup$

marked as duplicate by Simon Woods, Sjoerd C. de Vries, Yves Klett, m_goldberg, dr.blochwave Dec 13 '15 at 17:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1
$\begingroup$

In this kind of simple example, the communication time of parallization is much larger than the time it is trying to save.

$\endgroup$
  • $\begingroup$ So, how to parallelize such loop in Mathematica. Because, we can do it in C/C++ for example $\endgroup$ – BetterEnglish Dec 13 '15 at 6:00
  • 1
    $\begingroup$ It is parallized, but the performance of the implementation is worse than the performance of the single-threaded one. $\endgroup$ – Yves Klett Dec 13 '15 at 7:30
  • 2
    $\begingroup$ @Developer2000 many people think: it's parallelized, so it should be faster. But this isn't true. Parallelization isn't for free; it involves some overhead that is not present in the serial calculation. This is especially true in Mathematica, where the Parallel` package is written entirely in top-level code, and communication is via MathLink. It can be compared to MPI, rather than threading, but even slower because MathLink is not carefully tuned for latency and bandwidth. Unless you're very careful, Amdahl's law completely kills you. $\endgroup$ – Oleksandr R. Dec 13 '15 at 20:26
  • $\begingroup$ @OleksandrR. Thanks, it is a good answer $\endgroup$ – BetterEnglish Dec 13 '15 at 20:49
  • $\begingroup$ @OleksandrR. Thanks I learned a lot as well. $\endgroup$ – Yidan Dec 13 '15 at 23:56

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