Memory leak or incorrect use of '#pragma omp parallel'?
Hello, If I run the following program --- #include int n = 4, m = 2; int main () { for (;;) { int i; #pragma omp parallel num_threads(m) { int just_to_make_some_code_generated; just_to_make_some_code_generated = 0; } #pragma omp parallel for num_threads(n) for(i = 0; i < 1; i++) {} } return 0; } --- on FreeBSD6/7 (i386 and amd64) built with gcc42 or gcc43 -fopenmp (I have not tried other gcc versions), the memory usage is constantly growing during the run. The memory growth is observed in case n != m. If n == m, everything works ok. I have tried this code on CentOS5.2 i386 built with gcc41 and gcc43 and constant memory growth is not observed here. Althogh memory usage looks a bit strange. On the start the program uses much more memory (more then 60Mb) in comparison with FreeBSD (several Mb). If n == m, the memory usage statistis is not changing during the run, while when n != m the memory usage statistis varies from 64Mb to 102Mb. Should I report this as a bug? I am not familiar with openmp, we faced with this problem running some real application. So I am not sure if this is gcc bug or just incorrect use of '#pragma omp parallel'. -- Mikolaj Golub
Re: Memory leak or incorrect use of '#pragma omp parallel'?
On Mon, 11 May 2009 19:00:54 +0300 Mikolaj Golub wrote: > Hello, > > If I run the following program > > --- > > #include > > int n = 4, m = 2; > > int main () { > for (;;) { > int i; > > #pragma omp parallel num_threads(m) > { > int just_to_make_some_code_generated; > just_to_make_some_code_generated = 0; > } > #pragma omp parallel for num_threads(n) > for(i = 0; i < 1; i++) {} > > } > > return 0; > } > > --- > > on FreeBSD6/7 (i386 and amd64) built with gcc42 or gcc43 -fopenmp (I have not > tried other gcc versions), the memory usage is constantly growing during the > run. The memory growth is observed in case n != m. If n == m, everything works > ok. The problem is observed also for constructions like this one: #pragma omp parallel for num_threads(m) ... #pragma omp parallel for num_threads(n) ... Adding some sleep() code I see in top that during the program run m or n threads are run in turn. So it looks like memory leaks when thread is removed. It might be FreeBSD problem, not gcc. -- Mikolaj Golub
Re: Memory leak or incorrect use of '#pragma omp parallel'?
On Tue, 12 May 2009 09:33:34 +0300 Mikolaj Golub wrote: MG> On Mon, 11 May 2009 19:00:54 +0300 Mikolaj Golub wrote: >> Hello, >> >> If I run the following program >> >> --- >> >> #include >> >> int n = 4, m = 2; >> >> int main () { >> for (;;) { >> int i; >> >> #pragma omp parallel num_threads(m) >> { >> int just_to_make_some_code_generated; >> just_to_make_some_code_generated = 0; >> } >> #pragma omp parallel for num_threads(n) >> for(i = 0; i < 1; i++) {} >> >> } >> >> return 0; >> } >> >> --- >> >> on FreeBSD6/7 (i386 and amd64) built with gcc42 or gcc43 -fopenmp (I have >> not >> tried other gcc versions), the memory usage is constantly growing during the >> run. The memory growth is observed in case n != m. If n == m, everything >> works >> ok. MG> The problem is observed also for constructions like this one: MG> #pragma omp parallel for num_threads(m) MG> ... MG> #pragma omp parallel for num_threads(n) MG> ... MG> Adding some sleep() code I see in top that during the program run m or n MG> threads are run in turn. So it looks like memory leaks when thread is MG> removed. It might be FreeBSD problem, not gcc. The problem is in libgomp/team.c. gomp_thread_start() does gomp_sem_init() but gomp_sem_destroy() is never called. FreeBSD implementation of sem_init() allocates some memory for semaphore. This patch solves the problem for me: --- gcc-4.4-20090227/libgomp/team.c.orig2009-05-16 22:57:05.0 +0300 +++ gcc-4.4-20090227/libgomp/team.c 2009-05-16 22:57:14.0 +0300 @@ -458,6 +458,7 @@ gomp_team_start (void (*fn) (void *), vo void gomp_team_end (void) { + int i; struct gomp_thread *thr = gomp_thread (); struct gomp_team *team = thr->ts.team; @@ -493,6 +494,9 @@ gomp_team_end (void) } while (ws != NULL); } + + for(i = 1; i < team->nthreads; i++) +gomp_sem_destroy (team->ordered_release[i]); gomp_sem_destroy (&team->master_release); #ifndef HAVE_SYNC_BUILTINS gomp_mutex_destroy (&team->work_share_list_free_lock); I am going to register this in bugzilla. The problem is not observed under Linux, because it looks like sem_init() implementation for Linux does not do memory allocation in the process' virtual space. The memory for the test program below grows under FreeBSD and does not under Linux. #include int main(int argc, char *argv[]) { sem_t sem; for(;;) { sem_init(&sem, 0, 0);} return 0; } -- Mikolaj Golub
Re: Memory leak or incorrect use of '#pragma omp parallel'?
On Sun, 17 May 2009 09:34:22 +0300 Mikolaj Golub wrote: MG> The problem is in libgomp/team.c. gomp_thread_start() does gomp_sem_init() MG> but gomp_sem_destroy() is never called. Registered in bugzilla http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40174 -- Mikolaj Golub