在Ubuntu上进行Fortran科学计算通常涉及以下几个步骤:
sudo apt update
sudo apt install gfortran
验证安装:
gfortran --version
hello.f90
:program hello
implicit none
print *, 'Hello, World!'
end program hello
gfortran -o hello hello.f90
运行生成的可执行文件:
./hello
sudo apt install libmkl-dev libblas-dev
在编译时链接这些库:
gfortran -o my_program my_program.f90 -L/path/to/lib -lmkl_lapack95_lp64 -lmkl_blas95_lp64
import numpy as np
from scipy.linalg import eigh
import f2py
# 假设你有一个名为 'my_module.f90' 的Fortran模块
my_module = f2py.module('my_module', sources='my_module.f90')
# 调用Fortran函数
result = my_module.my_function(np.array([1.0, 2.0, 3.0]))
通过以上步骤和资源,可以在Ubuntu上高效地进行Fortran科学计算。