问题描述
我想编译这个程序/模块? (modulos.f) 在 Fortran 中
module vars_common
real sepaa[allocatable](:)
real sepan[allocatable](:)
real rt[allocatable](:)
real xob[allocatable](:)
real npx[allocatable](:)
real*8 bb[allocatable](:)
real*8 bl[allocatable](:)
real*8 bu[allocatable](:)
real*8 cvec[allocatable](:)
real*8 ww[allocatable](:)
real*8 a[allocatable](:,:)
real*8 xi[allocatable](:)
real*8 q[allocatable](:,:)
real*8 dd[allocatable](:,:)
!variables escalares
integer maxm_var,maxn_var,nrowa_var
integer liwork_var,lwork_var,maxbnd_var
end module vars_common
*********************************************************************
subroutine allocate_data
!maxm,maxn,maxbnd,mp
use vars_common
parameter(mg=1000,mp=2000)
integer ind
allocate(sepaa(0:maxm_var),sepan(0:maxm_var),rt(0:maxm_var),* stat=ind)
if (ind.ne.0) stop 'sin memoria'
allocate(xob(maxm_var),npx(0:mp),* stat=ind)
if (ind.ne.0) stop 'sin memoria'
allocate(bb(0:maxm_var),bl(maxbnd_var),bu(maxbnd_var),* stat=ind)
if (ind.ne.0) stop 'sin memoria'
allocate(cvec(maxn_var),ww(maxn_var),* stat=ind)
if (ind.ne.0) stop 'sin memoria'
allocate(a(0:maxm_var,0:maxn_var),stat=ind)
if (ind.ne.0) stop 'sin memoria'
allocate(xi(maxn_var),q(maxn_var,maxn_var),* stat=ind)
if (ind.ne.0) stop 'sin memoria'
allocate(dd(maxn_var,stat=ind)
if (ind.ne.0) stop 'sin memoria'
end subroutine allocate_data
**********************************************************************
subroutine deallocate_data
use vars_common
integer ind
deallocate(sepaa,sepan,rt,stat=ind)
if (ind.ne.0) stop 'problema liberando espacio'
deallocate(xob,npx,stat=ind)
if (ind.ne.0) stop 'problema liberando espacio'
deallocate(bb,bl,bu,stat=ind)
if (ind.ne.0) stop 'problema liberando espacio'
deallocate(cvec,a,stat=ind)
if (ind.ne.0) stop 'problema liberando espacio'
deallocate(xi,q,stat=ind)
if (ind.ne.0) stop 'problema liberando espacio'
deallocate(dd,stat=ind)
if (ind.ne.0) stop 'problema liberando espacio'
end subroutine deallocate_data
***********************************************************************
我不知道 Fortran 是什么版本,但我在 Ubuntu 20.04.1 LTS 的终端中尝试了以下命令。
gfortran modulos.f 我收到此错误消息: > 模数.f:2:21:
2 | real sepaa[allocatable](:)
| 1
Fatal error: Coarrays disabled at (1),use ‘-fcoarray=’ to enable
compilation terminated.
gfortran -fcoarray=lib -c modulos.f 或 gfortran -fcoarray=single -c modulos.f 我收到此错误消息:
modulos.f:2:33:
2 | real sepaa[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:3:33:
3 | real sepan[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:4:30:
4 | real rt[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:5:31:
5 | real xob[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:6:31:
6 | real npx[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:7:32:
7 | real*8 bb[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:8:32:
8 | real*8 bl[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:9:32:
9 | real*8 bu[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:10:34:
10 | real*8 cvec[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:11:32:
11 | real*8 ww[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:12:31:
12 | real*8 a[allocatable](:,:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:13:32:
13 | real*8 xi[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:14:31:
14 | real*8 q[allocatable](:,:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:15:32:
15 | real*8 dd[allocatable](:,:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:24:13:
24 | use vars_common
| 1
Fatal error: Cannot open module file ‘vars_common.mod’ for reading at (1): No such file or directory
compilation terminated.
gfortran -fcoarray=none -c modulos.f 我收到此错误消息:
gfortran -fcoarray=none -c modulos.f
modulos.f:2:21:
2 | real sepaa[allocatable](:)
| 1
Fatal error: Coarrays disabled at (1),use ‘-fcoarray=’ to enable
compilation terminated.
gfortran -fcoarray=single -c modulos.f 我收到此错误消息:
gfortran -fcoarray=single -c modulos.f
modulos.f:2:33:
2 | real sepaa[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:3:33:
3 | real sepan[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:4:30:
4 | real rt[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:5:31:
5 | real xob[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:6:31:
6 | real npx[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:7:32:
7 | real*8 bb[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:8:32:
8 | real*8 bl[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:9:32:
9 | real*8 bu[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:10:34:
10 | real*8 cvec[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:11:32:
11 | real*8 ww[allocatable](:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:12:31:
12 | real*8 a[allocatable](:,:)
| 1
Error: Upper bound of last coarray dimension must be ‘*’ at (1)
modulos.f:24:13:
24 | use vars_common
| 1
Fatal error: Cannot open module file ‘vars_common.mod’ for reading
at (1): No such file or directory
compilation terminated.
你能帮我找到解决办法吗?最好使用 gfortran 作为编译器。谢谢
解决方法
这个 [allocatable]
不是标准的 Fortran。
代替
real sepaa[allocatable](:)
real sepan[allocatable](:)
Fortran 需要
real,allocatable :: sepaa(:)
real,allocatable :: sepan(:)
等等。还存在带有 dimension
属性或带有单独 allocatable
语句的替代方案。
如果不是太多地方,我建议手动进行修正。
您可以尝试询问您的主管它是哪种语法以及它应该如何编译。有可能他们不再知道他们是从哪里学到的,但至少他们可能知道他们为此使用了哪个编译器。但是,如果搜索并购买一些可以接受它作为扩展的编译器,我建议改正代码。
gfortran 告诉您的是标准 Fortran 使用方括号 coarrays。那些用于并行处理
real,allocatable :: A(:)[:]
我认为这与您的代码无关。