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 commentaires

俊凯 王
俊凯 王 le 20 Juin 2021
question can be sayed like this how to use mingw compiler to compile cpp project with openmp into mex file
俊凯 王
俊凯 王 le 20 Juin 2021
my project is cpp,is that ok ?let me have a try
俊凯 王
俊凯 王 le 20 Juin 2021
success!thanks

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Centre d'aide et File Exchange

Produits

Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by