6
$\begingroup$

In good old Mathematica versions (5.2, 6.0), matrix multiplication was automatically done in parallel. For example, on an 8-core machine, define two square real matrices:

m1 = Table[Random[Real], {256}, {256}];
m2 = Table[Random[Real], {256}, {256}];

The total CPU time used in all cores to compute a dot product is:

Tsingle = Timing[m1.m2][[1]]

0.010999 Second

The real time needed for the calculation is:

Tparallel = AbsoluteTiming[m1.m2][[1]]

0.001546 Second

For large matrices, the ratio is almost equal to the number of cores (8):

Tsingle / Tparallel

7.114489004

Repeating the same calculation in newer Mathematica versions (8.0, 9.0) gives Tsingle equal to Tparallel, which seems to indicate that new Mathematica versions dropped automatic parallelization of the Dot command. Is this true?
I would be thankful if anyone can advise how to regain this functionality, i.e. compute Dot products in parallel (automatically or manually).

$\endgroup$
2
  • 2
    $\begingroup$ This may be due to changes in how timing works, see the documentation: "On certain computer systems with several CPUs, the Mathematica kernel may sometimes spawn additional threads on different CPUs. On some operating systems, Timing may ignore these additional threads. On other operating systems, it may give the total time spent in all threads, which may exceed the result from AbsoluteTiming." $\endgroup$
    – s0rce
    Commented Nov 2, 2013 at 23:22
  • 3
    $\begingroup$ It is still done in parallel, but you should use RandomReal and not Table because the former produces a packed array while the latter does not. By the way, a 256-by-256 matrix is not really big enough for parallelization to be particularly noticeable, so you should test with a larger matrix as well. For any remaining discrepancies, I agree with @s0rce's comment. $\endgroup$ Commented Nov 2, 2013 at 23:24

1 Answer 1

2
$\begingroup$

Not really an answer but too long for a comment, Timing doesn't appear different then AbsoluteTiming, I have 9.0.1 on Win7 x64.

n = 2^12;
m1 = RandomReal[1, {n, n}];
m2 = RandomReal[1, {n, n}];
Tsingle = Timing[m1.m2;][[1]]
Tparallel = AbsoluteTiming[m1.m2;][[1]]
Tsingle/Tparallel
1.435209
1.589091
0.90316
$\endgroup$

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.