Software Archive
Read-only legacy content

Array limits

Intel_C_Intel
Employee
393 Views
Hello Everyone and thank you for your time in advance;
My problem is in a DLL function to which I am sending in the dimensions of some matrices as arguments (NROW and NCOL). If I initialize the matrices as follows
!DEC$ ATTRIBUTES C, DLLEXPORT :: PHASEONE 
INTEGER FUNCTION PHASEONE(NROW, NCOL)  
... 
REAL ELEV(2000,2000), SCT(2000,2000) 
... 

I don't get any problems whereas if the above excerpt is changed to
 !DEC$ ATTRIBUTES C, DLLEXPORT :: PHASEONE 
INTEGER FUNCTION PHASEONE(NROW, NCOL)  
... 
REAL ELEV(NROW,NCOL), SCT(NROW,NCOL) 
... 

Calling the function with any number greater than 250 or so results in an "unknown software exception" !! error, i.e. the call "catchflow.Call({1000, 1000})" fails for the second case.

I'll appreciate any help to clarify this problem.

Greetings

Derya
0 Kudos
2 Replies
Steven_L_Intel1
Employee
393 Views
Your arrays are "automatic arrays", which means they are local variables allocated on the stack. The stack has a fixed size determined when the executable is linked, which in this case, is whatever you are calling the DLL from (I don't recognize the syntax you're using). What that means is - you probably can't change the size.

Consider this alternative:
INTEGER FUNCTION PHASEONE (NROW, NCOL)
REAL, ALLOCATABLE :: ELEV(:,:), SCT (:.:)
...
ALLOCATE (ELEV(NROW,NCOL),SCT(NROW,NCOL))
...

This will accomplish the goal of having a run-time sized array, and you won't be limited by the stack size, since the arrays will be allocated from the heap. They will get deallocated automatically when PHASEONE exits.

Incidentally, I am not comfortable with having the ATTRIBUTES directive BEFORE the FUNCTION statement. I am not sure if this really works (I'd have to run some tests) - the more common usage is to have the directive after the FUNCTION or SUBROUTINE statement.

Steve
0 Kudos
durisinm
Novice
393 Views
Can somebody give me a brief explanation of what the stack and heap are? They appear to be two different pools of memory that a program can use, and their sized appear to be governed by different limits.

Mike
0 Kudos
Reply