Using ifx rather than ifort with cmake

Hi,

I know this is more of a cmake problem, but I didn’t find any good resources when looking around online.

I have been running into some major issues with ifort after I had to upgrade to a newer version (weird things like parameters defined in subroutines causing ICEs and member of derived-types not being initialized correctly).

So I thought now may be the time to bite the bullet and switch to ifx. I’m using cmake to build my project and I modified it to try and use ifx but it still uses ifort. Any suggestions?

“C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe” -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_FORTRAN_COMPILER=ifx --no-warn-unused-cli -S<project_dir> -B<project_dir>/build -G “Visual Studio 17 2022” -T host=x86 -A x64

Which version of CMake are you using? From CMake 3.29 ifx is now included in the toolsets recognized by it CMAKE_GENERATOR_TOOLSET — CMake 3.30.1 Documentation you might try adding -T fortran=ifx

I’m using the cmake that ships with Visual Studio which is 3.28.

It seems crazy that Intel is deprecating ifort but they don’t have default support for ifx in the required build software (Visual Studio).

what errors are you seeing? Hard to diagnose if you simply say “it doesn’t work”

Ifx has been working with CMake for a long time. This was added to CMake three years ago:

Just set FC=ifx as an environment variable and you are good to go. CC=icx and CXX=icpx additionally if you need C or C++ compilers as well.

For me, compiling projects like HDF5 worked with CMake and the LLVM-intel compilers (ifx, icx, icpx) long before the autotools-build worked.

1 Like

If only it was that easy… While @runborg in the OP did not mentioned in the title, in the body of the post you can tell he is working under Windows + Microsoft Visual Studio 2022. Just as I have experienced myself, trying to migrate has proven extremely difficult…

Setting up just the environment variables can work if one uses Nmake to build and compile without the graphical editor. If one wants to build, compile and debug natively with MVS2022, then it is necessary to also setup the toolset in CMake such that the project recognizes the compiler. Problem is: the option has been barely added recently, if you are a solo developer, go ahead and install CMake 3.30.1, but if you are working in a large team and have a CI already in place, chances are you cannot “just” upgrade.

I would also like to know if there is a work-around to enable CMake (<3.29) to tell Visual that it should use ifx instead of ifort. So far, I haven’t found anything, the only solution seems to be to go manually through every single Fortran project after the MVS Solution is opened and within the complete solution, for each individual project “Right click on Fortran project name>Intel Compiler>Intel IFX …”.

Kindly correct me if I’m wrong, but did you perhaps expect the data members to be initialized to a default value, such as zero?

If so, then that could be an undefined behavior.

I can not say with certainty for Fortran, but in C/C++, variables that are not initialized, are ticking time bombs, and will cause errors that will be extremely difficult to debug.

So, if you perhaps expected that an integer variable such as this%iter to be automatically initialized to zero, since it is an integer, then it could be an undefined behavior, and cause of your bug.

Thanks for the feedback, everyone!

Sorry for not providing enough detail in my initial post. I recently upgraded to the intel oneAPI toolchain version 2024.2.0 (after my old computer crashed; I was previously using as 2021 version) with Visual Studio 2022. VS ships with CMake 3.28.

I am using the VS generators to build my project. It has been working very smoothly with ifort. I wanted to try switching to ifx because ifort is now causing some very odd problems (which I can explain in more detail below). Ideally, I don’t have to change too much for the build process because it will require me to reconfigure runner VMs we have for CI. I tried setting various environment variables (e.g., FC=ifx) and build flags (e.g., -DCMAKE_Fortran_COMPILER=ifx) to no avail. Based on the information here, it seems like this problem would be solved if I were using a newer version of CMake (which will require me to install a new version of CMake on our runners). I’m hoping there is a more straightforward solution. If you have any suggestions or recommendations, I’m all ears. I have very little CMake experience so would love to learn more.

As for the issues I’m encountering with ifort:

  • Certain members of derived types are not being initialized correctly. For example, I have a file derived type:
 type :: file
        character(:), allocatable :: name
        logical ::          mark = .false.
        integer ::          digits = 10
        integer ::          trim(2) = 0
        logical ::          opened = .false.
        integer ::          count = 0
        logical ::          headed = .false.
        logical ::          eof = .false.
        character(64) ::    tag_s = ' '
contains
.
.
.
end type file

Whenever a new instance of this type is initialized (via x = file() or an allocate statement), file%digits is initialized to something like 2058 and file.tag_s is initialized to an ASCII null character.

  • Additionally, when I compile with any optimizations enabled, I get lots of internal inconsistency check failures.

Note the downgrading to intel oneAPI version 2023.1.0 has stopped the runtime errors. (For anyone that is still using ifort).

I’ll leave this here as a note-to-self and for anyone else bumping into the same rock:

In order to build a MVS2022 project that can switch between classic or LLVM compilers (assuming <= oneAPI2023), one can now do it with CMake (version >3.29, I’m testing with 3.30.2):

  • Classic C++ and Classic Fortran
    -DCMAKE_GENERATOR_TOOLSET=Intel C++ Compiler 19.2,fortran=ifort
  • LLVM C++ and LLVM Fortran
    -DCMAKE_GENERATOR_TOOLSET=Intel C++ Compiler 2023,fortran=ifx

The Visual project is well set, and one can also then manually revert/change the compiler for individual projects.

1 Like