Optimization when creating static libraries with Intel Fortran

Dear friends,

I need to create a static library using Intel Fortran compiler (Windows) and I would like to use the speed optimization /O3. I follow the steps:

  1. /c to generate the object files.
  2. xilib to create the library file.
  3. I compile and link the main file with the library file.

However, in which step should I include the option /O3?

Many thanks for your kind help.

/O3 is particularly important during the compilation step. I do not think if it has any effects during the linking step (I may be wrong though), but specifying the flag at all stages of compilation and linking won’t hurt if not help with optimization. Intel website has excellent documentation of all of the ifort Fortran compiler flags including O3. What you probably need to specify at link time is the /Qipo interprocedural optimization flag between files. Here is a set of optimization flags that I typically use: /O3 /Qip /Qipo /Qunroll /Qunroll-aggressive. You could likely generate even faster code by specifying hardware-specific optimization flags. Use /Qparallel to enable auto-parallelization of Fortran do concurrent and other parallel features of Fortran (although, auto parallelization is not guaranteed).

1 Like

I built static library in Linux with gfortran compiler. Here is my procedure:

  1. gfortran -O3 -c sub1.f90 sub2.f90
  2. ar rcs libtest.a sub1.o sub2.o
  3. gfortran -O3 main.f90 -I. -L. -ltest

So I think that the optimization flag is added at your first and third steps.

@shahmoradi, @CYehLu many thanks for your help.

With ifort, there’s no point in using xilib unless you are also using -ipo, and if you ARE using -ipo to build a static library, you must link the executable with ifort -ipo or use xilink. -O3 indeed affects compilation only, not library/link.

1 Like

@sblionel, many thanks for your help.
Just to be sure I’m getting it right, the flag O3 should be incorporated only at the step 3, namely, when compiling and linking. Am I correct?

Many thanks.

No - use it for step 1 as well.