2

I'm a fortran beginner and simply wanted to try if i get a matrix multiplication to work.

    program testlapack
    implicit none

    COMPLEX, DIMENSION(2, 2) :: A, B, Output

    A = reshape((/ 4, 0, 0, 2 /), shape(A))
    B = reshape((/ 6, 0, 0, 3 /), shape(B))
    Output = reshape((/ 1, 0, 0, 1 /), shape(Output))

    call DGEMM('n','n',2,2,2,1.0,A,2,B,2,0.0,Output,2)

    Write(*,*) Output

    end program testlapack

I was expecting a simple A * B multiplication written into the Output-array. Instead, lapack is returning a 2x2 matrix with only zeros. The compilation with ifort -llpack yields no errors.

Where's my problem? Thanks

2 Answers 2

2

I suspect that passing complex arguments to a subroutine expecting real arguments might be the cause of your problem. Perhaps you meant to use zgemm rather than dgemm ?

Sign up to request clarification or add additional context in comments.

1 Comment

This was certainly a good guess, and thanks. But it wasn't the only reason, the output has not changed :(
1

I changed the matrices to REAL and used DGEMM. It worked once i used double precision for every number entering DGEMM, including the 1.0 set as "ALPHA". I didn't expect this to be mandatory.

2 Comments

That makes sense, given that the D in DGEMM means "double;" if you wanted single precision, you want the routine SGEMM.
Note that there's also CGEMM for complex numbers. netlib documentation

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.