openmp matlab,matlab – 为什么在mex文件中的OpenMP只产生1个线程?

我是OpenMP的新手.我有以下代码使用配置了MSVS2010的Matlab mex进行编译.计算机有8个处理器(我也使用matlabpool检查过).

#include "mex.h"

#include

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

output[i]=input[index[i]];

}

}

mexPrintf("nThreads = %i\n",nThreads);mexEvalString("drawnow");

}

我得到的输出是

n=600000000

nThreads = 1

尽管我要求8,但为什么只创建了一个线程?

你可能感兴趣的:(openmp,matlab)