How to properly link mkl interfaces with fortls

68 views Asked by At

In my project I'm doing massive use of the blas subroutines under the mkl implementation, I have no problems in compiling the project thanks to the Intel Advisor, but I can't get fortls to recognize the interface of the functions.

I tried to modify the Modern Fortran extensions settings adding to the include path /opt/intel/oneapi/mkl/latest/include/ where there is the file mkl_blas.fi which contains all the interfaces (the .mod files are in the subfolder mkl/intel64/ilp64) but the linter highlights in blue the line use blas95, saying that it can't be found in the project, and still asks for the external or an explicit interface for dgemm.

1

There are 1 answers

0
gnikit On

fortls cannot read .mod files since every compiler vendor uses a custom format to create them; it can only understand sources. If you have the sources for MKL you can add them to the files fortls needs to parse by editing the parsing options see docs: https://fortls.fortran-lang.org/options.html#sources-file-parsing

This will allow you to hover, peek, goto etc. to the MKL interfaces. You will probably have to set the .fi extension as valid Fortran sources.

That being said, the linter and the language server (fortls) are 2 different things and hence have different options. The linter uses a proper compiler (by default gfortran) to mock-compile your code. I would guess that the .mod files have been compiled with ifx and not gfortran so:

  • set your linter to ifx
  • include the directories containing the .mod files (you can use regex) to the linter

Your settings should look something like this;

{
    "fortran.linter.compiler": "ifx",
    // only necessary if ifx is not in your PATH
    "fortran.linter.compilerPath": "/opt/intel/oneapi/compiler/latest/linux/bin/intel64/ifx",
    "fortran.linter.includePaths": [
        "${workspaceFolder}/**", // your source files, you might not want this depending on your project
        "/opt/intel/oneapi/mkl/intel64/ilp64/**" // location of .mod files
    ],
    "fortran.fortls.directories": [
        "${workspaceFolder}/**", // your source files
        "/opt/intel/oneapi/mkl/latest/include/**" // location of MKL interfaces
    ],
    "fortran.fortls.suffixes": [
        ".fi",
    ]
}