Clear Filters
Clear Filters

Using DLL functions with parfeval

5 views (last 30 days)
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

Accepted Answer

Titus Edelhofer
Titus Edelhofer on 3 Feb 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 Comments
Titus Edelhofer
Titus Edelhofer on 13 Sep 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
Philipp Stockhammer
Philipp Stockhammer on 15 Sep 2018
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

Sign in to comment.

More Answers (1)

Ronron
Ronron on 15 Feb 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 Comment
Titus Edelhofer
Titus Edelhofer on 17 Sep 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

Sign in to comment.

Categories

Find more on Asynchronous Parallel Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!