I have the following simple C code which is compiled in MATLAB using
mex -v COMPFLAGS="$COMPFLAGS -fopenmp" LDFLAGS="$LDFLAGS -fopenmp" MEXTESTER.c
. I am using MATLAB R2019a, running on Windows 10 Home 64-bit with 6 cores available. Mex is configured to use MinGW64 Compiler.
#include "mex.h"
#include <stdio.h>
#include <omp.h>
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
printf("max threads = %d\n",omp_get_max_threads());
#pragma omp parallel
{
printf("ID = %d\n",omp_get_thread_num());
printf("nThreads = %d\n",omp_get_num_threads());
}
printf("End\n");
return;
}
However when running this code i get the following output
max threads = 6
ID = 0
nThreads = 1
End
How come only 1 thread is ran? If i move the code from Mex and just compile it as a normal C file, this produces the expected output(so ID=0-5 and nThreads = 6)
I have read Why is OpenMP in a mex file only producing 1 thread? , however the answer was to ensure OpenMP support when compiling which i feel like i have already done.
Anyone who can help?