Unexpected differences between parfor and spmd

조회 수: 13 (최근 30일)
Garry Hollier
Garry Hollier 2016년 11월 15일
댓글: Edric Ellis 2016년 11월 21일
When I replace
parpool(n, 'AttachedFiles', ...)
parfor k = 1:n
res(k) = func(A(k));
end
which works, by
parpool(n, 'AttachedFiles', ...)
spmd
res = func(A(labindex));
end
my machine's physical memory fills up and then my machine freezes, before I get any output.
(There's about 20kB of code behind func, and I have no idea which bit is causing the problem, which is why I'm putting this query in very general terms).
My query is: what sort of thing can cause this?
(The reason why I want to make the change is that I want my progress indicating output to be labelled by worker.)
I'm using R2016b, and I've set AutoAttachedFiles to false (I set AttachedFiles appropriately with parpool).
Garry
  댓글 수: 1
Edric Ellis
Edric Ellis 2016년 11월 21일
Hm, those two pieces of code ought to behave the same, as you expected. What happens if you try
spmd(1)
res = func(A(1));
end
Does that still show the problem? (This forces the spmd block to use only a single worker).

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

답변 (1개)

Walter Roberson
Walter Roberson 2016년 11월 16일
"id = labindex returns the index of the worker currently executing the function. labindex is assigned to each worker when a job begins execution, and applies only for the duration of that job. The value of labindex spans from 1 to n, where n is the number of workers running the current job, defined by numlabs."
labindex is not a counter of the iteration number: it is the worker number.
If you had used
parpool(n)
to try to get n workers so that each task would have its own worker, then that would fail if n exceeds the pool size (which typically defaults to the number of physical cores.)
Yes, if you know that there are exactly the same number of workers as you need iterations then it could work in place of a parfor.
  댓글 수: 1
Garry Hollier
Garry Hollier 2016년 11월 16일
Walter
I should have said that I ensure that n workers are running in both cases. I will edit the question.
But thanks for the response.
Garry

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by