freezing on mac OS

General OpenMP discussion

freezing on mac OS

Postby valladolid » Mon Nov 28, 2011 5:30 pm

Hi,

I am having a problem with some OpenMP code unexpectedly freezing, here is the shortest example I could find that causes the problem (it's very difficult to pinpoint exactly which lines are necessary because the freeze is very intermittent):

Code: Select all
#include <omp.h>
#include <stdlib.h>
#include <stdio.h>

void func()
{
  long* x = malloc(100 * sizeof(long));
  for (int i = 0; i < 100; i++)
    x[i] = i;
  long* y = malloc(100 * sizeof(long));
  for (int i = 0; i < 100; i++)
    y[i] = i;

#pragma omp parallel num_threads(2)
  {
#pragma omp for
    for (int j = 0; j < 10; j++)
      {
      }
  }

  free(y);
  free(x);
}

int main()
{
  for (int trial = 0; ; trial++)
    {
      if (trial % 10000 == 0)
   printf("done %d\n", trial);
      func();
    }
}



I am compiling with

gcc -o bug -fopenmp -std=c99 bug.c

When I run this on my system (Mac OS 10.6.8, intel core 2 duo, apple GCC 4.2.1), most of the time it runs for a while (perhaps a million iterations, maybe 15-30 seconds), and then freezes. A debugging session with gdb suggests that it is getting stuck on waiting for some synchronisation object at the #pragma omp parallel directive, i.e. it never gets to the #pragma omp for, but I'm not 100% sure of this, because when I insert printf's in various places the behaviour sometimes goes away. The freeze happens more reliably when the system is under moderate to high CPU load (e.g. constantly tabbing through windows or refreshing a web browser). Using top, I see that under normal conditions it consumes about 125% CPU, but after the freeze it drops to about 80% (even when nothing else is running).

I am an OpenMP newbie, so I would like to know whether my code is correct, or have I made a programming error. Other possibilities include compiler or OS bugs. I cannot reproduce this behaviour on a few other systems. It is very suspicious that it happens more often when the system is under high load.

Thanks for your help

david
valladolid
 
Posts: 1
Joined: Mon Nov 28, 2011 5:10 pm

Re: freezing on mac OS

Postby ftinetti » Tue Nov 29, 2011 3:37 am

Hi,

I do not see any thing in the code that could be an error, but it doesn't mean there is not any, of course. Try setting the OMP_WAIT_POLICY environment variable to passive, I'm guessing there is something related to thread synchronization... but it should be at the end of the omp parallel (or end of omp for)... not at the beginning... I'm just guessing.

HTH.
ftinetti
 
Posts: 571
Joined: Wed Feb 10, 2010 2:44 pm

Re: freezing on mac OS

Postby edgar » Tue Nov 29, 2011 11:07 am

Have you tried "#pragma omp parallel for" instead? the behavior should be identical but you never know, in Linux I didn't find any major difference in the assembly code.

I got the idea that by default OMP_WAIT_POLICY is set to passive, so I suggest you to try both.

Later on I will try to reproduce the error on your code on my mac, we should have the same software versions. Up to now I wasn't able to reproduce the error on any of my linux systems.
edgar
 
Posts: 3
Joined: Tue Nov 29, 2011 10:31 am

Re: freezing on mac OS

Postby edgar » Wed Nov 30, 2011 1:25 am

same thing in my system, same setting.

With OMP_WAIT_POLICY=passive just takes a little longer than with active.
edgar
 
Posts: 3
Joined: Tue Nov 29, 2011 10:31 am

Re: freezing on mac OS

Postby ftinetti » Wed Nov 30, 2011 3:24 am

same thing in my system, same setting.

With OMP_WAIT_POLICY=passive just takes a little longer than with active.

What is the last version of gcc available for Mac? And what is the version you are using?
ftinetti
 
Posts: 571
Joined: Wed Feb 10, 2010 2:44 pm

Re: freezing on mac OS

Postby edgar » Wed Nov 30, 2011 8:25 am

by same setting I meant:

Mac OS 10.6.8, intel core 2 duo, apple GCC 4.2.1

For 10.6.8 this is last version provided by apple
For 10.7 I googled but wasn't able to find if gcc gets updated.
edgar
 
Posts: 3
Joined: Tue Nov 29, 2011 10:31 am

Re: freezing on mac OS

Postby dmdqlett » Wed Dec 28, 2011 6:56 am

now it is mac lion .buy photoshop any one test it in this new systemcheap photoshop
dmdqlett
 
Posts: 1
Joined: Wed Dec 28, 2011 2:46 am

Re: freezing on mac OS

Postby timedfor » Tue May 22, 2012 1:34 am

i do think that the new 10.7.1 will provide or just simply improve the system acknowledgement of the gcc so it wont freezes.
timedfor
 
Posts: 1
Joined: Fri May 18, 2012 5:24 am


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 4 guests

cron