tall array within a parfor?

조회 수: 5 (최근 30일)
Ive J
Ive J 2022년 4월 6일
편집: Ive J 2022년 4월 6일
Consider the following scenario:
ds = datastore(...);
dst = tall(ds);
parfor ...
% warning here: dst is a broadcast variable. This might result in unnecessary communication overhead.
chunk = gather(dst(:, idx));
end
Given the fact that dst is a tall array, why MATLAB warns about overhead? In fact, due to the lazy nature of tall arrays, above parfor is quite memory friendly.
So, what's the reason of the warning in case of tall arrays (pleast note I'm aware of communication overhead issue in case of other data types)?
Thanks!

채택된 답변

Matt J
Matt J 2022년 4월 6일
편집: Matt J 2022년 4월 6일
You've generated idx in a way that doesn't have a simple dependence on the loop variable. This warning is not present if you are simply parfor-looping over the columns.
dst=tall(rand(5,10));
parfor i=1:size(dst,2)
chunk = gather( dst(:, i) );
end
Because of whatever you're doing, the variable is not sliced. Because it is not sliced, you may have overhead due to two or more parpool workers trying to access the same memory at the same time. If you had been writing into the tall array, you would have to be even more careful. Parallel write operations into the same memory location can have unpredictable effects.
  댓글 수: 1
Ive J
Ive J 2022년 4월 6일
편집: Ive J 2022년 4월 6일
I see, makes perfect sense. idx is a cell array of variable names in dst in non-overlapping chunks.
idx = {["var1", "var2"], ["var3", "var4"], ...};
parfor i = 1:numel(idx)
chunk = gather(dst(:, idx{i}));
end
For what it's worth, this has (several benchmarks) a stable memory usage (no change during the course of parfor loop), while in case of non-tall arrays out of memory can happen. so, in the end, I feel this is a safe approach regardless of slicing issue
Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by