#include <omp.h> int n = 4, m = 2;
int main () { for (;;) { int i; #pragma omp parallel for num_threads(m) for(i = 0; i < 1; i++) {} #pragma omp parallel for num_threads(n) for(i = 0; i < 1; i++) {} } return 0; } When run on freebsd, this test shows constant growth of virtual memory usage. Memory growth is observed only when m != n. 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.orig 2009-05-16 22:57:05.000000000 +0300 +++ gcc-4.4-20090227/libgomp/team.c 2009-05-16 22:57:14.000000000 +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); The problem is not observed on 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 on FreeBSD and does not on Linux. #include <semaphore.h> int main(int argc, char *argv[]) { sem_t sem; for(;;) { sem_init(&sem, 0, 0);} return 0; } -- Summary: Memory leak when using '#pragma omp parallel' Product: gcc Version: 4.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libgomp AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: to dot my dot trociny at gmail dot com GCC host triplet: i386-portbld-freebsd7.2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40174