calllib() and parallelization using OpenMP

3 Ansichten (letzte 30 Tage)
Mariora
Mariora am 3 Aug. 2016
Bearbeitet: Mariora am 4 Aug. 2016
I am calling a function from a dll with calllib() that is using parallel for loops using OpenMP. Specifically the dll is compiled with gcc using OpenMP compiler directives and then called from MATLAB like this
loadlibrary(path_to_dll, path_to_header)
ptr = libpointer('doublePtr', zeros(length, 1));
result = calllib('mylib', 'myfunction', ptr, argument);
MATLAB does not seem to actually create any threads when I call the function via calllib() and the function runs in a single thread.
I am using MATLAB R2012b on Windows 7 and building the dll with gcc 5.4.0 on the same machine.
How can I use multi-threading in the C function when called from MATLAB?
  1 Kommentar
Philip Borghesani
Philip Borghesani am 3 Aug. 2016
Are you building a Windows dll with gcc or are you building an '.so' with gcc on Linux? For this sort of problem it is helpful to know OS, MATLAB, and compiler versions.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Philip Borghesani
Philip Borghesani am 3 Aug. 2016
Bearbeitet: Philip Borghesani am 3 Aug. 2016
I can't tell you why this is not working but can give you someplace to start. Attempting to use OpenMP in a function called by callib will run into all the same issues as attempting to use OpenMP in a mex file. Try searching for OpenMP mex MATLAB and get scared. OpenMP in Mex
To have any chance of getting this working you may need to build your dll with the same compiler version used to build MATLAB.

Kategorien

Mehr zu C Shared Library Integration finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by