Hi all, I run a for loop where the iterations are independent and it's works well. To speed up my simulation, I'm trying to use a parfor loop. But I'm having some trouble with the invoke function I use to call another software to make some calculation. I get the following error :
An UndefinedFunction error was thrown on the workers for 'invoke'. This might be because the
file containing 'invoke' is not accessible on the workers. Use addAttachedFiles(pool, files)
to specify the required files to be attached. See the documentation for
'parallel.Pool/addAttachedFiles' for more details.
I understand that the file containing invoke could not be found but I could not find in the documentation the location of this file. Has someone already obtained this error and fix it ?

2 件のコメント

Edric Ellis
Edric Ellis 2016 年 12 月 6 日
編集済み: Edric Ellis 2016 年 12 月 6 日
A few questions. What cluster type are you using? (Normally, if you are using the 'local' cluster type, then the workers can see the same code on the path as your desktop MATLAB). Is your invoke a function or a method? What happens if you try
addAttachedFiles(gcp(), {'invoke'})
?
Guillaume Worms
Guillaume Worms 2016 年 12 月 6 日
Thank you for your answer Edric, invoke is a matlab method on COM object : here is the concerning page and i'm using the local cluster.
After some research I found that the handle of the COM object I use is lost when the parfor loop starts. How could I give this handle to the parfor loop, I cannot find in the documentation how to do that ?

サインインしてコメントする。

 採用された回答

Edric Ellis
Edric Ellis 2016 年 12 月 7 日

0 投票

The problem appears to be with passing COM objects to the workers. You need to build the COM object on the workers. One way (if you've got R2015b or later) is to use parallel.pool.Constant, like so:
% Set up a COM object on each worker, and specify that "delete"
% should be called when "comConstant" is cleared.
comConstant = parallel.pool.Constant(@() actxserver(...), @delete);
parfor idx = 1:N
comValue = comConstant.Value;
% ... use comValue ...
end
If you've got a release of MATLAB prior to R2015b, you can use Worker Object Wrapper in place of parallel.pool.Constant.

3 件のコメント

Guillaume Worms
Guillaume Worms 2016 年 12 月 7 日
Thank you for your answer, it's very helpfull. But I have one more question : in your example, the COM object is created only for the parfor loop and deleted after. If I want to use an existing COM object that I want to keep after, can I write this like that :
Object=actxserver(...)
%...some calculation...
%comConstant=parallel.pool.Constant(Object);
parfor idx1:N
comValue = comConstant.Value;
%...use comValue...
end
Edric Ellis
Edric Ellis 2016 年 12 月 13 日
No, you need to create the COM object in the process where you're going to use it (I think).
Seyedfarid Ghahari
Seyedfarid Ghahari 2017 年 3 月 10 日
I have a problem very related to this issue. I would like to create not only COM object outside of the parfor but also to start application (Myapplication.ApplicationStart) outside the parfor and use the already started application inside parfor. I really appreciate if you could guide me.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeUse COM Objects in MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by