Using DLL functions with parfeval

Hello Everybody,
I have a script which does basically the following:
loadlibrary('myDLL','myHEADER')
p=parpool(2)
f=parfeval(p,@myFunction,numout,inputs...)
However, the DLL 'myDLL' is not known if I use calllib in myFunction. When I am using myFunction without parfeval, everything is fine. So I assume that I need to declare myDLL as input in parfeval or make it somehow global.
Using calllib in myFunction is not an option since it is too time consuming. I also do not use any unloadlibrary before using parfeval.
Thanks in advance
Alexander

 Respuesta aceptada

Titus Edelhofer
Titus Edelhofer el 3 de Feb. de 2015
Hi Alexander, using loadlibrary will load the dll only to the client MATLAB, not to the pool workers. You will need to do this as well. Please try
p = parpool(2);
% execute loadlibrary on all workers:
spmd
loadlibrary('myDLL', 'myHEADER');
end
f = parfeval(...);
Titus

5 comentarios

Alexander Braun
Alexander Braun el 3 de Feb. de 2015
Seems to work. Thanks a lot!
Hi Titus, hi Alexander, I tried the same as you wrote above, but I get an error message which says:
Error detected on workers 2 4.
Caused by:
Error using coder.loadlibrary (line 24)
Header file, %s, must not already exist in the current folder
When I tried it without the parallel pool I didn't get the error message. The code looks like this:
if parforSwitch
gcp;
spmd
coder.loadlibrary(DLLFileName,HeaderFileRelDir);
end
else
coder.loadlibrary(DLLFileName,HeaderFileRelDir);
end
Whereas DLLFileName is the name of the dll-file and HeaderFileRelDir is the location of the headerfile (like: DLLFileName_win64\DLLFileName.h)
Thanks in advance, Philipp
Alexander Braun
Alexander Braun el 11 de Sept. de 2018
Hi Philipp,
I haven’t checked your code, yet. However, when I implemented the solution suggest by Titus, I encountered lots of “overhead” in the parallel loops. This means it toke some time for the loops to check if the other parallel loop has finished. I ended up without using parfor, since this gave me better performance on my problem.
Cheers,
Alex
Titus Edelhofer
Titus Edelhofer el 13 de Sept. de 2018
Hi Philipp,
did you have a look it the error message is correct? Is there a DLLFileName.h created in the current folder? If this is the case (I'm not sure about coder.loadlibrary in contrast to loadlibrary), then you would need to create subfolders so that worker2 doesn't see the file worker1 created ...
Titus
Hi Titus,
thx for your answer. I managed to solve the problem and it was exactly what you wrote.
coder.loadlibrary creates a new header file where it
(1) #include <tmwtypes.h>
(2) #define RTWTYPES_H
and finally adds
(3) #include "originalHeader"
the original headerfile and stores it in the current folder. And if every worker tries to do that,...
For now, I simply inserted (1) and (2) manually into the original header file at the beginning. Now I can use the "normal" loadlibrary function.
Philipp

Iniciar sesión para comentar.

Más respuestas (1)

Ronron
Ronron el 15 de Feb. de 2017
Hello, I would like to use classes from a NET assemby in parfeval. But I get the error
"Warning: Cannot load an object of class 'MAPort': No matching constructor signature found."
I tried the following.
p = parpool(2);
% execute loadlibrary on all workers:
spmd
try
NET.addAssembly('dSPACE.HILAPI.MAPort');
NET.addAssembly('dSPACE.HILAPI.Common');
NET.addAssembly('ASAM.HILAPI.Implementation');
NET.addAssembly('ASAM.HILAPI.Interfaces');
import ASAM.HILAPI.dSPACE.MAPort.*;
import ASAM.HILAPI.Implementation.Common.ValueContainer.*;
catch e
error(e.message)
end
end
F = parfeval(@batchTest,0, myview);
The object myview consits of an object of the type MAPort, so that the object can't be loaded. How can I solve the problem? I would appreciate any help!
Thanks, Ronja

1 comentario

Titus Edelhofer
Titus Edelhofer el 17 de Sept. de 2018
Hi Ronja,
I understand the NET.addAssembly works on your MATLAB Client? In this case it's probably a path problem, i.e., your "normal" MATLAB has the .NET dll located on the path, your workers don't ...
Titus

Iniciar sesión para comentar.

Categorías

Preguntada:

el 3 de Feb. de 2015

Comentada:

el 17 de Sept. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by