question can be sayed like this how to use mingw compiler to compile cpp project with openmp into mex file
openmp mingw mex for matlab error
11 views (last 30 days)
Show older comments
i use Code block and my compiler environment is mingw 6.30.At the beginning, I created the following OpenMP code in the code block
There was no error
#include <iostream>
#include<omp.h>
#include<stdio.h>
#include<mex.h>
using namespace std;
int main()
{
int A = 100;
#pragma omp parallel for lastprivate(A) firstprivate(A)
for(int i = 0; i<10;i++)
{
A=A+i;
}
printf("%d\n",A);
cout<<omp_get_active_level()<<"\n";//this function omp_get_active_level() is compatible in cpp
return 0;
}
code like this,i am sure that mingw6.30 gcc is compatible with openmp function like omp_get_active_level()
next setup,i want to change this code to mexfunction for matlab ,so code changed like this
#include <iostream>
#include<omp.h>
#include<stdio.h>
#include<mex.h>
using namespace std;
int test()
{
int A = 100;
#pragma omp parallel for lastprivate(A) firstprivate(A)
for(int i = 0; i<10;i++)
{
A=A+i;
}
printf("%d\n",A);
cout<<omp_get_active_level()<<"\n";//this function omp_get_active_level() is compatible in cpp
return 0;
}
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
{
test();
}
in matlab2020b,i select my matlab mex compiler mingw6.30 rather than vc++,but when i compile cpp to mex(i input mex -v COMPFLAGS="$COMPFLAGS -openmp" main.cpp),matlab warning like this

this makes me puzzles,because in code block,pure cpp project is compatible to run with omp_get_active_level,while in mex compiler,matlab warning this function undefined,after i delete omp_get_active_level,mex compiler show no error,why?whether matlab mexfunction support omp_get_active_level or not
4 Comments
Answers (0)
See Also
Categories
Find more on MATLAB Support for MinGW-w64 C/C++ Compiler in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!