# BLAS/LAPACK subroutine to add two matrices with different offsets and leading dimensions

I currently searching for a subroutine from BLAS or LAPACK which realizes the following operation

A = alpha*A + beta * B


where A and B have different leading dimensions, i.e. A is stored as

 REAL*8 A(N,N)


and B is stored as

 REAL*B B(LDB,N)


with LDB > N.

Is there a way to use existing BLAS or LAPACK operation to compute this or must I create an own subroutine for this kind of problems?

• What does it mean to add two matrices with different dimensions? – hardmath Jul 10 '12 at 13:19
• It is only the leading dimension, the means the length of a column in the Fortran storage format, i.e. the in memory distance between two elements of the same row – M.K. aka Grisu Jul 10 '12 at 13:40
• I'm aware that Fortran stores 2D arrays in column major order. Wouldn't the question be clearer if A = alpha*A + beta * B were replaced by the nested do-loop that tells which expressions are to be added to assign A(I,J)? – hardmath Jul 10 '12 at 14:16
• Replacing this by a nested do-loop or the quick-and-dirty Fortran-code which does the same job, does not help understanding the problem. The leading dimension problem can be handle by Fortran directly so the code does not point out the problem. Currently I use such a code but I'm interested if there is a efficient way using the standard linalg libraries. – M.K. aka Grisu Jul 10 '12 at 14:31
• I'm suggesting the nested do-loop not as a solution, but as a meaningful way to phrase the question. A = alpha*A + beta * B doesn't convey what you mean, though I'm sure the meaning is so clear in your mind you have difficulty seeing that it becomes a guessing game for me. – hardmath Jul 10 '12 at 15:19

The best you can do is to use the BLAS AXPY on each column, but that doesn't let you apply beta. You really might as well write your own since this is basically a level 1 or 2 BLAS operation, which for large matrices is memory bandwidth limited.