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

IPO with ifort, Microsoft C++, and Visual Studio IDE

Matt_F_1
Beginner
1,388 Views
I'm trying to build a mixed C/F95 console application using ifort and the microsoft C compiler within the Visual Studio 2005 IDE. On the linux platform IPO improves performance significantly, but I have so far been unable to get IPO to work on Windows within the Studio IDE.

Due to how ifort integrates with VS, I've created a separate static library project with all of the F95 code, and link that into a DLL with all of the C source. There are circular dependencies between these two libraries and I have
thus far been unable to sort them out to build the fortran library as a DLL, and would rather have the single DLL in any case. On linux I simply compile everything to *.o, and then make one library with everything, but that does not seem to be a method easily supported by Visual Studio.

I've compiled the F95 sources with /Qipo (manual command-line option), but when creating the static F95 library ipo does not seem to perform any significant optimizations: the ipo report only shows some unused variable elimination, without any inlining, vectorization, etc I should get. The archive step only shows:

Creating library...
ipo: remark #11005: generating object file [filename]
[repeat above for each source file]

without any other messages indicating optimizations or analysis, except for "OpenMP DEFINED LOOP WAS PARALLELIZED." Furthermore, this seems to indicate that the archiver is stripping out all ipo information from the archive so that even if I could figure out how to get the IDE to use xilink versus the microsoft linker it would not help.

What is the preferred method for creating a fortran library using IPO with the Visual Studio IDE?


Thank you,
Matt
0 Kudos
10 Replies
Matt_F_1
Beginner
1,388 Views
If I instead build the C DLL as a static lib and the F95 code as a DLL (with the C lib linked in) this seems to cause the intel linker to be used. I finally see:

Linking...
ipo: remark #11000: performing multi-file optimizations
ipo: remark #11005: generating object file ipo_39126obj.obj

but looking at the ipo, hpo, ilo, hlo optimization reports still only shows unref var removal and pack merge. No vectorization or inlining is happening, or any other optimizations. The linux version shows all sorts of optimizations including vectorization, inlining, etc.

Is IPO seriously broken on Windows, at least with the IDE, or am I doing something wrong?

Thanks,
Matt
0 Kudos
TimP
Honored Contributor III
1,388 Views
Microsoft and Intel whole program optimization object file formats aren't compatible, so you can't use either /Qipo or /GL when linking a combination of VC and ifort objects. In fact, you must set /GL- in such situations, if using a VS version where /GL is a default. /Qip (on by default) is no problem, if you can benefit from in-lining between Fortran functions in the same source file.
0 Kudos
Matt_F_1
Beginner
1,388 Views
So this means I must use the Intel C-compiler if I wish to use IPO across both C and F95 libraries?

Should my method of building a static F95 lib and linking it into a C-DLL work if I use the Intel C and F95 compilers?
0 Kudos
Steven_L_Intel1
Employee
1,388 Views
If you want the C code to participate in IPO, yes, you'll need to use Intel C++. Otherwise, the key is to link the application in an Intel Fortran project so that the Intel "pre-linker" is used. Try it as a Fortran exe and C static library and see how it works.
0 Kudos
Matt_F_1
Beginner
1,388 Views
It would be complicated to build a fortran EXE, as the top-level interface is C. I've tried to build as a Fortran DLL using a C-static lib, but have yet to get the top-level interface to work with that method (the F95 and C are intertwined). It seems like I'll either have to build three DLLs (Fortran, most of the C, and the C used by both of the others), or just get Intel C.

It's a shame Visual Studio makes it nearly impossible to specify another linker, and that you can't have a "mixed" C/F95 project as you evidently could with Compaq Fortran (and with my Makefile on Linux).

Thanks,
Matt
0 Kudos
Steven_L_Intel1
Employee
1,388 Views
You certainly can have a mixed C/Fortran project. Indeed, we provide samples in both directions. The issue you have is specific to using IPO with a mixed-language project when the C code is the main program and you are not using Intel C++. (Compaq Fortran had no such thing as IPO.) As for Linux, you also have to use ifort as the driver to build a program using IPO, so that's the same.

I was not suggesting you rewrite the program - but rather use a Fortran executable project even though the main program is in C. I think this should work.

You may find that the benefits of IPO when not using all Intel compilers is not worth the added effort.
0 Kudos
Matt_F_1
Beginner
1,388 Views
How do you have one project (not solution) with both C and F95 files? The examples I see with ifort have one solution with a fortran project with the fortran source and a C project with the C source. If I add main.c to a fortran console application project it does not do anything, nor give me any way to control the build (only a Fortran tab shows up in Properties). Similarly if I add all of my *.c and *.f files to either a C-DLL or Fortran-DLL project.

What one could do with Compaq Fortran within Visual Studio (not that I will use this) or with a Makefile is compile everything to *.obj (both C and F95) and then link that all into one library. This does not seem to be possible (or at least very difficult) with Visual Studio, at least with the Microsoft C compiler.

I think ifort and icc are great. I'm less impressed with Visual Studio; unfortunately that's been mandated on Windows.


0 Kudos
Steven_L_Intel1
Employee
1,388 Views
You can't mix languages in a project. You can build a mixed-language application, DLL or static library. This does require two projects in a solution, but little more than that. You are correct that this is a change imposed by Microsoft.

It is not clear to me what problem you are trying to solve. If you took a CVF mixed-language project and used the "Extract Compaq Visual Fortran Project Items" wizard, you should end up with a buildable solution. What is the current issue you are having?
0 Kudos
Matt_F_1
Beginner
1,388 Views
I don't have a Compaq Fortran project; that is just what others here are more familiar with.

The issue is getting IPO to work. For that, as you stated, requires using ifort to either link the executable or create the DLL. So I've discovered here (thanks!) that I need to build a static C library with the microsoft compiler (with /GL-), and link it into a fortran DLL (using /Qipo). I have yet to get that F95 DLL to work due to the intermingling of the C and fortran code. I'll try a bit more.

I think to make this easier, and get better IPO, I'll probably just purchase ICC.

Thanks,
Matt
0 Kudos
Matt_F_1
Beginner
1,388 Views
I've now used a trial version of ICL to build the DLL. So what I'm doing is:

- Build a static F95 library using /IPO /O3 /QaxT
- Build a DLL with the C-API that links in the above library (similar flags to above)

During the linking of the DLL I now see the message "ipo: performing multi-file optimization," but I have doubts that it is performing IPO correctly:

1) the executable that uses the DLL runs 12% slower than a Linux executable on the same hardware compiled with icc/ifort

2) using /Qopt-report:2 /Qopt-report-phase:all only shows unref variable elimination and pack-merge. No vectorization, inlining, etc are mentioned at all.

Note without /Qipo I do see messages about vectorization etc. Is /Qopt-report broken with IPO and the compiler is doing its best (and Windows is to blame for the 12% slowdown), or am I still not correctly using IPO?

I can supply the build logs if that would help. They are also included in the issue #507540.


Thanks,
Matt
0 Kudos
Reply