use a function written by Fortran source code in Qt,the result of function is right by 32bit compiler,the result is wrong by 64bit compiler
-
wrote on 6 Jul 2018, 11:58 last edited by
Hello Everyone:
I have recently met a strange problem about Qt&Fortran integrating program.In my Desktop App,the main function frame is written by Qt, I need a calculated function whose source code was written by Fortran,but not a .dll lib file.And I confirm that all the source code (Qt&Fortran) are right,The program could be compiled normally and run in my computer.I use 2 kind of compilers.The result of function which was compiled by 32-bit GNU-Mingw is right, I can get what I expected. However, when the code is compiled by 64-bit GNU-Mingw, Although the program can run , the result of calculated function is wrong. I check out the array matrix by qDebug, every value in my array is "NAN".I have doubt about the pointer is beyond the boundary of the array when the matrix is transferring from Qt to Fortran.My operating system is X86_64 Windows7.I really really what to know what is the reason for that problem and how to solve this fatal problem.Looking forward to your reply & Thanks again for your patience
tudiudiu -
Hello Everyone:
I have recently met a strange problem about Qt&Fortran integrating program.In my Desktop App,the main function frame is written by Qt, I need a calculated function whose source code was written by Fortran,but not a .dll lib file.And I confirm that all the source code (Qt&Fortran) are right,The program could be compiled normally and run in my computer.I use 2 kind of compilers.The result of function which was compiled by 32-bit GNU-Mingw is right, I can get what I expected. However, when the code is compiled by 64-bit GNU-Mingw, Although the program can run , the result of calculated function is wrong. I check out the array matrix by qDebug, every value in my array is "NAN".I have doubt about the pointer is beyond the boundary of the array when the matrix is transferring from Qt to Fortran.My operating system is X86_64 Windows7.I really really what to know what is the reason for that problem and how to solve this fatal problem.Looking forward to your reply & Thanks again for your patience
tudiudiuwrote on 6 Jul 2018, 14:21 last edited byHow were the Qt libraries compiled when you combine them with the 64bit compiled FORTRAN?
IIRC the question might if the memory model is the same for 64bit FORTRAN and C++ compiled with the same MinGW suite.
IMHO it is at the day's end not an issue of Qt, but more something with the compilers and the memory handling there.
-
Hello Everyone:
I have recently met a strange problem about Qt&Fortran integrating program.In my Desktop App,the main function frame is written by Qt, I need a calculated function whose source code was written by Fortran,but not a .dll lib file.And I confirm that all the source code (Qt&Fortran) are right,The program could be compiled normally and run in my computer.I use 2 kind of compilers.The result of function which was compiled by 32-bit GNU-Mingw is right, I can get what I expected. However, when the code is compiled by 64-bit GNU-Mingw, Although the program can run , the result of calculated function is wrong. I check out the array matrix by qDebug, every value in my array is "NAN".I have doubt about the pointer is beyond the boundary of the array when the matrix is transferring from Qt to Fortran.My operating system is X86_64 Windows7.I really really what to know what is the reason for that problem and how to solve this fatal problem.Looking forward to your reply & Thanks again for your patience
tudiudiuLifetime Qt Championwrote on 6 Jul 2018, 14:28 last edited by aha_1980 7 Jun 2018, 16:51@tudiudiu, as @koahnig already said this is more likely a compiler problem. As you already noted, it may be pointer related. 64 bit C++ compiler operate with 64 bit pointers, while 32 bit compilers use 32 bit pointers.
so the question: how do you combine your C++ and Fortran code? and which compiler do you use to compile fortran? do you compile Fortran to 64 bit also?
-
Hello Everyone:
I have recently met a strange problem about Qt&Fortran integrating program.In my Desktop App,the main function frame is written by Qt, I need a calculated function whose source code was written by Fortran,but not a .dll lib file.And I confirm that all the source code (Qt&Fortran) are right,The program could be compiled normally and run in my computer.I use 2 kind of compilers.The result of function which was compiled by 32-bit GNU-Mingw is right, I can get what I expected. However, when the code is compiled by 64-bit GNU-Mingw, Although the program can run , the result of calculated function is wrong. I check out the array matrix by qDebug, every value in my array is "NAN".I have doubt about the pointer is beyond the boundary of the array when the matrix is transferring from Qt to Fortran.My operating system is X86_64 Windows7.I really really what to know what is the reason for that problem and how to solve this fatal problem.Looking forward to your reply & Thanks again for your patience
tudiudiuwrote on 7 Jul 2018, 00:33 last edited by@tudiudiu said in use a function written by Fortran source code in Qt,the result of function is right by 32bit compiler,the result is wrong by 64bit compiler:
et a strange problem about Qt&Fortran integrating program.In my Desktop App,the main function frame is written by Qt, I need a calculated function whose source code was written by Fortran,but not a .dll lib file.And I confirm that all the source code (Qt&Fortran) are right,The program could be compiled normally and run in my computer.I use 2 kind of compilers.The result of function which was compiled by 32-bit GNU-Mingw is right, I can get what I expected. However, when the code is compiled by 64-bit GNU-Mingw, Although the program can run , the result of calculated function is wrong. I check out the array matrix by qDebug, every
Hi~~~@koahnig @aha_1980
In my Qt .pro file,the combine style is remarked as “lib += lgfortran,source += /abc.f90”.
In my Fortran file, the function is named as "sub(arg1,arg2,arg3......argN)"
In my main function file,Remark : extern "C" {void sub_(int *m, int *n, float x[], float fvec[], int *iflag);}
Then the Fortran's Subroutine is used by Qt as an external void function so that the compiler could compile the Qt & fortran at the same time. In my Qt Creator Edit , I have configured 2 kind of compile chain kit, MingW32 & MingW64. Even if the source code is same, but I can choose one compiler i need at one time(MingW32 or MingW64).As you already noted, the problem has something to do with the memory handling and pointer length.
The argument function in Fortran expect a 32-bit pointer transferred by Qt , but for 64bit compiler, the length of pointer is 64-bit. So I am planning to rewrite the Fortran code , for example "Integer *4 -> Integer 8, Real4 ->Double *8". I'm not sure whether it would work or not. I will reply to you @koahnig @aha_1980 as soon as i get the result.Really Appreciate for your guide And thanks again ~~~
tudiudiu
-
@tudiudiu said in use a function written by Fortran source code in Qt,the result of function is right by 32bit compiler,the result is wrong by 64bit compiler:
et a strange problem about Qt&Fortran integrating program.In my Desktop App,the main function frame is written by Qt, I need a calculated function whose source code was written by Fortran,but not a .dll lib file.And I confirm that all the source code (Qt&Fortran) are right,The program could be compiled normally and run in my computer.I use 2 kind of compilers.The result of function which was compiled by 32-bit GNU-Mingw is right, I can get what I expected. However, when the code is compiled by 64-bit GNU-Mingw, Although the program can run , the result of calculated function is wrong. I check out the array matrix by qDebug, every
Hi~~~@koahnig @aha_1980
In my Qt .pro file,the combine style is remarked as “lib += lgfortran,source += /abc.f90”.
In my Fortran file, the function is named as "sub(arg1,arg2,arg3......argN)"
In my main function file,Remark : extern "C" {void sub_(int *m, int *n, float x[], float fvec[], int *iflag);}
Then the Fortran's Subroutine is used by Qt as an external void function so that the compiler could compile the Qt & fortran at the same time. In my Qt Creator Edit , I have configured 2 kind of compile chain kit, MingW32 & MingW64. Even if the source code is same, but I can choose one compiler i need at one time(MingW32 or MingW64).As you already noted, the problem has something to do with the memory handling and pointer length.
The argument function in Fortran expect a 32-bit pointer transferred by Qt , but for 64bit compiler, the length of pointer is 64-bit. So I am planning to rewrite the Fortran code , for example "Integer *4 -> Integer 8, Real4 ->Double *8". I'm not sure whether it would work or not. I will reply to you @koahnig @aha_1980 as soon as i get the result.Really Appreciate for your guide And thanks again ~~~
tudiudiu
Hi @tudiudiu
I'm sorry, but I have absolutely no Fortran knowledge.
So if I understand you correctly, you have an entry
SOURCES += abc.f90
in your.pro
file. That means,abc.f90
is your Fortran source file, correct?That means,
qmake
generates aMakefile
which calls the Fortran compiler, correct too?So have you checked that the correct Fortran compiler (64 bit) is called for your 64 bit code?
Regards
-
Hi @tudiudiu
I'm sorry, but I have absolutely no Fortran knowledge.
So if I understand you correctly, you have an entry
SOURCES += abc.f90
in your.pro
file. That means,abc.f90
is your Fortran source file, correct?That means,
qmake
generates aMakefile
which calls the Fortran compiler, correct too?So have you checked that the correct Fortran compiler (64 bit) is called for your 64 bit code?
Regards
wrote on 7 Jul 2018, 09:24 last edited byIMHO the lack of Fortran knowledge is actually an advantage. I started out with Fortran very long ago and have pushed all knowledge to the back where the cobwebs reside ;)
More seriously. As @aha_1980 already mentions did you check that you are using 64 bit compilers in both cases?
Basically I would suggest that you are using the same MinGW compiler for both Fortran and C++.You did not give information of the library you are using from Fortran. I am typically going the route to convert Fortran to C/C++ and compile. However, that might be only an option with smaller libraries, since I was substituting the few Fortran emulating library calls with C/C++ calls when required.
-
wrote on 8 Jul 2018, 03:01 last edited by
@aha_1980 @koahnig
Hi~my friends,Thanks for your kindly help, And i have been trying to find this bug as the advice you give.First of all, I check the compilers to make sure there is only an effective tool chain. All of the source code were transferred to another machine(only with MingW64) to compile , The Result is still "NAN".However ,When the source code were transferred to a machine(only with MingW32) to compile, the Result is acceptable.
Secondly,I attempted to check whether there are a few lib(32bit dynamic or static) in Fortran code. At last, The result is that there is not other lib at all, The target function is written by pure Fortran format.
Thirdly, I rewrite part of the Fortran code with regarding to the variable declaration so that the length of variable could match the length of pointer in 64-bit system . For example "Integer *4 -> Integer 8, Real4 ->Double *8". But it doesn't work.
Finally, I change another new simple function ,Transfer a 2-Dimension matrix from Fortran to Qt, The result is totally correct.
So the bug seem to be nothing to do with the compilers .
I think the Fortran code i got from my company is wrong. I can't not imagine my colleague take that kind of stupid mistake , What makes me unexpected more is my boss have checked and give him "PASS".=_=|||I feel so apologetic for my fault.I should have think about this problem.
Sincerely gratitude for your help again.@aha_1980 @koahnigRegards
tudiudiu
1/7