Are MATLAB user defined objects supported in PARFOR in Parallel Computing Toolbox 4.1 (R2009a)?
2 views (last 30 days)
Show older comments
When I use my MATLAB user defined objects (class objects) in a PARFOR loop, I receive the following error:
Do not match the current constructor definition for class '<classname>'. The element(s) have been converted to structures.
I would like to know if MATLAB objects are supported for parallel computing when using Parallel Computing Toolbox 4.1 (R2009a).
Accepted Answer
MathWorks Support Team
on 31 Jul 2009
MATLAB class objects are supported in parallel computing. The MATLAB class syntax prior to MATLAB 7.6 (R2008a) are also supported as well.
The specific construct of PARFOR environment requires that the MATLAB class file can be saved and loaded as a MAT file with zero arguments. This only applies to the old MATLAB class syntax.
A class system that takes multiple arguments must have a separate constructor that takes in empty arguments. This is used as a check for the MATLAB workers.
A simple implementation in an Employee class example would be of the following:
function obj = Employee(name, salary, grade)
% Handle the no-argument case
if nargin==0
name = '';
salary = 0;
grade = 0;
end
% Proceed with rest of class definition and code
obj = struct('Name', name, 'Salary', salary, ' 'Grade', grade);
obj = class(obj, 'Employee');
0 Comments
More Answers (0)
See Also
Categories
Find more on Parallel for-Loops (parfor) 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!