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

Ifx/ifort upgrade issue

Fortrain
Beginner
344 Views
I frequently work with an external subroutine that is called via a .dll file - it is proprietary so I don’t have access to the source code, and it is all pre-compiled. This subroutine uses COMMON blocks extensively behind the scenes (which I DO have access to) - both for input and output values. All in all, there are around 70 common blocks that are referenced by this subroutine. I don’t think the code has been touched since the 60s, and there are things like Hollerith constants all over the place.

Calling this routine worked fine when my main program was compiled using ifort. However, if I compile my main program with ifx, the subroutine fails, and either gets stuck in an infinite loop or completely crashes. Since it is basically a black box dll file, I don’t have access to any diagnostics or anything to figure out why or where it is breaking. My best guess is that it’s an issue with data types or variable initialization: the only error it does give is “The value of integer variable X should be 1 or 2. The current value is -856384859087.”

Does anyone have any insights on what could cause this, or what steps I can take to troubleshoot it? A snippet of my code is below:

‘’’
Program Main
Implicit None

#include Globals.cmn

Integer X,Y,Z
Real*8 Val1, Val2
Parameter (X = 1, Y=3, Z = 7)
Val1 = 23.2

Call Calcs(X,Y,Z,Val1,Val2)
Write(*,*) Val2, GVAR56
End program main
‘’’

0 Kudos
4 Replies
Steve_Lionel
Honored Contributor III
309 Views

I might guess that it's related to this issue from the Release Notes:

BLOCK DATA

  • On Windows systems, a subprogram built into a library that references a common block variable initialized in a BLOCK DATA subprogram that is compiled separately and linked with the library will not get initialized but will have a zero value.  The workaround for this problem is to compile the subprogram and the BLOCK DATA subprogram together, or pass the object file with BLOCK DATA separately on the link line.

but I'm having difficulty trying to see how this combines with a DLL. Does your include file declare the common blocks with ATTRIBUTES DLLIMPORT? This is required if accessing common blocks from a DLL.

I'm going to put together a small test and see if I can reproduce a problem.

Fortrain
Beginner
298 Views

Yes - all of them do include !DIR$ ATTRIBUTES DLLIMPORT.

0 Kudos
Steve_Lionel
Honored Contributor III
297 Views

OK, I built a test case that imported a common block from a DLL and it worked.  I reproduce it below.  Your DLL's code must have been touched since the 60s as if it requires sharing a common block from a DLL then source changes not created until the late 90s would be required.

dll1.f90

subroutine foo
    implicit none
    !DIR$ ATTRIBUTES DLLEXPORT :: foo
    character(4) :: cx
    common /cmn/ cx
    !DIR$ ATTRIBUTES DLLEXPORT :: /cmn/
    print '(A,1X,Z16)', "In Foo, LOC(cx) is ", LOC(cx)
    print *, cx
    return
    end
block data
    integer :: cx
    common /cmn/ cx
    data cx /'FAIL'/
    end block data

console1.f90

    program Console1

    implicit none

    character(4) :: cx
    common /cmn/ cx
    !DIR$ ATTRIBUTES DLLIMPORT :: /cmn/
    external :: foo
    !DIR$ ATTRIBUTES DLLIMPORT :: foo
    
    cx = 'PASS'
    print '(A,1X,Z16)', "In Main, LOC(cx) is", LOC(cx)
    call foo 

    end program Console1

Build and run:

D:\Projects\Dll1\Console1>ifx /dll dll1.f90
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2025.1.0 Build 20250317
Copyright (C) 1985-2025 Intel Corporation. All rights reserved.

Microsoft (R) Incremental Linker Version 14.43.34809.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:dll1.dll
-dll
-implib:dll1.lib
dll1.obj
   Creating library dll1.lib and object dll1.exp

D:\Projects\Dll1\Console1>ifx console1.f90 dll1.lib
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2025.1.0 Build 20250317
Copyright (C) 1985-2025 Intel Corporation. All rights reserved.

Microsoft (R) Incremental Linker Version 14.43.34809.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:console1.exe
-subsystem:console
console1.obj
dll1.lib

D:\Projects\Dll1\Console1>console1.exe
In Main, LOC(cx) is     7FF874E83000
In Foo, LOC(cx) is      7FF874E83000
 PASS

D:\Projects\Dll1\Console1>
0 Kudos
andrew_4619
Honored Contributor III
227 Views

Maybe a naive question but is your DLL 32bit or 64bit? IFX is producing only 64 bit code, what did your IFORT setup generate?

Given there are no interfaces specified your are passing to Calcs by reference i.e. passing 64bit addresses.....

 

0 Kudos
Reply