Mex files and parallel processing

23 vues (au cours des 30 derniers jours)
Maria
Maria le 26 Août 2021
Modifié(e) : Walter Roberson le 26 Août 2021
Hi,
I have a function that uses parfor and I could successfully run it on my local cluster. When running, I could see that the local cluster was starting and was active.
From this file, I created a mex file. The mex file is created on my local machine (Win) and then I run it by using the local cluster (so, always Win). However, when the mex is running, the local cluster does not start. When I first start it, it goes in idle mode while the mex is running. So I assume that the mex file does not run in parallel.
The mex file is compiled for C language, and the default compiler is MinGW64. Shouldn't this be fine for parallel computation of mex files?
>> mex -setup
MEX configured to use 'MinGW64 Compiler (C)' for C language compilation.
  2 commentaires
Raymond Norris
Raymond Norris le 26 Août 2021
Sorry, I'm not quite following the flow here. I understand that you have a function that starts a parallel pool with the local profile. From there, you're probably running parfor.
Are you then trying to compile this function as a MEX-file, but don't see the local pool starting? Not seeing a speed up of your code? Maybe a little more description/sample code.
Maria
Maria le 26 Août 2021
Modifié(e) : Maria le 26 Août 2021
Sorry, I try to explain it better.
Yes, the original .m function is using parfor loops, so it starts automatically a parallel pool with the local profile.
I compiled it as a MEX-file and run it, but the local pool does not start. If I start the local pool manually, and then run the mex, the local pool goes into idle mode. The run takes 10/15 minutes, so I should be able to see the pool working.
I would like to see how much speed-up I get if I run the mex file with the parallelization, but it looks like the parfor loops are automatically converted into for loops by the compiler. Do I need to actively tell the compiler to use the parfor loops? Or is the MinGW64 compiler not supporting parallelization?

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 26 Août 2021
Modifié(e) : Walter Roberson le 26 Août 2021
Historically, MINGW did not support OpenMP, which is what parfor compiles into if you ask to generate code for parfor.
If I recall correctly, you need one of the Microsoft compilers -- but if I recall correctly, any of the Community or Express editions since 2011 should work (but not SDK 7.1), provided that the edition is supported by your MATLAB release.
  2 commentaires
Maria
Maria le 26 Août 2021
In the table of the supported compilers https://se.mathworks.com/support/requirements/supported-compilers.html , it is written that MinGW 6.3 C/C++ supports "Matlab Coder --> all features". But maybe it is misleading.
Walter Roberson
Walter Roberson le 26 Août 2021
Modifié(e) : Walter Roberson le 26 Août 2021
... which shows about installing OpenMP with MinGW.
However, it does not deal with the incompatibilities issues you rightly pointed to.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by