在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科學計算。