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

Passing allocateable array to a FORTRAN DLL

Muhammad_S_2
Beginner
477 Views

I hope you would not mind my ignorance. I am having a hard time trying to figure out how I can pass an allocatable array from a subroutine to a FORTRAN DLL, or if I am doing anything wrong. The source below does work and the values inside the allocateable array is passed to FORTRAN DLL, but it may seem that it may be overwriting something else? Below is the sample code which we are using currently:

      SUBROUTINE CL1(J1)
      REAL*4, ALLOCATABLE :: FFF(:,:)

! HERE I READ A LOGICAL FILE AFTER WHICH I KNOW THE SIZE OF MY ARRAY (ND AND NTSTEPS)
IF(.NOT.ALLOCATED(FFF)) THEN
  IATTEMPT1 = 1
  ALLOCATE (FFF(ND,NTSTEPS), STAT= IALLOC1)
END IF

! Here I will call the DLL file and pass on the allocatable array and the size as arguments

CALL NUKE(FFF,ND,NTSTEPS)

IF(ALLOCATED(FFF)) THEN
  DEALLOCATE(FFF, STAT= IDEALL1)
END IF

RETURN
END

SUBROUTINE NUKE(FFF,NX,NS)

!Expose subroutine NUKE to users of this DLL

!DEC$ ATTRIBUTES DLLEXPORT::NUKE

DIMENSION FFF(NX,NT) 

! DO SOME MORE CALCULATION AND PASS THIS ARRAY TO OTHER SUBROUTINES

RETURN
END

 

0 Kudos
4 Replies
mecej4
Honored Contributor III
477 Views

As long as you do not treat FFF as an allocatable argument in NUKE or other subroutines called from NUKE, things should work fine. What you cannot do in the DLL is to evaluate ALLOCATED(FFF), attempt to deallocate, reallocate or obtain the size of FFF.

What makes you suspect that "it may seem that it may be overwriting something else"?

0 Kudos
Muhammad_S_2
Beginner
477 Views

Mecej,

Thank you for your response. I am not sure, but it seems that the program does not return correct values after initial iteration is performed (iteration means that the allocateable array is passed to the DLL and back).

This may be due to some other reason like not being able to access logical file on subsequent iterations etc, but I think I will have to debug through the source to reach a conclusion.

Can you please also suggest a better approach on how allocatable arrays can be passed to DLLs?

Thank you! 

 

0 Kudos
Steven_L_Intel1
Employee
477 Views

There is nothing special about allocatable arrays here. You will need to debug the program to find out what is going wrong.

0 Kudos
Muhammad_S_2
Beginner
477 Views

Steve,

You are right, the allocatable array is working correctly. There was another issue in my source which was causing this issue.

Thank you Steve and Mecej for your help. 

0 Kudos
Reply