-1
$\begingroup$

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$
0

1 Answer 1

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$
5
  • $\begingroup$ So, how to parallelize such loop in Mathematica. Because, we can do it in C/C++ for example $\endgroup$ Dec 13, 2015 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, 2015 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$ Dec 13, 2015 at 20:26
  • $\begingroup$ @OleksandrR. Thanks, it is a good answer $\endgroup$ Dec 13, 2015 at 20:49
  • $\begingroup$ @OleksandrR. Thanks I learned a lot as well. $\endgroup$
    – Yidan
    Dec 13, 2015 at 23:56

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