Matlab JIT engine nested loops data type
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
In the textbook "Matlab programming for engineers" by S.Chapman (4th edition) it is stated that (see pp. 165-166)
- The JIT compiler only accelerates loops containing double, logical, and char data types (plus integer data types that we haven’t met yet). If other data types such as cell arrays or structures appear in the loop, it will not be accelerated.
- If an array in the loop has more than two dimensions, the loop will not be accelerated.
I would like to know if the information provided above is still accurate (I am using the newest Matlab release, R2021a).
2 Kommentare
Stephen23
am 31 Aug. 2021
Bearbeitet: Stephen23
am 31 Aug. 2021
You did not write the date of publication, but according to this link
the sixth edition was updated for R2018a. I suspect that this means the fourth edition does not even include the totally new Execution Engine that was introduced with R2015b (and will differ even more from your R2021a):
Unless the author has a very honored relationship with TMW it is unlikely that they have any such knowledge about unpublished JIT/Execution Engine behavior of the kind that you asked about. You should simply assume that any printed MATLAB guide is outdated the day after it is published.
Akzeptierte Antwort
Jan
am 30 Aug. 2021
Bearbeitet: Jan
am 31 Aug. 2021
This is a good question. Matlab's JIT was partially documented in Matlab 6.5 (2001), but afterwards MathWorks avoided to publish details. They have the good reason, that publishing details of the JIT would motivate users to adjust their programs to the JIT, but they want to adjust the JIT to the programs.
Some tests might show, that the mentioned limitations are not matching anymore.
function s = stupidTest(x)
s = 0;
for k = 1:numel(x)
s = s + x(k);
end
end
Calling this with 2D arrays has the same speed as with 3D arrays, if the number of elements is equal.
Impeding the JIT on purpose slows the code down, e.g. by s = eval('0');
Yes, the test case is very basic. But I'd avoid to adjust the code too much to assumed properties of the JIT.
4 Kommentare
DGM
am 2 Sep. 2021
Bearbeitet: DGM
am 2 Sep. 2021
I figured I'd give it a whirl, since I'm perpetually out-of-date and able to share the perspective that comes with running older versions.
Out of the gate, I don't have enough memory to wrangle that large of a DPFP array without being pushed into swap:
800x800x800 R2019b
Using command sum:
Elapsed time is 47.013714 seconds.
Using linear index, i.e. only one loop:
Elapsed time is 177.289160 seconds.
Using subscripts, i.e. 3 nested loops:
Elapsed time is 197.953229 seconds.
I know well enough that switching to single precision often slows things down, memory usage aside. I decided to try with a smaller array to keep away from swap usage, but my experience is still the opposite of yours for R2019b and R2015b:
600x R2019b
Using command sum:
Elapsed time is 0.133028 seconds.
Using linear index, i.e. only one loop:
Elapsed time is 2.440955 seconds.
Using subscripts, i.e. 3 nested loops:
Elapsed time is 2.539198 seconds.
600x R2015b (using sum(A(:)) )
Using command sum:
Elapsed time is 0.136865 seconds.
Using linear index, i.e. only one loop:
Elapsed time is 4.313646 seconds.
Using subscripts, i.e. 3 nested loops:
Elapsed time is 7.171336 seconds.
But look at good old R2009b doing its own thing:
600x R2009b (using sum(A(:)) )
Using command sum:
Elapsed time is 0.204012 seconds.
Using linear index, i.e. only one loop:
Elapsed time is 4.270620 seconds.
Using subscripts, i.e. 3 nested loops:
Elapsed time is 2.084054 seconds.
I don't know if I'd contribute this all to version differences. Hardware and environment matter too.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!