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

EXE vs. DLL, and recursive subroutine

bertazza
Beginner
895 Views

Dear forum users,

I'm trying to convert an EXE to a DLL. The DLL compiles ok, and I can call it without problems from Java using the JNI.

But, while the EXE runs ok, the DLL seems to get stuck in a recursive routine. So the EXE can successfully complete the processing, but the DLL goes on forever. The EXE and DLL source codes are identical, except for the few modifications required to implement a DLL.

The code runs over a 2D grid, and for each grid cell (at position col, row) calls the following recursive subroutine. The subroutine gets stuck when the conditions for calling it again are not met for the first time.

recursive

subroutine dry_upward_cell(col, row)

use

fill_mdl

implicit none

integer

col, row, j

integer

max_depth

! ----------------------

sh_col = (/ 0, -1, -1, -1, 0, 1, 1, 1 /)

sh_row = (/ 1, 1, 0, -1, -1, -1, 0, 1 /)

max_depth = 2000

depth = depth + 1

if

(depth.le.max_depth)then

do j = 1, 8

if(gDEM(col+sh_col(j),row+sh_row(j)).ne.esterno)then

if(gW(col+sh_col(j),row+sh_row(j)).eq.huge)then

if(mod(j,2).eq.1.and.gDEM(col+sh_col(j),row+sh_row(j)).ge.gW(col,row)+gEps1(col,row))then

gW(col+sh_col(j),row+sh_row(j)) = gDEM(col+sh_col(j),row+sh_row(j))

call dry_upward_cell(col+sh_col(j),row+sh_row(j))

elseif(mod(j,2).eq.0.and.gDEM(col+sh_col(j),row+sh_row(j)).ge.gW(col,row)+gEps2(col,row))then

gW(col+sh_ col(j),row+sh_row(j)) = gDEM(col+sh_col(j),row+sh_row(j))

call dry_upward_cell(col+sh_col(j),row+sh_row(j))

endif

endif

endif

enddo

endif

depth = depth - 1

return

end subroutine

Any idea why the EXE and the DLL do not behave in the same way, and the DLL gets stuck?

Thanks a lot

Alberto

0 Kudos
3 Replies
Steven_L_Intel1
Employee
895 Views
Where is DEPTH declared? What do you mean by "stuck"? This should be easy to debug.
0 Kudos
bertazza
Beginner
895 Views

Hi Steve,

thank you for your reply.

DEPTH is declared as integer in the module fill_mdl.

To debug the DLL, I open a dummy text file, and put some write statements around the code, to try see where the problem is. The last thing the code does is exiting the if(depth.le.max_depth)then, endif construct. After that, nothing: the recursive subroutine is not called again, nor the execution returns to the calling subroutine.

Could it be a problem related to the number of times the recursive subroutine is called? Is there some limit to that?

The interesting thing is that, as I mentioned, the executable version of this code runs flawlessy.

Alberto

0 Kudos
bertazza
Beginner
895 Views

Steve,

please ignore my last post, I didn't look with enough attention. I now narrowed down the problem to another part of the code calling the recursive subroutine. The problem is not related to the recursive subroutine then, but toa do construct and some logical variables controlling it.

I will investigated the problem further and get back to you if I work out why the executable works and the DLL doesn't.

Sorry about wasting your time.

Alberto

0 Kudos
Reply