# CPU timing for matrix rank calculation difference between 10.3 and 10.4 and 11.0

I run a small rank CPU test when new Mathematica version comes out. I noticed when version 10.1 came out that Mathematica rank calculation suddenly became extremely fast on a matrix when the size became over 2500 by 2500. (link at the very end). Here is from the link:

Mathematica 10.1 was surprisingly much faster on this test than 10.0.2. It seems Mathematica 10.1 is using different algorithm to compute the rank now to account for this drastic difference in speed improvement.

The speed boost was observed to occur at certain matrix size. At matrix size of 2500 or less, the same speed was obtained as with version 10.0.2. At matrix size over 2500, even by just one, a dramatic speed increase was seen. For n = 2500 Mathematica CPU was around 4.6 seconds which is the same as in 10.0.2, but by increasing the matrix size to n = 2501 , CPU time went down to about 1.4 seconds. This is 3 times as fast for essentially the same matrix size. This result was reproducible. This seems to indicate that Mathematica internally uses the same algorithm as previous version for smaller size matrices, and then switches to different algorithm for larger matrices.

The above was the case on windows up to 10.3.

Suddenly, in 10.4 and 11, this sudden speed up in rank calculation went away, and the CPU time went back to what it was before version 10.

Would some one be able to explain what happened to the speed improvement? and why now Mathematica is slower on this test than on 10.3? This is all on same PC, all on 64 bit windows 7.

This is the source code for the test

Remove["Global*"];
$HistoryLength = 0; Share[]; n = 2500; m = RandomReal[{}, {n, n}]; AbsoluteTiming[MatrixRank[m];]  Here is the result. Notice the speed up when the size becomes 2501 ## version 10.3 ## version 11 Similar result for 10.4 as above. So something changed between 10.3 and 10.4 which carried over to 11. The full detailed report can be found here Added data: size = Range[500, 8000, 500]; ver10 = {0.03, 0.14, 0.65, 2.15, 4.66, 2.25, 3.42, 4.98, 6.97, 8.8, 9.66, 12.81, 14.7, 17.82, 22.49, 27.04}; ver11 = {0.024, 0.134, 0.616, 2.033, 4.505, 8.393, 13.865, 22.088, 30.846, 43.079, 58.216, 75.655, 96.048, 120.505, 148.593, 180.311}; data = Transpose[{size, ver10, ver11}] Grid[Join[{{"N", "version 10.1 CPU", "version 11 CPU"}}, data], Frame -> All] p1 = ListPlot[Transpose@{size, ver10}, Mesh -> All, Joined -> True, PlotStyle -> Green, Frame -> True, FrameLabel -> {{"CPU time (sec)", None}, {"Matrix size", "Comparing CPU time for rank calculation"}}]; p2 = ListPlot[Transpose@{size, ver11}, Mesh -> All, Joined -> True, PlotStyle -> Red]; Show[p1, p2, PlotRange -> All]  UPDATE I think I have found something very important and I have a theory about what has happened. I run the rank test now on Matlab 2016a and also on Maple 2016, and discovered that the speed boost now is present in both Maple and Matlab. This tells me that the speed boost in rank calculation came from external library, which would be intel MKL math library which all three M's link to. So the speed boost happend before in Mathematica, simply because 10.3 was shipped linked to that library. Now the newer versions of Maple and Matlab are also linked to it. This is why the speed boost did not show up in the earlier versions of Maple and Matlab I used when I run the test before. The question then, why did the speed boost go away in 10.4 and 11.0? The only thing that could explain this, is that Mathematica is not linked to the current intel MKL math library which had this speed in rank calculations? What else could explain this? Here is Maple result and Matlab result with the new versions. Notice the sudden speed in rank calculation now, the same as used to be with 10.3 and at the same exact size: All on same PC, all 64 bit. Maple 2016.1: Matlab 2016a: >> clear all; n=2500; A=rand(n,n); tic();rank(A);toc() Elapsed time is 4.549381 seconds. >> clear all; n=2501; A=rand(n,n); tic();rank(A);toc() Elapsed time is 1.436199 seconds. >>  Question is: Is Mathematica 11 linked to the correct/latest intel MKL library on windows? What does the test show on mac with version 11? I need now to try to find out what intel MKL library Mathematica 11 in linked to and compare that to 10.3 Update Here is more information. It seems the MKL version 11.2 had the speed boost in it based on checking the MKL DLL file version on the CAS I have. And that MKL 11.3 do not have this speed boost for some reason. This is assuming the issue is to due to MKL From the above one can see that when MKL 11.2 is used, the three M's had fast rank calculations for Matrix size over 2500. Mathematica 10.4 and 11 changed from MKL 11.2 to 11.3 and I am guessing this is the reason why rank got slower. This is only a theory ofcourse. • You don't mention whether or not the calculated MatrixRank[] is actually correct in$v\le10.3\$. – Feyre Sep 3 '16 at 9:07
• I think you should contact the WRI:). – xyz Sep 3 '16 at 10:19
• @Nasser I'm not saying it's not, my first though was just maybe there was a bug which was fixed. – Feyre Sep 3 '16 at 10:42
• I think it is reasonable to assume that RandomReal[{}, {n, n}] will have full rank (i.e. n`) with very, very high probability. – mikado Sep 3 '16 at 11:36
• Hi, I enjoyed reading your benchmark webpage and this post. Am I correct in concluding from your study that the slowdown in Mathematica 11 is actually due to the update in MKL? Finally, since Mac computers now use Intel processors, does that mean Mathematica on Mac also exhibits this slowdown? Thanks! – QuantumDot Oct 2 '16 at 14:44