필터 지우기
필터 지우기

Using DLL functions with parfeval

조회 수: 7 (최근 30일)
Alexander Braun
Alexander Braun 2015년 2월 3일
댓글: Titus Edelhofer 2018년 9월 17일
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일
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
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
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
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
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 CenterFile Exchange에서 Asynchronous Parallel Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by