1
$\begingroup$

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?

$\endgroup$
7
  • $\begingroup$ What does it mean to add two matrices with different dimensions? $\endgroup$
    – hardmath
    Commented Jul 10, 2012 at 13:19
  • $\begingroup$ 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 $\endgroup$ Commented Jul 10, 2012 at 13:40
  • $\begingroup$ 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)? $\endgroup$
    – hardmath
    Commented Jul 10, 2012 at 14:16
  • $\begingroup$ 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. $\endgroup$ Commented Jul 10, 2012 at 14:31
  • 1
    $\begingroup$ 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. $\endgroup$
    – hardmath
    Commented Jul 10, 2012 at 15:19

2 Answers 2

3
$\begingroup$

Just write the loop code and forget about BLAS here. Adding two matrices is bandwidth-limited and the compiler will likely do as good a job as the BLAS implementation in this case.

$\endgroup$
2
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.