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

Fortran DLL slows down 2 times when called from Visual C++ in comparison to calling from Fortran

manh_nguyen
ビギナー
4,371件の閲覧回数

Hello everyone,

I have this problem, hope that you can help me out:

There is a subroutine in Fortran code that has been given to me. This Fortran code is acually a simulation model of a physical process, so there is a criteria of simulation speed. I compiled the Fortran code into a DLL file.

Then the DLL subroutine is called from a Fortran program by using Windows API functions LoadLibrary and GetprocessAdress, it gives a the speed ratio of 770 which means that it takes 1 second to simulate the physical process in 770 seconds real time

Next, i do the same thing but this time in C++, and this gives me a speed ratio of 380 which is 2 times slower than the calling from Fortran program

i have tried to get through the problem by setting the Runtime library option when compiling C++ program to  "Multithreaded DLL" which was set to the DLL but it did not resolve the problem

Anyone has any idea of what has happened with the call from C++?

Thanks for your help,

0 件の賞賛
29 返答(返信)
manh_nguyen
ビギナー
1,318件の閲覧回数

i have made a dll without anny input argument (something like "void DLL(void)"), then i simply call the function from both C/C++ and Fortran (there is no loops this time) the program C/C++ is always much slower than Fortran program

IanH
名誉コントリビューター III
1,318件の閲覧回数

Show all code.  Show all compiler options.

IanH
名誉コントリビューター III
1,318件の閲覧回数

For Fortran projects you can see the compile options in effect by right clicking on the project in the Visual Studio solution explorer and selecting Properties, then Fortran > Command line. 

You don't show the code for the DLL.

Those two console window screenshots appear to have different working directories.  Are you loading exactly the same DLL?  How do you ensure that?

IanH
名誉コントリビューター III
1,318件の閲覧回数

The fact that the factor between the two cases is very close to two is suspicious.  Is the CPU_TIME result printe by the program consistent with the elapsed time measured by your wrist watch?

The source code for the DLL is incomplete - you've only provided one subroutine.  That means readers of the forum can't compile your code and investigate things - they have to "head compile" what you've provided and hope that things that are called are inocuous.  Speaking for myself - my head compiler is notoriously buggy at the best of times.  If you don't want to post the full source, then chop it down yourself to a compilable and linkable subset that still exhibits the problem (as a debugging/diagnostic strategy you should be doing this anyway).  Otherwise we're all guessing.

What options are you using for the C program?

manh_nguyen
ビギナー
1,318件の閲覧回数

yes, it is correct compared to wrist watch

IanH wrote:

The fact that the factor between the two cases is very close to two is suspicious.  Is the CPU_TIME result printe by the program consistent with the elapsed time measured by your wrist watch?

manh_nguyen
ビギナー
1,318件の閲覧回数

i did copying from folder to folder to assure comparability, but its was not good. Now,  i copy 2 .exe file to the same folder and it gives same results. im sorry for that,



manh_nguyen
ビギナー
1,318件の閲覧回数

here are calling programs from dev-c++ and Visual Fortran, i dont understand why there is a slight difference in the result(comparison.JPG)

LanH, I can't find away to show all compiler option for you, is there a particular part you want to see?

manh_nguyen
ビギナー
1,318件の閲覧回数

steve, you can see the fortran code in .f90 and the C++ one in .cpp, .h files. bmchenrry, i used dev-c++ and intel fortran, the results are identical with both fortran and C++

Thx

manh_nguyen
ビギナー
1,318件の閲覧回数

linker option for DLL and calling program

返信