在 Ubuntu 上配置 Fortran 开发环境通常很简单,下面按从零开始的流程给你说明。
Ubuntu 自带 gfortran(GNU Fortran 编译器),推荐直接使用。
sudo apt update
sudo apt install gfortran
gfortran --version
能看到版本号就说明安装成功。
nano hello.f90
program hello
print *, "Hello, Fortran!"
end program hello
gfortran hello.f90 -o hello
./hello
输出:
Hello, Fortran!
gfortran hello.f90 -o hello \
-O2 \ # 优化
-Wall \ # 显示警告
-g # 调试信息
sudo apt install gdb
使用:
gdb ./hello
示例 Makefile:
FC = gfortran
FLAGS = -O2 -Wall
hello: hello.f90
$(FC) $(FLAGS) hello.f90 -o hello
clean:
rm -f hello
使用:
make
./hello
make clean
sudo apt install libblas-dev liblapack-dev
编译时:
gfortran main.f90 -llapack -lblas
sudo apt install mpich
使用:
mpif90 hello.f90 -o hello
mpirun -np 4 ./hello
确认:
which gfortran
.f:Fortran 77.f90 / .f95:现代 Fortran如果你告诉我:
我可以给你更针对性的配置方案。