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

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

manh_nguyen
Beginner
4,374 Views

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 Kudos
29 Replies
manh_nguyen
Beginner
1,319 Views

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

0 Kudos
IanH
Honored Contributor III
1,319 Views

Show all code.  Show all compiler options.

0 Kudos
IanH
Honored Contributor III
1,319 Views

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?

0 Kudos
IanH
Honored Contributor III
1,319 Views

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?

0 Kudos
manh_nguyen
Beginner
1,319 Views

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?

0 Kudos
manh_nguyen
Beginner
1,319 Views

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,



0 Kudos
manh_nguyen
Beginner
1,319 Views

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?

0 Kudos
manh_nguyen
Beginner
1,319 Views

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

0 Kudos
manh_nguyen
Beginner
1,319 Views

linker option for DLL and calling program

0 Kudos
Reply