フィルターのクリア

Sliced variables in parfor loop (restricted indexing)

5 ビュー (過去 30 日間)
Andrew Sykes
Andrew Sykes 2014 年 3 月 31 日
コメント済み: Nikita Balyschew 2018 年 3 月 15 日
Hi,
I am having trouble with some parallel for-loop coding. I believe my essential difficulties can be captured in the following example code.
The function "do_something(x)" takes an array as input and returns an array of equal size ("rand(size(pSlice))" would suffice for example), but this should be irrelevant. Matlab doesn't like the way I am indexing "p". After reading "documentation-center/classification-of-variables/sliced-variables", I understand (in principle) why Matlab doesnt accept "p" (incorrect form of indexing ), but what are my options to resolve this problem?
CellOccupations=round(rand(50,1)*20);
p=rand([sum(CellOccupations) 3]);
csO=cumsum(CellOccupations);
parfor iter=1:50
StartingPointIndex=csO(iter)-CellOccupations(iter)+1;
EndPointIndex=csO(iter);
pSlice=p(StartingPointIndex:EndPointIndex,:);
pSlice=do_something(pSlice);
p(StartingPointIndex:EndPointIndex,:)=pSlice;
end
I'll be happy to provide additional details and description of the problem if someone thinks they can help.
Thanks very much in advance for any help and effort!

採用された回答

Edric Ellis
Edric Ellis 2014 年 4 月 1 日
Although you are dividing up 'p' so that each loop iteration works on a different piece, unfortunately you aren't doing it in the simple manner required for a PARFOR sliced variable. I think in this case because each iteration works on a differently sized 'slice' of 'p', you need to divide up 'p' to be a cell array. Something like this might work:
CellOccupations = round(rand(50, 1) * 20);
p = rand([sum(CellOccupations), 3]);
pSliced = mat2cell(p, CellOccupations);
parfor idx = 1:numel(pSliced)
pSlice = pSliced{idx};
pSlice = do_something(pSlice);
pSliced{idx} = pSlice;
end
p = cell2mat(pSliced)
  4 件のコメント
Ryan Livingston
Ryan Livingston 2014 年 4 月 8 日
編集済み: Ryan Livingston 2014 年 4 月 8 日
Hi Andrew,
Could you please make a new question for the codegen issue and add the product MATLAB Coder to it? Cell arrays are not supported for code generation so that may be the source of some errors.
Nikita Balyschew
Nikita Balyschew 2018 年 3 月 15 日
Hi Andrew or Ryan,
is it possible to link to this with cell arrays occuring problem and opened question to get further information?
Thanks in advance, Nikita

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by