Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Module members used in declarations

longthong
Beginner
1,102 Views

MS Windows XP
Compaq Visual Fortran Professional Edition 6.6.C
WIN32 framework

The following code snippets have me wondering what I am doing wrong. I haven't found anything in the documentation saying that the following is illegal. What is more disturbing is that all of these options compile without error but they won't execute. The cases that use module members in declarations never gets executed. It just bombs out.

use Nut3DGlobals,only : nCol,nRow
.
.
! real(4):: DumArray(nCol,nRow) ! this does not work!
! real,dimension(nCol,nRow) :: DumArray! this does not work!
! real(4):: DumArray(800,600) ! this is ok!
real(4),allocatable :: DumArray(:,:) ! this works
! I guess you can't use members of a module in declarations??
.
.
allocate(DumArray(nCol,nRow)) ! This works
. ! nCol and nRow ARE defined

0 Kudos
6 Replies
Steven_L_Intel1
Employee
1,102 Views

Can you show a small but complete program that doesn't work? What does "bombs out" mean?

0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,102 Views

Can you show a small but complete program that doesn't work? What does "bombs out" mean?

It "bombs out" with a stack overflow. Declaring local variables like that is standard Fortran -- these are called "automatic arrays". The difference comes in implementation -- automatic arrays go to the stack, and allocatable to the heap.

The default stack size in CVF (more precisely, Microsoft linker) is fairly small -- 1 MB -- and your DumArray is close to 2MB. So, either increase stack size while compiling, or stick to allocatable arrays.

0 Kudos
longthong
Beginner
1,102 Views

Can you show a small but complete program that doesn't work? What does "bombs out" mean?


I shall work on a small program tnat "bombs out". "bombs out" in this case means that it never entered the code section of the sub that made the declaration. If you have as much trouble as I have bombing out you know the meaning of the term.

DT

0 Kudos
Steven_L_Intel1
Employee
1,102 Views

The trouble is that "bombs out" has many different possible meanings, each with its own cause. I would prefer to see the complete and exact text of any error message or a description of the actual behavior.

0 Kudos
longthong
Beginner
1,102 Views

The trouble is that "bombs out" has many different possible meanings, each with its own cause. I would prefer to see the complete and exact text of any error message or a description of the actual behavior.

Steve, you are right. I will be more carefull in the future. I forget that you and others are corresponding with many different threads.

I ran the three simple console apps litsed herein and, Yugoslav, you are right. I got "stack overflow" messages in the appropriate places. The automatic array DumArray is too large. I should have known that. Problem solved. Thank you both.

DT


module ConTest2Global
integer :: nCol,nRow! size of DumArray
end module ConTest2Global

program ConTest2
use ConTest2Global
nCol = 800
nRow = 600
call sub1()
end program ConTest2

subroutine sub1()
use ConTest2Global,only:nCol,nRow
real,dimension(nCol,nRow) :: DumArray ! this causes stack overflow
print * ,"Enter Sub1"
end subroutine Sub1

!********************************************************************

program ConTest2
call sub1()
end program ConTest2

subroutine sub1()
real,dimension(800,600) :: DumArray ! this works ok
print * ,"Enter Sub1"
end subroutine Sub1

!*********************************************************************

program ConTest2
call sub1(800,600)
end program ConTest2

subroutine sub1(nCol,nRow)
integer :: nCol,nRow
real,dimension(nCol,nRow) :: DumArray ! this causes stack overflow
print * ,"Enter Sub1"
end subroutine Sub1


0 Kudos
Steven_L_Intel1
Employee
1,102 Views

Add the /heap-arrays option and the error should go away.

0 Kudos
Reply