On Thursday, September 17, 2015 at 11:38:29 PM UTC-4, Patrick Kofod 
Mogensen wrote:
>
> Yes, I did indeed just notice I had made a mistake with the ;.
>
> My state spaces typically have more than two values, so they're more 
> likely hundreds-by-hundreds instead of 2-by-2.
>
> What does the "right dimensions for locality" mean? Are you referring to 
> the memory addresses (to make sure I'm not jumping all over the place) or 
> what does "locality" mean in this context? Sorry if this is basic stuff.
>

Suppose you are concatenating all of your little MxM matrices F1, F2, 
etcetera into a single matrix F.  You can either concatenate vertically 
into an (N*M)xM matrix Fv = [F1; F2; ...] or horizontally into an Mx(N*M) 
matrix Fh = [F1 F2 ...].  Which one you do has a big effect on spatial 
locality (see e.g. https://en.wikipedia.org/wiki/Locality_of_reference), 
which affects how fast you can access the data because of cache lines.

When you are accessing the n-th matrix Fm[i,j], in Fv you would do Fv[n*M-1 
+ i, j] and in Fh you would do Fh[i, n*M-1 + j].

Julia uses column-major order for its matrices, which means that matrices 
are stored in memory with contiguous columns, one after another.   That 
means Fh stores each matrix Fm as a contiguous block of M*M memory 
elements, which is fast to access, whereas in Fv it is stored as 
discontiguous chunks (each column of Fm is offset from the next column by 
(N-1)*M memory items), which is slower to access.

None of this affects you if you are using an array of arrays; in that case 
each of the sub-arrays is stored contiguously.

Reply via email to