Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29250 ディスカッション

fortran return a different value respect to the one expected

afylot1
ビギナー
605件の閲覧回数

I checked with a debugger that a value of a variable(the name of the function) is computed, but then a different value is returned. I'd think this is related to type translation, but I don't see how. I have the following function.

double precision function func_energy(temp)
use func_params
implicit none
double precision energy_f_temp, temp
func_energy = energy_f_temp(temp, density) - p_invert
return
end function func_energy

func_params has been declared as the following

module func_params              
double precision, save :: p_invert
double precision, save :: density
end module func_params

I checked that the initialization of func_params is correct. When I am inside func_energy I found that

energy_f_temp(temp, density) - p_invert 

is equal to -42476827268725768, but then when I check at the next line the value of func_energy I get 588030290385264, and this is the value that is returned by the function. I don't understand what is going on. It looks to me that everything is double precision. What could be going wrong here?

I'm using ifort with compiler option:

-g -O0 -check bounds -warn all -traceback -align all -align rec8byte

These functions are part of a fortran library that I am calling from a C main program. I have read somewhere that when the calling convention are not right you could be corrupting the stack. Does it apply here? The point is that the error appeared suddently.

thanks

0 件の賞賛
1 返信
Steven_L_Intel1
従業員
605件の閲覧回数
Calling convention mismatch does not apply here. How is energy_f_temp declared? If it is not also double precision, you could have this problem.

Without a complete source we can build and run, it's very difficult to diagnose the problem. I'd suggest putting energy_f_temp and any other functions you call in a module and USEing that module, instead of relying on implicit interfaces., to make sure that everything is ok. -warn all will give you generated interface checking, but if you compiled the called routine later it would not pick that up.
返信