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

Unable to access external function

Ling_Meng-chieh
Beginner
1,561 Views

Dear all

   This morning I faced a trouble with access violation (severe 157) to an external function F2 in an external subroutine and I could not identity which step went wrong (I suspect I miss something but do not know which one), so I am here to ask for help. I am using Visual Studio 2010 (Fortran 90). 

   My program looks like:

   Program Block-Matrix
   .
   .
   Interface 
   subroutine tridiagonalization(xi_0, nshell, lambda, epsilo, t, V, count2)
   include 'link_fnl_shared.h'
   include 'link_fnl_static.h'

   use umach_int
   use csitg_int
   use csval_int
   use csint_int
   use FMZM (some MP package)
   use RLINE_INT
   use QDAGS_INT

   implicit none

   real(kind(1d0)), intent(in) :: lambda, V
   real(kind(1d0)), intent(out) :: xi_0
   integer, intent(in) :: nshell, count2
   real(kind(1d0)), dimension(0:nshell), intent(out) :: epsilo, t

   end subroutine
   .
   .
   End Interface
   .
   .
   End program
    

   Subroutine tridiagonalization(xi_0, nshell, lambda, epsilo, t, V, count2)

   use package shown above in the interface

   some variables (kind(1d0))

   real(kind(1d0)) :: F2
   external :: F2

   call D_QDAGS(F2, Lambda**(-i-1), Lambda**(-i), numerator) <-- The compiler indicate the access violation here 

   end subroutine

   real function F2(x, B_0, B_1)
   real(kind(1d0)), intent(in) :: B_0, B_1 (some parameters from data fitting )
   real(kind(1d0)) :: x
   
   F2 = B_0*x + B_1*x**2

   End function. 

   I will appreciate your help if any of you can point out at which step I made a stupid mistake.

Best

Meng-Chieh

 

0 Kudos
11 Replies
Les_Neilson
Valued Contributor II
1,561 Views
As you have it written : In your routine TriDiagonalization you tell the compiler that F2 is real(kind=1d0) i.e. double precision. But in F2 you have it decaled as just real i.e. single precision. Les
0 Kudos
Ling_Meng-chieh
Beginner
1,561 Views
Hi Les First, thank you for your reply. Now the problem becomes how to declare F2 as double precision? Best Meng-Chieh
0 Kudos
Les_Neilson
Valued Contributor II
1,561 Views
real(kind(1d0)) function f2 .... You might also read up on using RESULT for functions. (and SELECTED_REAL_KIND for declaring real types might be useful to know) function fn(...) result (r) integer dp = SELECTED_REAL_KIND(6,70) ! sets dp to 8 real(dp) r Les
0 Kudos
Ling_Meng-chieh
Beginner
1,561 Views
Hi It does not work. Everything goes well during compile, but it fails when debugging. Best Meng-Chieh
0 Kudos
Ling_Meng-chieh
Beginner
1,561 Views
Hi It does not work. Everything goes well during compile, but it fails when debugging. Best Meng-Chieh
0 Kudos
Les_Neilson
Valued Contributor II
1,561 Views
Well I shall try for the fourth time to submit a reply :-( Fails how? Incorrect answers ? Error message ? if so what message? Have you turned on all compile and runtime debugging checks (uninitialised variables, array bounds check etc.) Are you stepping through the code in debug mode, examining the contents of your data variables up to the point of failure? Les
0 Kudos
Les_Neilson
Valued Contributor II
1,561 Views
Well I shall try for the fourth time to submit a reply :-( Fails how? Incorrect answers ? Error message ? if so what message? Have you turned on all compile and runtime debugging checks (uninitialised variables, array bounds check etc.) Are you stepping through the code in debug mode, examining the contents of your data variables up to the point of failure? Les
0 Kudos
Ling_Meng-chieh
Beginner
1,561 Views
Hi I upload the error message (see the attached .jpg file). Those messages above are not important, it might be just a warning from linear fitting routine since I gave the routine two points. Array bound should be fine since if it was wrong, there would be another message for it. As for the variables, some shows undefined address but when I print them out they are correct (sorry that I am not a hard-core programmer). Thanks Meng-Chieh
0 Kudos
Les_Neilson
Valued Contributor II
1,561 Views
Well from the view of the attached jpg your code is failing at line 415 in subroutine / function F1 Access violation often means variables are being used but have not been initialised. Or there is an argument mismatch between what you are passing to a subroutine or function and what the subroutine / function says it expects. If there are no argument mismatches then you should put a break point in F1 somewhere before this line and run debug stepping through the code till you find where the error is. Les
0 Kudos
Ling_Meng-chieh
Beginner
1,561 Views
I think I have solve the problem. The root of this problem might come from that the subroutine for integration can only accepts one variables. So if there are more than one variables, it confuses the subroutine and we obtain the error message. Thank you for your help Meng-Chieh
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,561 Views
To assist in weeding out interface issues, declare the interfaces only within a module (used specifically for interfaces) then USE the interface module in both the PROGRAM (and it's subroutines and functions) as well as in the DLL (subroutines and functions). To be specific: USE the same module file for all components of callers and callees of the particular interface(s). Do not copy and paste interfaces into multiple sources. Not only will changes in one place not propigate to others, but compile time options and/or other INCLUDE, #INCLUDE, USE may affect the interpretation of the interface, whereas the compiled MOD file will (should) have but one interpretation. Jim Dempsey
0 Kudos
Reply