使用VS2019+Intel OneAPI (ifort)+Intel MPI编译和运行MPI程序与Coarray程序

使用VS2019+Intel OneAPI (ifort)+Intel MPI编译和运行MPI程序与Coarray程序

一、安装环境

  1. 安装vs2019
  2. 安装Intel OneAPI Base Toolkit中的Intel Fortran Compiler,并勾选与vs2019适配
  3. 安装Intel OneAPI HPC Toolkit中的Intel MPI
  4. 运行intel mpi安装目录下/env/vars.bat进行环境变量的注册,路径为<install-dir>\mpi\<version>.<update>\env\vars.bat
  5. 用管理员身份运行cmd或者shell,运行:hydra_service -installhydra_service -start
  6. 继续用管理员身份在cmd中运行:mpiexec -register,输入的用户名为空,密码为电脑的登陆密码
  7. 运行:mpiexec -validate.

二、编译和运行MPI程序

以下是针对Release程序的设置,如果是Debug程序,需要相应修改,且只支持x64程序。

编译:

  1. 在Fortran—General—Additional Include Directories加入C:\Program Files (x86)\Intel\oneAPI\mpi\latest\include,也即mpi的include目录。
  2. 在Linker—General—Additional Library Directories加入C:\Program Files (x86)\Intel\oneAPI\mpi\latest\libC:\Program Files (x86)\Intel\oneAPI\mpi\latest\lib\release.
  3. 在Linker—Input—Additional Dependices加入impi.lib

运行:在cmd中使用mpiexec即可。
注记:windows下,如果运行exe时提示缺少MKL的dll,那么把linker-libraries-runtime libirary改成default(multithreaded),不要使用DLL.

三、编译和运行Coarray程序

编译:打开项目属性—Fortran—Language,开启Enable Coarrays并输入Coarray Images数量,直接编译。
运行:win系统上鼠标双击即可运行,或者通过cmd运行,别去用mpiexec。
注记:Coarray程序只要安装了Intel MPI就可以运行。

四、使用MKL

如果使用Fortran95编程,想要使用新的MKL Lapack函数,需要在VS2019加入mkl_lapack95_lp64.lib,其他的也类似处理。在Linux上,需要在编译选项添加-lmkl_lapack95_lp64.

五、Linux上用PBS启动分布式计算

1. 纯MPI

编写job.pbs文件如下,使用qsub job.pbs提交任务。

#PBS -N name					#任务的名字
#PBS -l nodes=2:ppn=28			#请求2个节点,每个节点28个核心
#PBS -l walltime=24000:00:00	#运算时间无限
#PBS -q cu1						#节点在cu1队列中
#PBS -o stdout					#标准输出到stdout
#PBS -e stderr					#标准错误到stderr
#PBS -r y						#可运行

#这一个对于纯MPI项目不重要,可写可不写
export I_MPI_JOB_RESPECT_PROCESS_PLACEMENT=off
cd $PBS_O_WORKDIR				#进入pbs文件所在目录

#编译
/opt/intel/impi/5.0.2.044/intel64/bin/mpiifort *.f90 -O3 -mtune=native -march=native -xHost -m64 -r8 -fpp -ipo -qopt-prefetch=5 -qopenmp -qopenmp-simd -no-wrap-margin -mcmodel=large -fp-model fast=1 -mkl=sequential -lmkl_lapack95_lp64 -o main.exe
/opt/intel/impi/5.0.2.044/intel64/bin/mpiifort *.f90 -O3 -mtune=native -march=native -xHost -m64 -r8 -fpp -ipo -qopt-prefetch=5 -qopenmp -qopenmp-simd -no-wrap-margin -mcmodel=large -fp-model fast=1 -mkl=sequential -lmkl_lapack95_lp64 -o main.exe
/opt/intel/impi/5.0.2.044/intel64/bin/mpiifort *.f90 -O3 -mtune=native -march=native -xHost -m64 -r8 -fpp -ipo -qopt-prefetch=5 -qopenmp -qopenmp-simd -no-wrap-margin -mcmodel=large -fp-model fast=1 -mkl=sequential -lmkl_lapack95_lp64 -o main.exe
/opt/intel/impi/5.0.2.044/intel64/bin/mpiifort *.f90 -O3 -mtune=native -march=native -xHost -m64 -r8 -fpp -ipo -qopt-prefetch=5 -qopenmp -qopenmp-simd -no-wrap-margin -mcmodel=large -fp-model fast=1 -mkl=sequential -lmkl_lapack95_lp64 -o main.exe
/opt/intel/impi/5.0.2.044/intel64/bin/mpiifort *.f90 -O3 -mtune=native -march=native -xHost -m64 -r8 -fpp -ipo -qopt-prefetch=5 -qopenmp -qopenmp-simd -no-wrap-margin -mcmodel=large -fp-model fast=1 -mkl=sequential -lmkl_lapack95_lp64 -o main.exe
/opt/intel/impi/5.0.2.044/intel64/bin/mpiifort *.f90 -O3 -mtune=native -march=native -xHost -m64 -r8 -fpp -ipo -qopt-prefetch=5 -qopenmp -qopenmp-simd -no-wrap-margin -mcmodel=large -fp-model fast=1 -mkl=sequential -lmkl_lapack95_lp64 -o main.exe
rm -r *.mod						#删除mod组件
mpirun -np 56 ./main.exe		#启动2*28=56个进程

这样就启动了56个进程,正好占用满了所有申请的进程。如果启动的进程数量更少,那么就有空置的进程。

2. 混合MPI/OpenMP

#PBS -N name					#任务的名字
#PBS -l nodes=2:ppn=28			#请求2个节点,每个节点28个核心
#PBS -l walltime=24000:00:00	#运算时间无限
#PBS -q cu1						#节点在cu1队列中
#PBS -o stdout					#标准输出到stdout
#PBS -e stderr					#标准错误到stderr
#PBS -r y						#可运行

#禁用PBS系统的进程排布方案,在mpirun显式指定
export I_MPI_JOB_RESPECT_PROCESS_PLACEMENT=off
cd $PBS_O_WORKDIR				#进入pbs文件所在目录

#编译
/opt/intel/impi/5.0.2.044/intel64/bin/mpiifort *.f90 -O3 -mtune=native -march=native -xHost -m64 -r8 -fpp -ipo -qopt-prefetch=5 -qopenmp -qopenmp-simd -no-wrap-margin -mcmodel=large -fp-model fast=1 -mkl=sequential -lmkl_lapack95_lp64 -o main.exe
/opt/intel/impi/5.0.2.044/intel64/bin/mpiifort *.f90 -O3 -mtune=native -march=native -xHost -m64 -r8 -fpp -ipo -qopt-prefetch=5 -qopenmp -qopenmp-simd -no-wrap-margin -mcmodel=large -fp-model fast=1 -mkl=sequential -lmkl_lapack95_lp64 -o main.exe
/opt/intel/impi/5.0.2.044/intel64/bin/mpiifort *.f90 -O3 -mtune=native -march=native -xHost -m64 -r8 -fpp -ipo -qopt-prefetch=5 -qopenmp -qopenmp-simd -no-wrap-margin -mcmodel=large -fp-model fast=1 -mkl=sequential -lmkl_lapack95_lp64 -o main.exe
/opt/intel/impi/5.0.2.044/intel64/bin/mpiifort *.f90 -O3 -mtune=native -march=native -xHost -m64 -r8 -fpp -ipo -qopt-prefetch=5 -qopenmp -qopenmp-simd -no-wrap-margin -mcmodel=large -fp-model fast=1 -mkl=sequential -lmkl_lapack95_lp64 -o main.exe
/opt/intel/impi/5.0.2.044/intel64/bin/mpiifort *.f90 -O3 -mtune=native -march=native -xHost -m64 -r8 -fpp -ipo -qopt-prefetch=5 -qopenmp -qopenmp-simd -no-wrap-margin -mcmodel=large -fp-model fast=1 -mkl=sequential -lmkl_lapack95_lp64 -o main.exe
/opt/intel/impi/5.0.2.044/intel64/bin/mpiifort *.f90 -O3 -mtune=native -march=native -xHost -m64 -r8 -fpp -ipo -qopt-prefetch=5 -qopenmp -qopenmp-simd -no-wrap-margin -mcmodel=large -fp-model fast=1 -mkl=sequential -lmkl_lapack95_lp64 -o main.exe
rm -r *.mod						#删除mod组件
mpirun -np 2 -ppn 1 ./main.exe	#启动2个进程,每个node一个进程

这样,一共2个节点,每个节点1个MPI进程,节点内部使用OpenMP共享内存并行。

  • 6
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
'ifort'是Intel Fortran编译器的命令行工具。它用于编译和链接Fortran语言的程序。如果你在命令行中输入'ifort',但是系统提示"'ifort' 不是内部或外部命令,也不是可运行程序",这意味着该命令在你的系统中无法找。 可能的原因是你没有正确安装Intel Fortran编译器,或者该编译器的路径没有添加到系统的环境变量中。要解决这个问题,你可以按照以下步骤进行操作: 1. 确保你已经正确安装了Intel Fortran编译器,并且知道它的安装路径。 2. 打开系统的环境变量设置。在Windows系统中,可以通过控制面板中的"系统"->"高级系统设置"->"环境变量"来打开。 3. 在系统变量中找到名为"Path"的变量,并点击编辑。 4. 在编辑窗口中,添加Intel Fortran编译器的安装路径。例如,如果安装路径是"C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2020.0.166\windows\bin\intel64",则在变量值的末尾添加";C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2020.0.166\windows\bin\intel64"。 5. 点击确定保存修改,并关闭所有打开的窗口。 6. 重新打开命令行窗口,输入'ifort'命令,看是否能够正常执行。 如果按照上述步骤操作后仍然无法解决问题,请确保你已经正确安装了Intel Fortran编译器,并且检查安装路径是否正确。如果问题仍然存在,可能需要重新安装编译器或者联系Intel支持获取进一步的帮助。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值