Using DLL functions with parfeval
7 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Titus Edelhofer
2015-2-3
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 个评论
Titus Edelhofer
2018-9-13
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
2018-9-15
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
更多回答(1 个)
Ronron
2017-2-15
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 个评论
Titus Edelhofer
2018-9-17
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Asynchronous Parallel Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!