[lammps-users] Error compiling LAMMPS stable patch released on 29Sep 2021

Hi LAMMPS folks,

I’m trying to compile lammps latest stable release from 29 sept 2021 with Intel oneAPI toolkit integrated to Visual Studio. I saw there is a preset file oneapi.cmake in the camke folder, but since the preferred method of setting preset cacheVairables, according to the visual studio official documentation is using CmakePresets.json, I made the following configuration preset copying vars from oneapi.cmake:

{
"name": "x64-Debug-oneApi",
"displayName": "x64 Debug oneApi",
"description": "Target Windows (64-bit) with the Visual Studio development environment. (Debug)",
"generator": "Visual Studio 17 2022",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"inherits": "windows-base",
"architecture": {
"value": "x64",
"strategy": "set"
},
"toolset": {
"value": "Intel C++ Compiler 2022",
"strategy": "set"
},
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_CXX_COMPILER": "icpx",
"CMAKE_C_COMPILER": "icx",
"CMAKE_Fortran_COMPILER": "ifx",
"CMAKE_CXX_FLAGS_DEBUG": "-Wall -Wextra -g",
"CMAKE_CXX_FLAGS_RELWITHDEBINFO": "-Wall -Wextra -g -O2 -DNDEBUG",
"CMAKE_CXX_FLAGS_RELEASE": "-O3 -DNDEBUG",
"CMAKE_Fortran_FLAGS_DEBUG": "-Wall -Wextra -g",
"CMAKE_Fortran_FLAGS_RELWITHDEBINFO": "-Wall -Wextra -g -O2 -DNDEBUG",
"CMAKE_Fortran_FLAGS_RELEASE": "-O3 -DNDEBUG",
"CMAKE_C_FLAGS_DEBUG": "-Wall -Wextra -g",
"CMAKE_C_FLAGS_RELWITHDEBINFO": "-Wall -Wextra -g -O2 -DNDEBUG",
"CMAKE_C_FLAGS_RELEASE": "-O3 -DNDEBUG",

"MPI_CXX": "icpx",
"MPI_CXX_COMPILER": "mpicxx",

"HAVE_OMP_H_INCLUDE": true,
"OpenMP_C": "icx",
"OpenMP_C_FLAGS": "-qopenmp",
"OpenMP_C_LIB_NAMES": "omp",
"OpenMP_CXX": "icpx",
"OpenMP_CXX_FLAGS": "-qopenmp",
"OpenMP_CXX_LIB_NAMES": "omp",
"OpenMP_Fortran_FLAGS": "-qopenmp",
"OpenMP_omp_LIBRARY": "libiomp5.so"
}
}

The configuration cache is generated and vscode *.vcxproj files are generated. But when I build the default target item “Debug/lmp.exe” I run into the following error:

clang-cl: : warning : unknown argument ignored in clang-cl: '-restrict' [-Wunknown-argument] [E:\Sainath\lammps-29Sep2021\cmake\out\build\x64-Debug-oneApi\mpi_stubs.vcxproj]
clang-cl: : warning : unknown argument ignored in clang-cl: '-g' [-Wunknown-argument] [E:\Sainath\lammps-29Sep2021\cmake\out\build\x64-Debug-oneApi\mpi_stubs.vcxproj]
clang-cl: : warning : argument unused during compilation: '-Qstd=c++11' [-Wunused-command-line-argument] [E:\Sainath\lammps-29Sep2021\cmake\out\build\x64-Debug-oneApi\mpi_stubs.vcxproj]
E:\Sainath\lammps-29Sep2021\src\STUBS\mpi.cpp(24,10): : error : 'sys/time.h' file not found [E:\Sainath\lammps-29Sep2021\cmake\out\build\x64-Debug-oneApi\mpi_stubs.vcxproj]
#include <sys/time.h>
^~~~~~~~~~~~
1 error generated.

I’m not sure if I’m missing something here like setting up any environment variables or include directories? MPI libraries are available in oneAPI toolkit and I already setup the oneAPI environment by running the following command on dev terminal:

"C:\Program Files (x86)\Intel\oneAPI\setvars.bat"

I know the alternate way to do this is using a WSL or remote linux system. But I want to make this work on windows with oneApi. I kindly request you to help, I tried many things and am in a desperate situation. The cmake config log is attached for reference.

cmake.log (15.4 KB)

The preset is for compiling on Linux, not Windows. LAMMPS compilation has not yet been ported to use the Intel Compilers on Windows natively.
I don’t remember whether it is possible from the command line (using the latest CMake version, not the one integrated into VS), but certainly not from within VS.

If you want to natively compile LAMMPS on Windows, I strongly recommend to use the latest patch release (4 May 2022) and make certain that you have updated VS to version 17.1.x
This version has a suitable CMakeSettings.json file in the cmake folder and VS will ask when opening the LAMMPS sources where it is. That has 4 configurations for MSVC++ and Clang each with Debug and Release settings and it will load the available “windows.cmake” preset. This should also work if you clone the LAMMPS repo from github and check out the release branch.

Please see the LAMMPS manual and particularly this paragraph https://docs.lammps.org/Build_windows.html#using-microsoft-visual-studio

If you want to port the cmake scripting and compilation to the OneAPI compilers you are most welcome to do so, but there is not much help that you can get.
I have tried but failed and after some recent updates the Intel OneAPI installer have destroyed the installation into an unfixable mess (at least for somebody with my limited knowledge of Windows internals).

For a code like LAMMPS there is very limited benefit from the intel compilers. My expectations are that your best chances are with the Intel classic compilers. The new compilers have too many issues and are not (yet) reliably detectable by CMake on windows to have a proper port.

Axel.

Dear Axel,

Thank you for that quick and detailed clarification.

Best,
Abhijith Anandakrishnan,
Applied Mechanics,

Indian Institute of Technology Madras

Quick update.

I found that the oneAPI installer problems are due to the visual studio integration (which appears to break when you update VS).

I can now confirm that it is possible to compile LAMMPS on Windows with the Intel oneAPI compiler toolkit when using an external CMake and Ninja installation (not from within visual studio). Using a cmake command line like the following:

cmake -G Ninja -S cmake -B build-intel -DCMAKE_CXX_COMPILER=icx -DCMAKE_BUILD_TYPE=Release -C cmake\presets\basic.cmake -DCMAKE_TUNE_FLAGS="-Wno-unused-command-line-argument"

You can substitute dpcpp for icx

Large-scale Atomic/Molecular Massively Parallel Simulator - 4 May 2022
Git info (develop / patch_4May2022)

Usage example: lmp -var t 300 -echo screen -in in.alloy

[...]

OS: Windows 10 Home, Windows ABI 6.2 (9200) on x86_64

Compiler: Intel LLVM C++ 202201.0 / Intel(R) oneAPI DPC++/C++ Compiler 2022.1.0 (2022.1.0.20220316) with OpenMP not enabled
C++ standard: C++17
MPI v1.0: LAMMPS MPI STUBS for LAMMPS version 4 May 2022