Are MATLAB user defined objects supported in PARFOR in Parallel Computing Toolbox 4.1 (R2009a)?
3 次查看(过去 30 天)
显示 更早的评论
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).
采纳的回答
MathWorks Support Team
2009-7-31
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!