'How to use Intel fortran compiler with MKL on command line

I've freshly installed the Intel® Parallel Studio XE Composer Edition for Fortran OS X* (student version). It comes with the Math Kernel Library, which is why I bought it. I'm having a hard time getting started with MKL. Here's what I've done step-by-step.

1) Installed Intel® Parallel Studio XE Composer Edition for Fortran OS X* (no problem). I can run a 'hello world' script using ifort and throw the -mkl link command on at the end with no problem (not calling any mkl commands just yet).

2) Following these instructions I set my environment variables using a script provided by intel (located in opt/intel/bin to be precise). I have the intel 64-bit architecture (according to ifort -V) so I use bash mklvars.sh intel64 mod ilp64. It runs without error (or any output).

3) I write the following code to use MKL's gemm command for fortran95. Just multiplying 2 matrices.

program test

implicit none
real, dimension(2,2) :: testA, testB, testC

testA = 1
testB = 1
testC = 0  ! I don't think I need this line, but it shouldn't matter

call gemm(testA, testB, testC)

write(*,*) testC

end program test

4) I compile with ifort test_mkl.f90 -o test -mkl. I get the following error:

Undefined symbols for architecture x86_64:
  "_gemm_", referenced from:
      _MAIN__ in ifortSTVOrB.o
ld: symbol(s) not found for architecture x86_64

5) I try ifort test_mkl.f90 -o test -L/opt/intel/mkl/lib -mkl and get the same result.

I notice a lot of people using MKL begin their code with USE mkl95_blas, ONLY: gemm, so I put that in above implicit none in both of the above examples and get:

    test_mkl.f90(4): error #7002: Error in opening the compiled module file.  Check INCLUDE paths.   [MKL95_BLAS]
    USE mkl95_blas, ONLY: gemm
--------^
test_mkl.f90(12): error #6406: Conflicting attributes or multiple declaration of name.   [GEMM]
    call gemm(testA, testB, testC )
---------^
test_mkl.f90(4): error #6580: Name in only-list does not exist.   [GEMM]
    USE mkl95_blas, ONLY: gemm
--------------------------^
compilation aborted for test_mkl.f90 (code 1)

Any ideas as to what the problem is or how to fix this? I have successfully run a simple script in XCODE using MKL, so it's definitely something I'm doing and not my installation.



Solution 1:[1]

I think your program has some bugs, first, you have to include blas95 at the beginning of your code, then, you can't use gemm, you have to choose the specific version of gemm. For example, to do real number matrix multiplication, you have to use dgemm, here is my code(Which I called test.f90), which compiles successfully using ifort -mkl test.f90 -o test.exe

program test
    use blas95
    implicit none
    real*8,dimension(2,2)::testA,testB,testC
    integer::i,j
    testA=1d0
    testB=1d0
    testC=1d0
    call dgemm("N", "N", 2, 2, 2, 1d0, A, 2, B, 2, 0, C, 2)
    print *, testC
end program test

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ???