Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

Reducing the compiled size

Lars_Jakobsen
Beginner
503 Views
Hi,

We have just switched from usingCompaq visual fortran (CVF) incl IMSL to Intel Visual Fortran (IVF)without IMSLand therefor I am using IMKL to do FFT. I have included mkl_dfti.f90 in my project and enabled IMKL byincluding mkl_intel_c.lib mkl_sequential.lib mkl_core.lib (or alternatively /Qmkl:sequential). This all works fine. However the size of our applications (exe files) increases from approximately 2Mb (when using CVF)to 26Mb (when using IVF).I can track the cause to be inclusion of IMKL.

It seems to me that I am including the entire IMKL library, even though I only need the part doing FFT. Am I doing something wrong or is it common that the size will increase that much? Is it possible to limit the size by e.g. linking only to part of the IMKL?

Regards

Lars
0 Kudos
10 Replies
barragan_villanueva_
Valued Contributor I
503 Views
Lars,

You used static linking with MKL. Please link with dynamic MKL:
mkl_intel_c_dll.lib mkl_sequential_dll.lib mkl_core_dll.lib
or with single dynamic library (with additional setting to use sequential libs, see MKL doc)
mkl_rt.lib
0 Kudos
Lars_Jakobsen
Beginner
503 Views

Hi Victor,

This will indeed reduce the size of the .exe file. When counting the additional dll's that needs to be distributed(mkl_core.dll and mkl_sequential.dll) Iend up withapproximately 11Mb.

However this is still 4 times the size of my old code andI would rather have a static linked library.
Any suggestions are highly appreciated?

Thanks
Lars

0 Kudos
barragan_villanueva_
Valued Contributor I
503 Views
Hi Lars,

MKL static libraries from which custom library is built currently contain all supported CPU-codes since Pentium-4.
Therefore they are so big in size.
Do you need both single and double precision DFT transforms?
In case of one precision, you can reduce DLL size by selecting correct names in export list. See comments in DFT example list.
But if your application uses for exampleDFT with 2-power sizes only you can try to use IPP FFT libraries.
0 Kudos
Lars_Jakobsen
Beginner
503 Views
Hi Gennady and Victor,

Thank you both, I will look into both IPP and the DFT examples.

Regards

Lars
0 Kudos
Lars_Jakobsen
Beginner
503 Views
Hi Victor,
I found the example inmkl_dfti.f90 and tried to use

USE MKL_DFTI, FORGET=>DFTI_SINGLE, DFTI_SINGLE=>DFTI_SINGLE_R

This reduced the size of the exe from approximately 26Mb to 12Mb. However I am somewhat puzzled by the FORGET=>DFTI_SINGLE part of the above. From mkl_dfti.f90

[bash]  ! DFTI_PRECISION for reduced size of statically linked application.
  ! Recommended use: modify statement 'USE MKL_DFTI' in your program,
  ! so that it reads as either of:
  ! USE MKL_DFTI, FORGET=>DFTI_SINGLE, DFTI_SINGLE=>DFTI_SINGLE_R
  ! USE MKL_DFTI, FORGET=>DFTI_DOUBLE, DFTI_DOUBLE=>DFTI_DOUBLE_R
  ! where word 'FORGET' can be any name not used in the program.
[/bash]



What is meant by: ...word'FORGET' can be any name not used in the program?

Regards

Lars
0 Kudos
Dmitry_B_Intel
Employee
503 Views
Hi Lars,

Literally, you can replace word 'FORGET' with any other word which is not used in the program/function/subroutine that includes the USE statement.

Fortran statement
USE module-name, local-name => use-name, local-name => use-name
is a convenient way to redefine a use-name (the name injected into the program by
the USE statement) by rename operator '=>'.

Ifthe local-name that wewant toemploycoincides with a use-name,
then werun into the situation which is described by Fortran standard as
'two or more accessible entities have the same name'. This is ok unless the name
is referenced in the program and is not a generic name, which is not our case.

In other words, we cannotwriteDFTI_SINGLEat the left of '=>' until we
rename it by placing it at the right of '=>', whichis what we do in the firstrename.
Word 'forget' is not a keyword, it is chosen so to correctly convey the semantics
of the operation.

Thanks
Dima
0 Kudos
Lars_Jakobsen
Beginner
503 Views
Hi Dima,
Thank you for the explanation -this makes sense.

Additional question:
I tried to compile the code without the first rename i.e.

use MKL_DFTI, DFTI_SINGLE=>DFTI_SINGLE_R

and this compiles without error (and I get a reduced size of my executable). The full code looks like this:

[bash]subroutine FFTRF(nXi,nXo, X_in, X_out)
!-------------------------------------------------------------------------------
!
!-- Compute the Fourier coefficients of a real periodic sequence using Intel Math Kernel Library. 
!   Based on the example in the IMKL help.
!-------------------------------------------------------------------------------
    USE MKL_DFTI, DFTI_SINGLE=>DFTI_SINGLE_R
    implicit none

    integer                , intent(in)      :: nXi, nXo     ! number of points in X_OUT
    real(4), dimension(nXi), intent(in)      :: X_in         ! real sequence
    real(4), dimension(nXo), intent(in out)  :: X_out        ! fourier coefficients

    type(DFTI_DESCRIPTOR), pointer  :: fftDescHandle
    integer                         :: iret

    ! Perform a complex to complex transform
    iret = DftiCreateDescriptor(fftDescHandle, DFTI_SINGLE, &
        DFTI_REAL, 1, nXo )
    iret = DftiSetValue(fftDescHandle, DFTI_PLACEMENT, DFTI_NOT_INPLACE)
    iret = DftiCommitDescriptor(fftDescHandle)
    iret = DftiComputeForward(fftDescHandle, X_in, X_out)
    iret = DftiFreeDescriptor(fftDescHandle)
    ! result is given by {X_out(1),X_out(2),...,X_out(32)}

    return
end subroutine FFTRF[/bash]

Is there an exception in this case?

Regards

Lars
0 Kudos
mecej4
Honored Contributor III
503 Views
If you are prepared to do a little extra work in order to invoke only those module entities that are used, you can spell them out:

[fortran]    USE MKL_DFTI, only :      &
       DFTI_DESCRIPTOR,       &
       DftiCreateDescriptor,  &
       DftiSetValue,          &
       DftiComputeForward,    &
       DftiCommitDescriptor,  &
       DftiFreeDescriptor,    &
       DFTI_REAL,             &
       DFTI_PLACEMENT,        &
       DFTI_NOT_INPLACE       &
       DFTI_SINGLE
[/fortran]
This will exclude all module entities that are not used from fattening up your OBJ and EXE files.
0 Kudos
Lars_Jakobsen
Beginner
503 Views
Hi mecej4,

I already tried that, but it did not give mea size reduction of my exe. In fact you still have to use DFTI_SINGLE => DFTI_SINGLE_R in the only list to geta size reduction.

Regards

Lars
0 Kudos
Dmitry_B_Intel
Employee
503 Views

Is there an exception in this case?


This is probably my misinterpretation of the standard's intericate clauses. Compiler may interpretthe clause differently anyway and not require the 'forget' rename. If you care about portability of the software, you should probably leave the 'forget' rename in place.

Thanks
Dima
0 Kudos
Reply