Borrar filtros
Borrar filtros

Matlab crashes using mex-Function and openMP

1 visualización (últimos 30 días)
Pierre Guilbert
Pierre Guilbert el 9 de Jun. de 2016
Comentada: Matthew Hopcroft el 7 de Abr. de 2020
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
  3 comentarios
Sushant Mahajan
Sushant Mahajan el 4 de Mayo de 2019
Did you find a solution? I am having the same issue with a MEX code in FORTRAN. It crashes if I compile with -fopenmp flag, but runs smoothly without -fopenmp
mex feature_on_sun_fortran.F90 FFLAGS="$FFLAGS -O3" LDFLAGS="$LDFLAGS -O3"
The code does not even have a OMP_PARALLEL construct, it only has
include 'omp_lib.h'
Matthew Hopcroft
Matthew Hopcroft el 7 de Abr. de 2020
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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by