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

Linking to a static library that uses OpenMP directives

lxander
Novice
895 Views

I have a simple program compiled with Intel Fortran Classic that links to a static library using OpenMP directives (including !$omp SIMD on a couple of loops).  When I compile the static library, I can see that there has been optimisation and that the loops I want vectorised have (supposedly) been vectorised.  Then I compile the main program under /O3 and /Qopenmp (same as for the library); no errors, everything looks good.  But when I profile the program using Intel Advisor it tells me that the loops that I thought I had vectorised (in the static library) are scalar.

In an effort to chase down what is going on, I moved the subroutines with the loops I want vectorised from the static library to the main program.   Compiling again and then profiling using Intel Advisor, I see that the loops (that were previously in the static library and are now in the main program) are now vectorised.  That leads me to suspect that the optimisation (supposedly) happening when the static library is compiled isn’t making its way to the main program.  Am I missing an option when compiling the static library?  Do I need to specify something special when linking the main program?  How do I make it so that the code in my static library (with OpenMP SIMD) directives works the same (and performs as well) as if it were compiled in the main program?

Labels (2)
0 Kudos
3 Replies
jimdempseyatthecove
Honored Contributor III
850 Views

What happens when you link the .obj file generated in the static library build directly into your main application as opposed to via the static library?

 

Also, the optimized code generated, especially for code that can vectorize, most often has data alignment checks (as well as CPU instruction set availability checks) and then takes one of multiple code paths. This may be the case of data alignment is different.

Additionaly, intraprocedural optimizations may have inlined the non-library build and was able to determine/have aligned data.

 

Jim Dempsey

0 Kudos
Alina_S_Intel
Employee
811 Views

Thank you for your question. To assist you better, we need some additional information:

  • compiler version
  • reproducer
  • environment details, i.e. operating system, Visual Studio version if applicable

0 Kudos
Steve_Lionel
Honored Contributor III
802 Views

You're building a static library, but how are you linking? The OpenMP library on Windows is DLL-only. 

If you build your library with /Qipo and your main program too, then there will be whole-program optimization including the library.

0 Kudos
Reply