- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We have a large solution in Visual Studio 2010 which comprises a Fortran exe and multiple Fortran and C++ static library projects:
FORTRAN EXE --> MY_LIB (C++)
--> MY_LIB_2 (C++)
--> MY_LIB_3 (Fortran)
We have encountered a problem with the run-time performance of the EXE diminishing by about 50% after modifying a C++ static library dependency.
Everything was running fine until we referenced some additional header files in one of the C++ libs. These headers are contained in a project that does not contain any source files, only C++ header files, and therefore does not produce any compiled output of its own:
FORTRAN EXE --> MY_LIB (C++, now includes headers from headers-only project)
--> MY_LIB_2 (C++)
--> MY_LIB_3 (Fortran)
The reason that the headers-only aspect is significant is that it is not possible to set optimizations for a C++ project in Project Properties unless it contains source (.c/.cpp files) and produces some output. However, when included elsewhere, the headers will be subject to the same optimizations as the including project. We’re not doing anything in the code the disables optimizations (e.g. with pragmas).
After the change our code now runs about 50% as fast as it did before. We are calling only one function in the newly included headers which carries little overhead and does not account for the slowdown. Profiling in AQTime reveals that the slowdown is consistent throughout the code.
What I believe may be causing this is optimizations being inadvertently disabled. At the point the Fortran EXE is linked, we receive a large number of C4748 warnings about optimisations having been disabled in various functions defined in the newly included headers, as well as in <memory> and other cpp files that also include them (we didn’t receive these before including the additional headers):
------ Build started: Project: FortranEXEProject, Configuration: Release Win32 ------
Linking...
Creating library D:\Source\Release\FortranEXEProject.lib and object D:\Source\Release\FortranEXEProject.exp
Generating code
c:\program files (x86)\microsoft visual studio 10.0\vc\include\memory(620) : warning C4748: /GS can not protect parameters and local variables from local buffer overrun because optimizations are disabled in function
d:\Source\CPPHeaderLibrary\header1.hpp(3231) : warning C4748: /GS can not protect parameters and local variables from local buffer overrun because optimizations are disabled in function
d:\Source\CPPSourceLibrary\source.cpp(54) : warning C4748: /GS can not protect parameters and local variables from local buffer overrun because optimizations are disabled in function
…
All projects have optimizations enabled and are using link-time code generation (/LTCG).
Process explorer reveals that that the Fortran linker XLink.exe is calling the C++ linker, LINK.exe.
Can you explain what is happening here please, and how to ensure that optimizations in linked C++ code are maintained?
Thanks in advance.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page