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

OpenMP with libs:static cause memory leak

EruditePig
Beginner
1,125 Views

Here is the code:

 


    program main

    implicit none
    integer                         :: i
    
    type Element
        real(8),allocatable         :: eForce(:)                
    end type Element
    
    type (Element),allocatable      :: elems(:)
   
    
    allocate(elems(100))
    
    !$omp parallel do private (i) schedule (guided)
    do i=1,100
        allocate(elems(i)%eForce(1000000))
        elems(i)%eForce=1.
    end do
    !$omp end parallel do
    
    write(*,*) "befor clean..."
    do while (.true.)
        write(*,fmt='(a,\)') "input 1 to continue:"
        read(*,*) i
        if(i.eq.1) exit
    end do    
    
    deallocate(elems)
    
    write(*,*) "clean finished..."
    do while (.true.)
        write(*,fmt='(a,\)') "input 1 to continue:"
        read(*,*) i
        if(i.eq.1) exit
    end do  
    
    end program main
    

 

If I choose "Debug Multithreaded (/libs:static /threads /dbglibs)" in project property, after clean the allocated memory, the memory usage is still near 1GB

EruditePig_0-1624506761075.png

 

EruditePig_1-1624506806727.png

 

However, If I choose "Debug Multithread DLL (/libs:dll /threads /dbglibs)", deallocate will perform right.

EruditePig_2-1624506872552.png

EruditePig_3-1624506911177.png

 

I notice that IVF stop support for static link of OpenMP (https://community.intel.com/t5/Intel-Fortran-Compiler/Intel-Fortran-Static-Library-with-OpenMP-enabled/td-p/1014804)

 

According to the thread, Am i wrong to choose the libs:static option?

 

The Intel Fortran version I used is 19.1.0.166 

 

Labels (1)
0 Kudos
6 Replies
Steve_Lionel
Honored Contributor III
1,072 Views

/libs:static doesn't affect the OpenMP library, which is DLL-only. Have you tried a more recent compiler and runtime library? 

0 Kudos
EruditePig
Beginner
1,055 Views

the attachment is the solution, The Intel Fortran version I used is 19.1.0.166 , the VisualStudio version is 16.9.0
Both are recent updated software

0 Kudos
Steve_Lionel
Honored Contributor III
1,033 Views

I can reproduce the difference using the 2021.0.2 compiler and libraries. What causes it, I don't know., but I do know that there can sometimes be issues mixing DLL and static linked code. If you have paid support I suggest you report this through the Intel Online Service Center. But the most pragmatic approach would be to use DLL linking, which is the default.

0 Kudos
JohnNichols
Valued Contributor III
1,025 Views

Why is the default dll, it makes a lot more sense to bind in the lib.  

0 Kudos
Steve_Lionel
Honored Contributor III
1,001 Views

Linking to DLL libraries saves space, reduces memory load, and allows for DLLs to be updated without requiring a relink. Microsoft changed its defaults many years back to default to DLL linking. In the case of OpenMP, I recall a claim that there were run-time issues caused by use of a static library for OpenMP. I don't recall the details, and note that a static OMP library is still provided on Linux, but that is a different environment.

0 Kudos
JohnNichols
Valued Contributor III
998 Views

but in the days of Microsoft Fortran you created a single file that sat on a floppy and just ran, now it is a convoluted set of dlls.  Bring back MS Fortran V 3.03 and twin floppy drives, the modern youth are spoiled. 

0 Kudos
Reply