How to pass class method handle to createTask

5 Ansichten (letzte 30 Tage)
sun peng
sun peng am 24 Mär. 2015
Kommentiert: sun peng am 27 Mär. 2015
Hi,
The Matlab parallel computing toolbox function createTask needs a function handle as the input which it executes on a worker machine. But in all the documents and examples I can find the handle is a plain function handle. I'm wondering if it is possible to pass in a class method handle? That is, I first create a class on the worker machine, and later I want its method be called as a task. If it is impossible, is there any working around (e.g., certain Design Pattern, a trick like message queue, etc.)?
Thanks :)
Peng

Akzeptierte Antwort

Edric Ellis
Edric Ellis am 25 Mär. 2015
Bearbeitet: Edric Ellis am 25 Mär. 2015
Remember that MATLAB class methods can always be invoked in the "functional" form, like so:
e = MException('some:identifier', 'This is the message');
report = getReport(e); % same as e.getReport();
Therefore, you can simply specify the method you wish to invoke as the function, and pass the object as the first argument, like so:
j = createJob(parcluster());
t = createTask(j, @getReport, 1, ...
{MException('some:identifier', 'This is the message.')});
submit(j); wait(j);
fetchOutputs(j)
  2 Kommentare
sun peng
sun peng am 26 Mär. 2015
Hi Edric,
Thanks for your reply!
I just realized I didn't make things clear in my initial question. I actually want the class instance be created on the worker machine, holding some states and its method being called many times by the server (i.e., the sponsor of the task, sorry I don't know the exact term here but I guess you know what I mean:) ) where the behavior depends on the states and will change the states.
In your example, the class instance e is destroyed once the task is done, right? Also, I guess the instance e is firstly created on the caller machine and then passed to the worker machine via the network transmission which may be slow? Can we avoid these difficulties?
sun peng
sun peng am 27 Mär. 2015
For the updated question, I just found that "spmd" syntax does exactly what I want.
As for the initial question, Edric's answer is the best solution.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Cluster Configuration finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by