Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fortran错误:变量的大小太大_Fortran_Size - Fatal编程技术网

Fortran错误:变量的大小太大

Fortran错误:变量的大小太大,fortran,size,Fortran,Size,我有一个很长的程序,目标是求解矩阵系统ax=b。当我运行它时,它显示“错误:变量的大小太大” 注:GE(AA,BB,XX,3*NBE)是求解矩阵系统的函数。下面是GE的功能 subroutine GE(a,b,x,n) !=========================================================== ! Solutions to a system of linear equations A*x=b ! Method: Gauss elimination (

我有一个很长的程序,目标是求解矩阵系统ax=b。当我运行它时,它显示“错误:变量的大小太大”

注:
GE(AA,BB,XX,3*NBE)
是求解矩阵系统的函数。下面是GE的功能

subroutine GE(a,b,x,n)
!===========================================================
! Solutions to a system of linear equations A*x=b
! Method: Gauss elimination (with scaling and pivoting)
!-----------------------------------------------------------
! input ...
! a(n,n) - array of coefficients for matrix A
! b(n) - array of the right hand coefficients b
! n - number of equations (size of matrix A)
! output ...
! x(n) - solutions
! coments ...
! the original arrays a(n,n) and b(n) will be destroyed
! during the calculation
!===========================================================

implicit none
integer n
double precision a(n,n),b(n),x(n)
double precision s(n)
double precision c, pivot, store
integer i, j, k, l

! step 1: begin forward elimination
do k=1, n-1

! step 2: "scaling"
! s(i) will have the largest element from row i
do i=k,n ! loop over rows
s(i) = 0.0
do j=k,n ! loop over elements of row i
s(i) = max(s(i),abs(a(i,j)))
end do
end do

! step 3: "pivoting 1"
! find a row with the largest pivoting element
pivot = abs(a(k,k)/s(k))
l = k
do j=k+1,n
if(abs(a(j,k)/s(j)) > pivot) then
pivot = abs(a(j,k)/s(j))
l = j
end if
end do
! Check if the system has a sigular matrix
if(pivot == 0.0) then
write(*,*) "The matrix is singular"
return
end if

! step 4: "pivoting 2" interchange rows k and l (if needed)
if (l /= k) then
do j=k,n
store = a(k,j)
a(k,j) = a(l,j)
a(l,j) = store
end do
store = b(k)
b(k) = b(l)
b(l) = store
end if

! step 5: the elimination (after scaling and pivoting)
do i=k+1,n
c=a(i,k)/a(k,k)
a(i,k) = 0.0
b(i)=b(i)- c*b(k)
do j=k+1,n
a(i,j) = a(i,j)-c*a(k,j)
end do
end do
end do

! step 6: back substiturion
x(n) = b(n)/a(n,n)
do i=n-1,1,-1
c=0.0
do j=i+1,n
c= c + a(i,j)*x(j)
end do
x(i) = (b(i)- c)/a(i,i)
end do

end subroutine GE

将数组(至少
AA
BB
XX
)转换为可分配数组,并在代码中自行分配。您正在达到静态分配数组的内存限制。如果我记得清楚的话,某些系统的容量限制为2GB(专家会确认或给出正确的数字)。

何时打印?你有没有试着找出电话号码?确切的错误消息是什么?它能在GE内部吗?(你必须展示一下。)在
write
s和其他输入/输出语句中使用
iostat=
可能会很有用。先生,我已经发布了GE函数。当FML=FMH=20或40时,我可以获得txt文件,但当FML=FMH=80时,它告诉我变量“aa”的大小太大large@VladimirFPlease发布更多信息,包括什么编译器和编译时选项,以及完整的错误输出。但是在您的代码
FML
FMH
中,不会影响
AA
的大小,是吗?或者您实际上是否使用了注释掉的版本
NBE=FN*FML*FMH
?发布所有相关信息,包括罗斯要求的信息。不要彻底改变你的问题。这完全否定了现有的答案!如果您有关于新代码的新问题,请在别处询问。谢谢,先生!所以我需要将代码修改为:双精度,维度(:,:),可分配::AA双精度,维度(:),可分配::BB双精度,维度(:),可分配::XXYes,你知道了。在开始使用这些变量之前,请在代码中分配(AA(3*NBE,3*NBE),BB(3*NBE),XX(3*NBE))如果我使用分配(AA(3*NBE,3*NBE),BB(3*NBE),XX(3*NBE)),我不需要重新定义变量?我不确定我是否理解你的意思。无论如何,当您将其声明为可分配时,您需要allocate语句为这些变量请求内存空间。我也这么认为,但请注意,在问题中的代码中,数组的大小是一个常量,不取决于任何FML或FMH。但是OP一直在改变密码,所以我们真的不能相信他真正的密码是什么。我昨天在评论中问了这个问题,因为我认为这是答案,但没有回应。。。
subroutine GE(a,b,x,n)
!===========================================================
! Solutions to a system of linear equations A*x=b
! Method: Gauss elimination (with scaling and pivoting)
!-----------------------------------------------------------
! input ...
! a(n,n) - array of coefficients for matrix A
! b(n) - array of the right hand coefficients b
! n - number of equations (size of matrix A)
! output ...
! x(n) - solutions
! coments ...
! the original arrays a(n,n) and b(n) will be destroyed
! during the calculation
!===========================================================

implicit none
integer n
double precision a(n,n),b(n),x(n)
double precision s(n)
double precision c, pivot, store
integer i, j, k, l

! step 1: begin forward elimination
do k=1, n-1

! step 2: "scaling"
! s(i) will have the largest element from row i
do i=k,n ! loop over rows
s(i) = 0.0
do j=k,n ! loop over elements of row i
s(i) = max(s(i),abs(a(i,j)))
end do
end do

! step 3: "pivoting 1"
! find a row with the largest pivoting element
pivot = abs(a(k,k)/s(k))
l = k
do j=k+1,n
if(abs(a(j,k)/s(j)) > pivot) then
pivot = abs(a(j,k)/s(j))
l = j
end if
end do
! Check if the system has a sigular matrix
if(pivot == 0.0) then
write(*,*) "The matrix is singular"
return
end if

! step 4: "pivoting 2" interchange rows k and l (if needed)
if (l /= k) then
do j=k,n
store = a(k,j)
a(k,j) = a(l,j)
a(l,j) = store
end do
store = b(k)
b(k) = b(l)
b(l) = store
end if

! step 5: the elimination (after scaling and pivoting)
do i=k+1,n
c=a(i,k)/a(k,k)
a(i,k) = 0.0
b(i)=b(i)- c*b(k)
do j=k+1,n
a(i,j) = a(i,j)-c*a(k,j)
end do
end do
end do

! step 6: back substiturion
x(n) = b(n)/a(n,n)
do i=n-1,1,-1
c=0.0
do j=i+1,n
c= c + a(i,j)*x(j)
end do
x(i) = (b(i)- c)/a(i,i)
end do

end subroutine GE