How to use Intel fortran compiler with MKL on command line

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 19:37:06

问题


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.


回答1:


The documentation tells you to use the "source" command on the provided compilervars.sh script to make all the resources available. For example:

source //bin/compilervars.sh

This will add MKL to the include and library paths so that the compiler and linker can find them. If you need more help, please ask in https://software.intel.com/en-us/forums/intel-fortran-compiler-for-linux-and-mac-os-x You can get MKL-specific help in https://software.intel.com/en-us/forums/intel-math-kernel-library



来源:https://stackoverflow.com/questions/31497734/how-to-use-intel-fortran-compiler-with-mkl-on-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!