Fortran程式並行和GDB除錯
阿新 • • 發佈:2022-05-16
Fortran程式並行和GDB除錯
本機器系統為Ubuntu18.04LTS,編譯器安裝了intel的oneAPI
Fortran+MPI實現並行
MPI是一個適用於C/C++/Fortran77/Fortran90的並行庫,初學者只需學會4個基本函式即可上手使用,需要程序通訊時還需要學兩個。
c filename: hello_world.f c parallel program program main use mpi !for Fortran90 use ifort complie !INCLUDE "mpif.h" !for Fortran77 implicit none integer*4::ierr,my_id,num_procs call MPI_INIT ( ierr ) call MPI_COMM_RANK (MPI_COMM_WORLD, my_id, ierr) !my_id ==> NO. now process call MPI_COMM_SIZE (MPI_COMM_WORLD, num_procs, ierr) !num_procs ==> number of process write(*,'('Hello World',1x,i2,a,i2)') my_id,'/',num_procs call MPI_FINALIZE ( ierr ) end program
並行程式的編譯
fortran編譯器有對應的mpi編譯命令
對於intel的oneAPI(即ifort編譯器)
#compile
mpiifort hello_world.f -o z.out
#run
mpirun -np 3 ./z.out
對於gcc
#compile
mpif90 hello_world.f -o z.out
#run
mpirun -np 3 ./z.out
GDB除錯
首先安裝xterm終端模擬器
sudo apt install xterm -y
進行GDB除錯
#compile mpif90 -g hello_world.f -o z.out #run mpirun -np 3 xterm -e gdb ./z.out
接下來會顯示三個xterm模擬終端,分別表示這三個並行的程序,在每一個gdb終端裡輸入‘r’即可開啟子程序