I'm using Intel Visual Fortran to compile a DLL library. The library itself works fine, but unfortunately the size of the library is very large, over a 100 Megabyte. Note that this is the size when debugging is disabled.
I tried to figure out why our libraries are soo large and came up with the following example:
module ExampleMod implicit none private type :: DataType real, dimension(1000000) :: array real :: scalar = 1 end type DataType contains subroutine DataTypeDoSomething(this) class(DataType), intent(inout) :: this this%array(1) = 0 end subroutine DataTypeDoSomething subroutine DoSomething1(dat) !DEC$ ATTRIBUTES DLLEXPORT :: DoSomething1 type(DataType) :: dat call DataTypeDoSomething(dat) end subroutine DoSomething1 ! subroutine DoSomething2(dat) ! !DEC$ ATTRIBUTES DLLEXPORT :: DoSomething2 ! type(DataType) :: dat ! call DataTypeDoSomething(dat) ! end subroutine DoSomething2 ! ! ! subroutine DoSomething3(dat) ! !DEC$ ATTRIBUTES DLLEXPORT :: DoSomething3 ! type(DataType) :: dat ! call DataTypeDoSomething(dat) ! end subroutine DoSomething3 ! ! ! subroutine DoSomething4(dat) ! !DEC$ ATTRIBUTES DLLEXPORT :: DoSomething1 ! type(DataType) :: dat ! call DataTypeDoSomething(dat) ! end subroutine DoSomething4 end module ExampleMod
The above code compiles into a library of approximately 4 Megabyte. A few interesting remarks:
- The size of the DLL is approximately the same as the size of one instance of Type(DataType).
- If the subroutines DoSomething2, DoSomething3 and DoSomething4 are uncommented then the size of the DLL increases to approx 16 Megabytes. Note that this is approximately 4 times the size of an instance of Type(DataType).
So apparently every time a function is added to the DLL that uses Type(DataType), an additional 4 megabytes are added to the DLL. To me it seems that this is a bug in the compiler or linker.
Has anyone else seen this issue? Will it be solved in a next release of Intel Visual Fortan?
PS1: The problem only occurs when using the object oriented features of Fortran. When class(DataType) is replaced with type(DataType) in the subroutine DataTypeDoSomething, the size of the DLL is only a few kilobytes, even when DoSomething2, DoSomething3 and DoSomething4 are uncommented.
PS2: When the line "real :: scalar = 1" is replaced with "real :: scalar" then the size of the DLL is also only a few kilobytes.