How to pass class method handle to createTask
5 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Edric Ellis
on 25 Mar 2015
Edited: Edric Ellis
on 25 Mar 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)
More Answers (0)
See Also
Categories
Find more on Cluster Configuration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!