Thread Subject: improper openmp paralellization or bug?

Subject: improper openmp paralellization or bug?

From: Sebastiaan

Date: 29 May, 2008 14:03:22

Message: 1 of 2

Dear list,

I am trying to parallellize some code C mex files using
openmp. I am having trouble with allocating memory for the
threads. The code I am using roughly looks like this:

double *T, *A;
int i, Bm=100;

A = mxCalloc(Bm*Bm, sizeof(double));

#pragma omp parallel shared(Bm,A) private(i,j,T)
{
  T = mxCalloc(Bm, sizeof(double));
/*T = calloc(Bm, sizeof(double));*/
  #pragma omp for schedule(dynamic,1) nowait
    for (i=0; i<Bm; i++)
    {
      for (j=0; j<i; j++)
      {
        /* do some math and fill T */
        T[j] = i;
      }

      /* Write cache to matrix A */
      for (j=0; j<i; j++)
        A[i*Bm + j] += T[j];

      /* Clear T */
      bzero(T, sizeof(double)*(i+1));
    }

  mxFree(T);
/*free(T); */
}


This should reserve memory for each tread, and the code
works fine outside Matlab.

It also seems to work fine inside Matlab, when using
mxCalloc and mxFree in R2007b.

In R2008a Matlab occasionally crashes with:
Severe:
memmgr/memcache.cpp:742: Assert : (hdr->in_use != 0),
"Attempt to free previously freed memory"
The program '[17833] : Native' has exited with code 2 (0x2).

However, when I use calloc/free instead of mxCalloc and
mxFree in Matlab 2008a, it works fine.

So, is there a bug in my OMP loop and it is just luck that
it does not crash, or is this a bug in Matlab?

The code is compiled with Intel C compiler 10. I am now
trying to build gcc-4.3.0 to test with gcc.

Thanks in advance,
Sebastiaan

Subject: improper openmp paralellization or bug?

From: Sebastiaan

Date: 30 May, 2008 07:46:01

Message: 2 of 2

> The code is compiled with Intel C compiler 10. I am now
> trying to build gcc-4.3.0 to test with gcc.

Update: the code works fine with gcc-4.3.0 and mxCalloc and
mxFree.

So, what goes wrong with 2008a and icc-10 ?

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
openmp Sebastiaan 29 May, 2008 10:05:21
omp Sebastiaan 29 May, 2008 10:05:21
mex Sebastiaan 29 May, 2008 10:05:21
memory allocation Sebastiaan 29 May, 2008 10:05:21
rssFeed for this Thread

Contact us at files@mathworks.com