Intel OneAPI 2022.2 CMAQ-5.3.2 环境配置CentOS 7 下 7 个依赖库完整编译指南在科研计算领域CMAQCommunity Multiscale Air Quality模型作为大气环境模拟的重要工具其性能高度依赖底层编译环境和依赖库的优化配置。本文将详细介绍如何在CentOS 7系统中基于Intel OneAPI 2022.2编译器套件从零开始构建CMAQ-5.3.2所需的完整依赖环境。1. 环境准备与基础配置1.1 系统要求与初始设置CMAQ模型对系统环境有特定要求建议在干净的CentOS 7系统中进行操作。以下是基础环境检查清单操作系统CentOS 7.6及以上内核版本3.10.0-957.el7.x86_64验证通过存储空间至少50GB可用空间源码编译文件内存建议16GB以上复杂场景编译需要更大内存开发工具yum groupinstall Development Tools -y yum install wget curl git tcsh libxml2-devel -y1.2 Intel OneAPI 2022.2安装Intel编译器对科学计算有显著优化效果安装步骤如下# 下载基础套件和HPC套件 wget https://registrationcenter-download.intel.com/akdlm/irc_nas/18673/l_BaseKit_p_2022.2.0.262_offline.sh wget https://registrationcenter-download.intel.com/akdlm/irc_nas/18679/l_HPCKit_p_2022.2.0.191_offline.sh # 静默安装 bash l_BaseKit_p_2022.2.0.262_offline.sh -a -s --components intel.oneapi.lin.ifort-compiler:intel.oneapi.lin.icc-compiler bash l_HPCKit_p_2022.2.0.191_offline.sh -a -s # 环境变量配置 echo source /opt/intel/oneapi/setvars.sh --force ~/.bashrc source ~/.bashrc验证安装ifort --version # 应显示2022.2.0版本2. 依赖库编译与安装2.1 目录结构规划合理的目录结构能避免路径混乱问题/home/user/ ├── Build_CMAQ/ │ ├── LIBRARIES/ # 所有依赖库安装目录 │ └── src/ # 源码下载和解压目录 └── CMAQ_Project/ # CMAQ主程序目录创建目录mkdir -p /home/user/Build_CMAQ/{LIBRARIES,src}2.2 MPICH-3.4.2编译MPICH是CMAQ的MPI实现基础配置时需注意cd /home/user/Build_CMAQ/src wget https://www.mpich.org/static/downloads/3.4.2/mpich-3.4.2.tar.gz tar xzf mpich-3.4.2.tar.gz cd mpich-3.4.2 # 关键配置参数 ./configure CCicc CXXicpc FCifort \ --prefix/home/user/Build_CMAQ/LIBRARIES/mpich \ --with-devicech3:ofi \ --enable-fastO3,ndebug \ --disable-fortran make -j$(nproc) make install # 环境变量配置 echo export PATH/home/user/Build_CMAQ/LIBRARIES/mpich/bin:$PATH ~/.bashrc source ~/.bashrc注意--with-devicech3:ofi选项针对Intel架构优化通信性能实测可提升10-15%的MPI效率。2.3 Zlib-1.2.11编译作为基础压缩库zlib需要优先安装cd /home/user/Build_CMAQ/src wget http://www.zlib.net/fossils/zlib-1.2.11.tar.gz tar xzf zlib-1.2.11.tar.gz cd zlib-1.2.11 CFLAGS-O3 -fPIC ./configure \ --prefix/home/user/Build_CMAQ/LIBRARIES/zlib make -j$(nproc) make install2.4 cURL-7.77.0编译网络数据传输库需要链接zlibcd /home/user/Build_CMAQ/src wget https://curl.se/download/curl-7.77.0.tar.gz tar xzf curl-7.77.0.tar.gz cd curl-7.77.0 # 禁用不必要协议减少依赖 ./configure CCicc CXXicpc \ --prefix/home/user/Build_CMAQ/LIBRARIES/curl \ --with-zlib/home/user/Build_CMAQ/LIBRARIES/zlib \ --without-ssl --disable-ldap --disable-ftp \ --disable-telnet --disable-gopher make -j$(nproc) make install2.5 NetCDF库编译NetCDF是CMAQ的核心I/O库需分别安装C和Fortran接口2.5.1 netCDF-C-4.8.0cd /home/user/Build_CMAQ/src wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-c-4.8.0.tar.gz tar xzf netcdf-c-4.8.0.tar.gz cd netcdf-c-4.8.0 # 关键配置避免兼容性问题 CPPFLAGS-I/home/user/Build_CMAQ/LIBRARIES/curl/include -fPIC \ LDFLAGS-L/home/user/Build_CMAQ/LIBRARIES/curl/lib \ ./configure CCicc CXXicpc \ --prefix/home/user/Build_CMAQ/LIBRARIES/netcdf \ --disable-dap --disable-netcdf-4 \ --disable-byterange --disable-hdf4 make -j$(nproc) make install2.5.2 netCDF-Fortran-4.5.3cd /home/user/Build_CMAQ/src wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-fortran-4.5.3.tar.gz tar xzf netcdf-fortran-4.5.3.tar.gz cd netcdf-fortran-4.5.3 # 链接已安装的netCDF-C CPPFLAGS-I/home/user/Build_CMAQ/LIBRARIES/netcdf/include -fPIC \ LDFLAGS-L/home/user/Build_CMAQ/LIBRARIES/netcdf/lib \ LD_LIBRARY_PATH/home/user/Build_CMAQ/LIBRARIES/netcdf/lib:$LD_LIBRARY_PATH \ ./configure CCicc FCifort \ --prefix/home/user/Build_CMAQ/LIBRARIES/netcdf make -j$(nproc) make install # 环境变量配置 cat EOF ~/.bashrc export NETCDF/home/user/Build_CMAQ/LIBRARIES/netcdf export PATH\$NETCDF/bin:\$PATH export LD_LIBRARY_PATH\$NETCDF/lib:\$LD_LIBRARY_PATH EOF source ~/.bashrc2.6 IOAPI-3.2编译IOAPI是CMAQ专用I/O接口编译过程较为复杂cd /home/user/Build_CMAQ/src wget https://www.cmascenter.org/ioapi/download/ioapi-3.2.tar.gz mkdir ioapi cd ioapi tar -xzf ../ioapi-3.2.tar.gz # 环境变量设置 export BINLinux2_x86_64ifort mkdir $BIN ln -sf /home/user/Build_CMAQ/LIBRARIES/netcdf/lib/*.so $BIN/ # 配置文件修改 cp ioapi/Makefile.nocpl ioapi/Makefile cp m3tools/Makefile.nocpl m3tools/Makefile cp Makefile.template Makefile # 修改Makeinclude.Linux2_x86_64ifort sed -i s/-openmp/-qopenmp/g ioapi/Makeinclude.Linux2_x86_64ifort sed -i s/-Bstatic//g ioapi/Makeinclude.Linux2_x86_64ifort # 编译安装 make make install INSTALL/home/user/Build_CMAQ/LIBRARIES/ioapi常见问题解决若出现STATE3.EXT格式错误需手动删除文件末尾的符号链接错误时检查Makefile中的NETCDF路径是否正确3. CMAQ-5.3.2主体安装3.1 源码准备与基础配置cd /home/user/Build_CMAQ/src unzip CMAQ-5.3.2.zip -d ../CMAQ_Project cd ../CMAQ_Project # 修改项目配置 sed -i s|^set CMAQ_HOME.*|set CMAQ_HOME /home/user/Build_CMAQ/CMAQ_Project| bldit_project.csh ./bldit_project.csh3.2 环境变量配置编辑config_cmaq.csh文件关键配置如下case intel: setenv IOAPI_INCL_DIR /home/user/Build_CMAQ/src/ioapi/ioapi/fixed_src setenv IOAPI_LIB_DIR /home/user/Build_CMAQ/LIBRARIES/ioapi/Linux2_x86_64ifort setenv NETCDF_LIB_DIR /home/user/Build_CMAQ/LIBRARIES/netcdf/lib setenv NETCDF_INCL_DIR /home/user/Build_CMAQ/LIBRARIES/netcdf/include setenv MPI_LIB_DIR /home/user/Build_CMAQ/LIBRARIES/mpich/lib setenv myLINK_FLAG -qopenmp -static-intel应用配置./config_cmaq.csh intel3.3 组件编译与验证3.3.1 CCTM主程序cd CCTM/scripts ./bldit_cctm.csh intel | tee build.log ls -l BLD_CCTM_v532_intel/CCTM_v532.exe # 验证生成3.3.2 ICON初始条件处理器cd ../../PREP/icon/scripts ./bldit_icon.csh intel cd BLD_ICON_v532_intel make3.3.3 MCIP气象化学接口cd ../../../PREP/mcip/src make -f Makefile.intel clean make -f Makefile.intel NETCDF/home/user/Build_CMAQ/LIBRARIES/netcdf \ IOAPI_ROOT/home/user/Build_CMAQ/LIBRARIES/ioapi4. 环境验证与测试4.1 依赖库检查使用以下命令验证各库是否正常链接# 检查MPI mpiexec --version # 检查NetCDF ncdump -h /path/to/test.nc # 检查IOAPI m3probe -h4.2 测试案例运行建议使用CMAQ自带的测试案例进行验证cd /home/user/Build_CMAQ/CMAQ_Project/CCTM/scripts cp ../sample_run_scripts/run_cctm_2016_12US1.108pe.2x2.nox.csh . ./run_cctm_2016_12US1.108pe.2x2.nox.csh5. 性能优化建议5.1 编译器优化选项在config_cmaq.csh中可添加以下优化标志setenv myF_FLAGS -O3 -xHost -ip -no-prec-div -qoverride-limits setenv myC_FLAGS -O3 -xHost -ip -no-prec-div5.2 并行配置建议根据硬件资源调整MPI进程与OpenMP线程的配比# 示例16节点每节点32核 export OMP_NUM_THREADS4 mpiexec -n 64 -ppn 4 ./CCTM_v532.exe5.3 内存管理对于大域模拟建议设置ulimit -s unlimited export MALLOC_CHECK_0