![]() Your CPU is twiddling its thumbs while this iteration occurs. The 4th addition must wait for the 3rd, and 3rd must wait for the 2nd. C code is still processing this code in an iterative first-in-first out queue-like way. Vectorized code like this is usually good-enough for typical tasks, but if extracting every rev of horsepower from your Alienware's QUAD-CHIP 32-Core hyperthreaded CPU is mission critical, keep reading.ĭon't make the mistake of saying this code is "multi-threaded" or "multi-core" because it's not. Operations performed in a vectorized way like this above are between 2 and 5 orders of magnitude faster than if you put this in a for loop. This arrayfun code is "vectorized", and GNU Octave packages this code to be handed to pre-optimized C code rather than having GNU Octave manage its own glacial iteration. Down straight to multi-core and multi-thread optimization on the bare metal: PROTIP: Why this code on a sufficiently large matrix won't max out your quad-core CPU.īelow is an analysis of the arrayfun's capabilities from the perspective of Vectorization down through lowlevel C. Notice how the procedure (add 5) was applied to each item in the matrix. Put this code in filename called "main.m" ) Put this code in filename called "myfun.m" function = myfun(num)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |