SuperLU用于求解大规模稀疏线性方程组,本文记录在远程Linux服务器下编译安装SuperLU的流程。
一、配置VS Code
2.1 安装VS Code Extensions
在本地打开VS Code, 安装以下扩展插件,
Task Explorer Output Colorizer Git Extension Pack Remote Developement Remote X11 | |
C/C++ Extension Pack C++ TestMate | |
Modern Fortran FORTRAN InstelliSense Fortran Breakpoint Support | |
Extension Pack for Intel Software Developer Tools |
2.2 Remote SSH
通过"Remote Development"扩展插件登录远程Linux服务器,并安装以下插件
C/C++ Extension Pack C++ TestMate | |
Modern Fortran FORTRAN InstelliSense Fortran Breakpoint Support | |
Extension Pack for Intel Software Developer Tools |
二、安装与配置oneAPI
1.1 配置包管理器
wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \
| gpg --dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null
echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list
sudo apt update
1.2 安装
sudo apt -y install cmake pkg-config build-essential
1.3 安装oneAPI
sudo apt install intel-basekit
sudo apt install intel-hpckit
1.4 配置CMake Kits
打开VS Code, 执行"CMake: Edit User-Local CMake Kits",编辑“~/.local/share/CMakeTools/cmake-tools-kits.json”文件,
[
{
"name": "GCC 11.4.0 x86_64-linux-gnu",
"compilers": {
"C": "/usr/bin/gcc",
"CXX": "/usr/bin/g++"
},
"isTrusted": true
},
{
"name": "Intel(R) oneAPI DPC++/C++ Compiler 2024.2.1",
"compilers": {
"C": "/opt/intel/oneapi/compiler/2024.2/bin/icx",
"CXX": "/opt/intel/oneapi/compiler/2024.2/bin/icpx"
},
"isTrusted": true
}
]
1.5 oneAPI环境变量配置
编辑"~/.bashrc"文件,添加以下内容,
source /opt/intel/oneapi/setvars.sh --force
然后重启远程服务器,在本地重新通过"VS Code"连接远程Linux服务器。
三、编译安装SuperLU
3.1 下载SuperLU
git https://github.com/xiaoyeli/superlu.git
cd ./superlu
git checkout v7.0.0
3.2 编译安装SuperLU
可以使用CMake Kits或者CMake Presets来构建SuperLU,
方法1: 使用CMake Kits
选择"Intel(R) oneAPI DPC++/C++ Compiler 2024.2.1", 使用在VS Code中使用CMake Tools完成构建,同时做如下配置修改,
CMAKE_C_FLAGS | -fPIC |
CMAKE_BUILD_TYPE | Release |
BUILD_SHARED_LIBS | ON |
BUILD_TESTING | OFF |
enable_tests | OFF |
CMAKE_INSTALL_PREFIX | /data/3rdparty/install/intel-opt-dto |
方法2: 使用CMake Presets
在superlu目录下,编辑CMakeUserPresets.json文件,
{
"version": 4,
"configurePresets": [
{
"name": "linux_default",
"hidden": true,
"displayName": "Default Linux Config",
"description": "Default build using Unix Makefiles generator",
"generator": "Unix Makefiles",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"cacheVariables": {
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "linux_gcc",
"inherits": "linux_default",
"displayName": "GCC 11.4.0 x86_64-linux-gnu",
"description": "Using compilers: C = /usr/bin/gcc, CXX = /usr/bin/g++",
"cacheVariables": {
"CMAKE_C_COMPILER": "/usr/bin/gcc",
"CMAKE_CXX_COMPILER": "/usr/bin/g++",
"CMAKE_MAKE_PROGRAM": "/usr/bin/make"
}
},
{
"name": "linux_intel",
"inherits": "linux_default",
"displayName": "Intel(R) oneAPI DPC++/C++ Compiler 2024.0.2",
"description": "Using compilers: C = /opt/intel/oneapi/compiler/latest/bin/icx, CXX = /opt/intel/oneapi/compiler/latest/bin/icpx",
"cacheVariables": {
"CMAKE_C_COMPILER": "/opt/intel/oneapi/compiler/latest/bin/icx",
"CMAKE_CXX_COMPILER": "/opt/intel/oneapi/compiler/latest/bin/icpx"
}
}
],
"buildPresets": [
{
"name": "linux_gcc",
"description": "",
"displayName": "",
"configurePreset": "linux_gcc"
},
{
"name": "linux_intel",
"description": "",
"displayName": "",
"configurePreset": "linux_intel"
}
]
}
然后在VS Code CMake Tools中,修改CMake Cache,
CMAKE_C_FLAGS | -fPIC |
CMAKE_BUILD_TYPE | Release |
BUILD_SHARED_LIBS | ON |
BUILD_TESTING | OFF |
enable_tests | OFF |
CMAKE_INSTALL_PREFIX | /data/3rdparty/install/intel-opt-dto |
3.3 检查SuperLU连接引用
检查编译生成的libsuperlu.so是否正常链接到了oneAPI MKL,
ldd /data/3rdparty/install/intel-opt-dto/lib/libsuperlu.so
linux-vdso.so.1 (0x00007ffc24be1000)
libmkl_intel_lp64.so.2 => /opt/intel/oneapi/mkl/2024.2/lib/libmkl_intel_lp64.so.2 (0x00007dd914c00000)
libmkl_intel_thread.so.2 => /opt/intel/oneapi/mkl/2024.2/lib/libmkl_intel_thread.so.2 (0x00007dd912800000)
libmkl_core.so.2 => /opt/intel/oneapi/mkl/2024.2/lib/libmkl_core.so.2 (0x00007dd90e800000)
libiomp5.so => /opt/intel/oneapi/compiler/2024.2/lib/libiomp5.so (0x00007dd90e200000)
libimf.so => /opt/intel/oneapi/compiler/2024.2/lib/libimf.so (0x00007dd90dc00000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007dd915b88000)
libsvml.so => /opt/intel/oneapi/compiler/2024.2/lib/libsvml.so (0x00007dd90c400000)
libirng.so => /opt/intel/oneapi/compiler/2024.2/lib/libirng.so (0x00007dd914b07000)
libintlc.so.5 => /opt/intel/oneapi/compiler/2024.2/lib/libintlc.so.5 (0x00007dd915b25000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007dd90c000000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007dd915b20000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007dd915b1b000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007dd915b16000)
/lib64/ld-linux-x86-64.so.2 (0x00007dd915d2e000)
可以看到,SuperLU实际上是链接到了LP64接口的MKL。若想SuperLU链接到ILP64接口的MKL,需要做如下CMake配置,
BLA_SIZEOF_INTEGER | 8 |
BLA_VENDOR | Intel10_64ilp |
四、FAQs
Q. 在主程序中同时引用oneMKL、SuperLU,运行时调用oneMKL API报错。
A. 这个可能是由于libmkl_intel_lp64.so/libmkl_intel_ilp64.so混合调用所致。可考虑将CMake Cache “MKL_INTERFACE”设置为"lp64",这样会在主程序中使用"LP64"接口的MKL。
网络资料
SuperLU: Home Page (nersc.gov)https://portal.nersc.gov/project/sparse/superlu/#superluUsing the ILP64 Interface vs. LP64 Interface
https://www.intel.com/content/www/us/en/docs/onemkl/developer-guide-windows/2023-0/using-the-ilp64-interface-vs-lp64-interface.html