openmp in mex : stackoverflow error

Posted by Edwin on Stack Overflow See other posts from Stack Overflow or by Edwin
Published on 2010-05-02T08:59:45Z Indexed on 2010/05/02 9:07 UTC
Read the original article Hit count: 447

Filed under:
|
|
|

i have got the following fraction of code that getting me the stack overflow error


#pragma omp parallel shared(Mo1, Mo2, sum_normalized_p_gn, Data, Mean_Out,Covar_Out,Prior_Out, det) private(i)  num_threads( number_threads )  
{  

        //every thread has a new copy  
        double* normalized_p_gn = (double*)malloc(NMIX*sizeof(double));   
        #pragma omp critical  
        {
            int id =  omp_get_thread_num();
            int threads = omp_get_num_threads();
            mexEvalString("drawnow");  
        }  

        #pragma omp for
        //some parallel process.....

}  

the variables declared in the shared are created by malloc. and they consumes with large amount of memory

there are 2 questions regarding to the above code. 1) why this would generate the stack overflow error( i.e. segmentation fault) before it goes into the parallel for loop? it works fine when it runs in the sequential mode.... 2) am i right to dynamic allocate memory for each thread like "normalized_p_gn" above?

Regards Edwin

© Stack Overflow or respective owner

Related posts about openmp

Related posts about c++