Hello,
I have a memory leak problem with nested OpenMP parallel regions when both regions run with multiple threads. At the same time, when only one region have multiple threads and other one is 1-threaded, there is no memory leak.
There is C# program that calls Fortran dll multiple times. In Fortran dll I have nested parallel regions like that:
subroutine Sub1()
*some work*
!$ call OMP_SET_NESTED(.TRUE.)
!$OMP parallel do num_threads(n1) shared(...) private(...)
do i=1,2
*allocation of private dynamic arrays*
*some work*
call Sub2(args)
*some work*
*deallocation of private arrays*
end do
!$OMP end parallel do
end subroutine
subroutine Sub2(args)
*allocation dynamic arrays*
*some work*
!$OMP parallel do num_threads(n2) shared(...) private(...)
do i=1,2
*allocation of private dynamic arrays*
*some work*
*deallocation of private dynamic arrays*
end do
!$OMP end parallel do
*deallocation of dynamic arrays*
end subroutine
So I have 2 loops each has 2 iterations. When I run the code with n1=2, n2=1, or n1=1, n2=2 (number of threads in Sub1 and Sub2), everything is fine, but when I run it with n1=2, n2=2 then I have memory leak and program crashes after some time when memory usage reaches 2 Gb (I build it as 32-bit app).
VMMAP tool shows that most memory as taken by "Private data", where I can see a lot of memory blocks with size 1024 Kb and total WS 1000 Kb, the amount of such blocks is increasing with time. Because of such even size (exactly 1 Mb) I suspect that these are some system blocks, maybe stacks of OpenMP threads?
I tried it both on 15.0 and 16.0 (beta) compilers, the behavior is the same.