I need to get some MEX functions running with openMP and I have som problems with the compiling.
I use a 2013b version of matlab on OS X 10.9, and run the gcc compiler with the tweeks described in
http://www.mathworks.com/matlabcentral/answers/103904
I know the compiler works on regular C and C++ MEX-functions.
The test code I am trying to compile is the following test:
#include "mex.h"
#include <stdio.h>
#include "omp.h"
void mexFunction(int nlhs,mxArray* plhs[], int nrhs, const mxArray* prhs[])
{
double sum;
/* Check for proper number of arguments. */
if(nrhs!=0) {
mexErrMsgTxt("No input");
} else if(nlhs!=0) {
mexErrMsgTxt("No output");
}
omp_set_num_threads(omp_get_max_threads());
mexPrintf("Max number of threads %d\n",omp_get_max_threads());
#pragma omp parallel for
for (int i=0;i<omp_get_max_threads();i++){
mexPrintf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
}
return;
}
When I try to compile it using the -fopenmp flag, it seems that the compiler ignores it.
Typing:
>> mex openMPtest.c CFLAGS="\$CFLAGS -fopenmp" LDFLAGS="\$LDFLAGS -fopenmp"
Gives:
clang: warning: argument unused during compilation: '-fopenmp'
Why is the -fopenmp flag ignored? I thougth Matlab would use gcc when gcc is the one asked for in Mexopts.sh, why do I get a warning from CLANG?
The program gets compiled btw. without the openMP functionality:
Output:
>> openMPtest
Max number of threads 4
Hello from thread 0, nthreads 1
Hello from thread 0, nthreads 1
Hello from thread 0, nthreads 1
Hello from thread 0, nthreads 1