Codistributed array as class property
이전 댓글 표시
Hi all,
I have a large array (a database let's say, which stays fixed), which I load into a codistributed array directly to avoid communication overhead. I do this as follows:
spmd
% Allocate memory in codistributed array
database = codistributed.zeros(some_size);
% Get the local part on the worker
lp = getLocalPart(database);
% Load the data from files into the local part
lp = loadDataFromFiles();
% Put the local part back
database = codistributed.build(lp,getCodistributor(database));
end
I do this to allow several workers to process parts of the database simultaneously. This works fine, as long as I perform this in the 'main' script of the program, and the database variable is available in the workspace. However, when I want to put all functionality into a class, things stopped working. Let's say I have something as follows:
classdef database
properties
data
end
methods
function obj = database()
% Load the data
spmd
% Allocate memory in codistributed array
database = codistributed.zeros(100);
end
obj.data = database;
end
function queryData(obj)
spmd
% Perform some operations on the database, which is stored
% as a distributed array in obj.data.
size(getLocalPart(obj.data))
end
end
end
end
Matlab let's me create an object of the class, and the property data is initialised. When checking the properties of the class object, it says that obj.data is a distributed array, as I would expect.
However, when I try to execute the queryData method, I get the following error:
Error using distributed/getLocalPart (line 195)
It is not possible to call "getLocalPart" directly on a distributed array. To call
"getLocalPart", you must enter an SPMD block and operate on the corresponding codistributed
array.
I can't seem to find any related topics. So my question obviously is: what am I doing wrong? And is it even possible to 'hide' a distributed array in a class property?
Thanks!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Distributed Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!