Visible to Intel only — GUID: GUID-E0EC22B2-FDDF-4340-8B6E-C4E0747626B2
Visible to Intel only — GUID: GUID-E0EC22B2-FDDF-4340-8B6E-C4E0747626B2
Matrix Layout for LAPACK Routines
There are two general methods of storing a two dimensional matrix in linear (one dimensional) memory: column-wise (column major order) or row-wise (row major order). Consider an M-by-N matrix A:
Column Major Layout
In column major layout the first index, i, of matrix elements ai,j changes faster than the second index when accessing sequential memory locations. In other words, for 1 ≤i < M, if the element ai,j is stored in a specific location in memory, the element ai+1,j is stored in the next location, and, for 1 ≤j < N, the element aM,j is stored in the location previous to element a1,j+1. So the matrix elements are located in memory according to this sequence:
{a1,1a2,1 ... aM,1a1,2a2,2 ... aM,2 ... ... a1,Na2,N ... aM,N}
Row Major Layout
In row major layout the second index, j, of matrix elements ai,j changes faster than the first index when accessing sequential memory locations. In other words, for 1 ≤j < N, if the element ai,j is stored in a specific location in memory, the element ai,j+1 is stored in the next location, and, for 1 ≤i < M, the element ai,N is stored in the location previous to element ai+1,1. So the matrix elements are located in memory according to this sequence:
{a1,1a1,2 ... a1,Na2,1a2,2 ... a2,N ... ... aN,1aN,2 ... aM,N}
Leading Dimension Parameter
A leading dimension parameter allows use of LAPACK routines on a submatrix of a larger matrix. For example, the submatrix B can be extracted from the original matrix A defined previously:
B is formed from rows with indices i0 + 1 to i0 + K and columns j0 + 1 to j0 + L of matrix A. To specify matrix B, LAPACK routines require four parameters:
the number of rows K;
the number of columns L;
a pointer to the start of the array containing elements of B;
the leading dimension of the array containing elements of B.
The leading dimension depends on the layout of the matrix:
Column major layout
Leading dimension ldb=M, the number of rows of matrix A.
Starting address: offset by i0 + j0*ldb from a1,1.
Row major layout
Leading dimension ldb=N, the number of columns of matrix A.
Starting address: offset by i0*ldb + j0 from a1,1.