Matlab crashes using mex-Function and openMP

조회 수: 4 (최근 30일)
Pierre Guilbert
Pierre Guilbert 2016년 6월 9일
댓글: Junda 2024년 10월 8일
I have a problem using matlab mexfunction and openMP instructions. I found some related topics but none of them were able to help me.
I want to use openMP with a mex-Function to create a .mexw64 file. But when i use my matlab function, matlab crashes in a brutal way.
Theses are my codes:
C++ code
#include "mex.h"
#include <iostream>
#include <omp.h>
void mexFunction(int nlhs,
mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
{
#pragma omp parallel default(shared)
{
}
mexPrintf("Hi !\n", N);
}
Matlab code:
clear all, close all, clc;
testopenMP();
clear mex;
When i call my function testopenMP matlab crashes. But if I comment the "#pragma omp parallel" instruction, everything work fine:
#include "mex.h"
#include <iostream>
#include <omp.h>
void mexFunction(int nlhs,
mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
{
//#pragma omp parallel default(shared)
{
}
mexPrintf("Hi !\n", N);
}
Another important point, with the pragma omp parallel intruction, sometimes the program works, and sometimes it crashes...
Do you have any ideas of what crashes matlab ? Any help is welcolme
  댓글 수: 4
Matthew Hopcroft
Matthew Hopcroft 2020년 4월 7일
I just discovered that having a mexPrintf statement inside a OMP PARALLEL construct causes the program to crash. Move the print statement outside the parallel construct and it runs fine.
Junda
Junda 2024년 10월 8일
I met the same issue. Seems like MEX does not support mexPrintf inside OpenMP parallel region. Litterally can't find a way to output any information inside parallel region.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Write 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