Error when using openmp 'collapse' directive in matlab mex

1 回表示 (過去 30 日間)
Ajay Iyer
Ajay Iyer 2015 年 3 月 17 日
コメント済み: Ajay Iyer 2015 年 3 月 19 日
Hi,
I am trying to optimize the code for matrix multiplication in a mex file with openmp. The code is given below.
void MatrixMultiply(double *in1,double *in2,double *out,int M, int N, int P)
{
/* Description: multiplies a MxN matrix with a NxP matrix */
int i,j,k;
omp_set_num_threads(2);
#pragma omp parallel for schedule(static) shared(in1,in2,out,M,N,P) private(i,j,k)
for (i= 0; i < M; i++) {
for (j = 0; j < P; j++) {
out[M*j + i] = 0;
for (k = 0; k < N; k++) {
out[M*j + i] += in1[k*M + i]*in2[j*N + k];
}
}
}
return;
}
However, when I change the directive to "#pragma omp parallel for collapse(3) schedule(static) shared(in1,in2,out,M,N,P) private(i,j,k) " I get an error - "error C3005: 'collapse' : unexpected token encountered on OpenMP 'parallel for' directive"
Any help in resolving this error would be appreciated.
Thanks!

採用された回答

James Tursa
James Tursa 2015 年 3 月 18 日
Does your compiler support the collapse directive? What compiler are you using?
  3 件のコメント
James Tursa
James Tursa 2015 年 3 月 19 日
I think MSVC 2010 only supports OpenMP 2.0, and the collapse directive was introduced in OpenMP 3.0.
Ajay Iyer
Ajay Iyer 2015 年 3 月 19 日
Switching to gcc instead of MSVC fixed the problem. Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWrite C Functions Callable from MATLAB (MEX Files) についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by