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

 채택된 답변

Titus Edelhofer
Titus Edelhofer 2015년 2월 3일

1 개 추천

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

Alexander Braun
Alexander Braun 2015년 2월 3일
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 2018년 9월 11일
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 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
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
Ronron 2017년 2월 15일

0 개 추천

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
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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by