When I alternate between 2 OpenMP parallel regions with a different number of threads repeatedly, the memory consumption increases indefinitely (tens of MB or even more). And it does this even in such a simple code snippet:
#include <unistd.h>
int main() {
while (true) {
#pragma omp parallel num_threads(16)
usleep(30);
#pragma omp parallel num_threads(8)
usleep(30);
}
return 0;
}
As I have already discovered in a related question, on my system 8 threads are reused all the time, while remaining 8 are newly created each time 16-thread section is entered. While creating and destroying threads may be an intended OpenMP behavior, constantly increasing memory usage looks like a memory leak. For 2 sections with the same number of threads everything is ok. Does anyone have any ideas what is the reason and what I can do if I insist on using a different number of threads in each section?
I am using Ubuntu 18.04 with GOMP form gcc 8.4.0 on a Ryzen 8-core 16-thread machine (7.5.0 has the same problem).
This question is a stripped down version of a previous question making a minimal working example without unnecessary info.