public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libgomp/40174]  New: Memory leak when using '#pragma omp parallel'
@ 2009-05-17  7:26 to dot my dot trociny at gmail dot com
  2009-05-19  7:31 ` [Bug libgomp/40174] " jakub at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: to dot my dot trociny at gmail dot com @ 2009-05-17  7:26 UTC (permalink / raw)
  To: gcc-bugs

#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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-05-20 21:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-17  7:26 [Bug libgomp/40174] New: Memory leak when using '#pragma omp parallel' to dot my dot trociny at gmail dot com
2009-05-19  7:31 ` [Bug libgomp/40174] " jakub at gcc dot gnu dot org
2009-05-19 10:06 ` to dot my dot trociny at gmail dot com
2009-05-20 20:55 ` jakub at gcc dot gnu dot org
2009-05-20 20:56 ` jakub at gcc dot gnu dot org
2009-05-20 21:15 ` jakub at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).