First, the msdn/sun articles explicitly make his point:
"For example, consider the following (naïve) matrix multiplication routine"
"This is a very simple example and, if you really want a good matrix multiply routine, you will have to consider cache effects, or use a better algorithm"
Second, all three versions (his, msdn, and sun) are doing different things.
- His version increments in to C[i,j], but C is never initialized anywhere so who knows what it's calculating
- msdn's version intializes result[i,j] to 0 and increments in to it (impossible with his version because he moved the loop that initalizes the result down to the lowest loop)
- Sun's version is using the same array for everything, and assigning to array[i,j]
If this was an example of making cache aware algorithms, he gave no explanation of how to do it.
If this was an example of writing a really fast correct matrix multiply, he didn't do that either as his sums in to uninitialized data.
If this was an example of why showing users how to parallelize for loops is a bad idea because it's too simple and nobody will ever need to do that, he really should've gotten his example correct to demonstrate how easy it is.
I really can't tell what led to this article other than he noticed that the code ran faster when you flipped the loops and decided to write _something_ about it.
The multiply itself is not being changed. Rather, the order in which the elements in the matrices are being multiplied is changed. The results will be the same.
4 comments
[ 3.0 ms ] story [ 15.7 ms ] thread"For example, consider the following (naïve) matrix multiplication routine"
"This is a very simple example and, if you really want a good matrix multiply routine, you will have to consider cache effects, or use a better algorithm"
Second, all three versions (his, msdn, and sun) are doing different things.
- His version increments in to C[i,j], but C is never initialized anywhere so who knows what it's calculating
- msdn's version intializes result[i,j] to 0 and increments in to it (impossible with his version because he moved the loop that initalizes the result down to the lowest loop)
- Sun's version is using the same array for everything, and assigning to array[i,j]
If this was an example of making cache aware algorithms, he gave no explanation of how to do it.
If this was an example of writing a really fast correct matrix multiply, he didn't do that either as his sums in to uninitialized data.
If this was an example of why showing users how to parallelize for loops is a bad idea because it's too simple and nobody will ever need to do that, he really should've gotten his example correct to demonstrate how easy it is.
I really can't tell what led to this article other than he noticed that the code ran faster when you flipped the loops and decided to write _something_ about it.