필터 지우기
필터 지우기

Why this piece of parallel code in MATLAB does not work ?

조회 수: 1 (최근 30일)
Ammar
Ammar 2017년 5월 18일
댓글: Steven Lord 2017년 5월 18일
Dear all, I am using pmode tool in MATLAB for parallel execution. I have situation where if there are two cores work in parallel and I want their internal results to be broadcast so other cores will know what each core is doing with own variables.
Please, the following code demonstrate the problem I am facing.
Kind regards Ammar -------------------------------------------------
itr=1;
while itr<=4
if labindex==1
X=itr;
itr=itr+1;
labBroadcast(1,X);
labBroadcast(1,itr);
elseif labindex==2
Y=itr;
itr=itr+1;
labBroadcast(2,Y);
labBroadcast(2,itr);
else
X=labBroadcast(1);
Y=labBroadcast(2);
itr=labBroadcast(1);
itr=labBroadcast(2);
end
end
---------------------------------------- The error message is
Warning: An incoming message was discarded from lab 2 (tag: 400003) Warning: An incoming message was discarded from lab 1 (tag: 400003)

답변 (1개)

Steven Lord
Steven Lord 2017년 5월 18일
I believe that the causes for the two warning messages is that the worker with labindex == 1 (worker 1) does not have any code indicating it is to receive the data from the variable Y being broadcast by the worker with labindex == 2 (worker 2.) Nor does worker 2 have any code indicating it is to receive the data being broadcast by worker 1.
Based on the last paragraph in the Description section of the documentation page for the labBroadcast function I think you'll need to be very careful about the ordering of the labBroadcast calls to send and receive on workers 1 and 2. Otherwise you might end up with worker 1 waiting to send its information until it receives information from worker 2 and vice versa.
  댓글 수: 2
Ammar
Ammar 2017년 5월 18일
Dear Steven, I would like to thank you for this answer. Please, do you know how can I broadcast internal variables between parallel workers ? Regards
Steven Lord
Steven Lord 2017년 5월 18일
By my understanding of the function, broadcasting involves one worker "speaking" and each of the other workers "listening". If one or more of the other workers aren't listening, you will receive the warning that the non-speaking, non-listening workers didn't receive the message.
Perhaps if you describe what you're trying to do in more detail, someone may be able to offer suggestions about whether pmode is the right tool or if something else, like parfor, spmd, or other parts of Parallel Computing Toolbox may be a better fit.

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

카테고리

Help CenterFile Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by