Почему OpenMP в mex-файле создает только 1 поток?

Я новичок в OpenMP. У меня есть следующий код, который отлично компилируется с использованием Matlab mex, настроенного с помощью MSVS2010. В компьютере доступно 8 процессоров (которые я также проверил с помощью matlabpool).

#include "mex.h"
#include <omp.h>

typedef unsigned char uchar;
typedef unsigned int uint;
//Takes a uint8 input array and uint32 index array and preallocated uint8 array the same
//size as the first one and copies the data over using the indexed mapping
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[] ) 
{
    uint N = mxGetN(prhs[0]);
    mexPrintf("n=%i\n", N); mexEvalString("drawnow");
    uchar *input = (uchar*)mxGetData(prhs[0]);
    uint *index = (uint*)mxGetData(prhs[1]);
    uchar *output = (uchar*)mxGetData(prhs[2]);

    uint nThreads, tid;
#pragma omp parallel private(tid) shared(input, index, output, N, nThreads) num_threads(8) 
    {
        tid = omp_get_thread_num();

        if (tid==0) {
            nThreads = omp_get_num_threads();

        }

        for (int i=tid*N/nThreads;i<tid*N/nThreads+N/nThreads;i++){
            output[i]=input[index[i]];
        }
    }
    mexPrintf("nThreads = %i\n",nThreads);mexEvalString("drawnow");
}

В результате я получаю

n=600000000
nThreads = 1

Почему создается только один поток, несмотря на то, что я запрашиваю 8?

8
задан twerdster 7 November 2011 в 17:27
поделиться