Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
6536 Discussions

MKL clapack - leading dimension when data is in row-major order?

Michael_B_19
Beginner
571 Views
Hi. I hope this isn't too basic of a question, but I am interested in trying out the clapack interface, and there is something that is not quite clear to me in the documentation.
Suppose I want to use the dtrtrs function to solve AX=B when A is triangular. Both A and B are stored in row-major order. In the parameter arguments, the routine asks for the leading dimensions of A and B (lda and ldb). This makes sense when matrices are in column-major order, but if they are in row-major, the number of rows in the array doesn't really tell the routing anything. Shouldn't I be reporting the trailing dimension (number of columns in the array) instead?
Thanks so much for your help.
Michael
0 Kudos
1 Solution
Alexander_K_Intel3
571 Views

Hi Michael,

You are right ifyou have N columns in your matrix A, thenLDA=N for row-major case.

In general leading dimension is equal to the number of elements in major dimension.Also it isequal to the distance in elements between two neighbor elements in a line of minor dimension.

Thusif you have no extra elements in your matrix with M rows and N columns, then:
- In row-major case: row ilays in memory right after row i-1and thus LDA=N - number of elements in row.
- In column-major case: column ilays in memory right after column i-1and thus LDA=M - number of elements in column.

If you refer to a submatrix ( m x n )then you use as leading dimension the number of elements in major dimension of the whole matrix (as above)whilem andn in subroutine's inputparametersdescribes the size of the submatrix.



You are welcome.
Alexander.

View solution in original post

2 Replies
Alexander_K_Intel3
572 Views

Hi Michael,

You are right ifyou have N columns in your matrix A, thenLDA=N for row-major case.

In general leading dimension is equal to the number of elements in major dimension.Also it isequal to the distance in elements between two neighbor elements in a line of minor dimension.

Thusif you have no extra elements in your matrix with M rows and N columns, then:
- In row-major case: row ilays in memory right after row i-1and thus LDA=N - number of elements in row.
- In column-major case: column ilays in memory right after column i-1and thus LDA=M - number of elements in column.

If you refer to a submatrix ( m x n )then you use as leading dimension the number of elements in major dimension of the whole matrix (as above)whilem andn in subroutine's inputparametersdescribes the size of the submatrix.



You are welcome.
Alexander.

Michael_B_19
Beginner
571 Views
Thank you, your answer is crystal clear. But is this a standard interpretation? I ask because I often use the GSL library, for which all arrays are in row-major order, and what you are calling the leading dimension, GSL calls the trailing dimension. I'm wondering why the discrepancy, or whether some clarification in the documentation might be appropriate.
In any event, I now know what to do when using MKL. Thanks again.
Reply