The Tag Field of labSendReceive() Function

1 回表示 (過去 30 日間)
Jim Chung
Jim Chung 2020 年 7 月 18 日
回答済み: Walter Roberson 2020 年 7 月 20 日
Hello, the Forum!
The following code allows the dataReceived vector of each node has the same values in its nodeList. But my question is how to make use of the "tag". I wish to inform the neighboring agents, say j, that some data corresponds to Agent i. I did it this way: dataReceived = [dataReceived, labSendReceive(nodeList{labindex}(i),nodeList{labindex}(i),labindex, labindex)], but it turned out to be something like an infinite loop. Thank you!
nodeList{1} = [2,4];
nodeList{2}= [1,4];
nodeList{3} = 4;
nodeList{4} = [1,2,3];
parpool('local',4);
spmd
% mydata = magic(labindex);
dataReceived = [ ];
for i = 1:length(nodeList{labindex})
% labSend(labindex,nodeList{labindex}(i));
% dataReceived = [dataReceived, labReceive(nodeList{labindex}(i))];
dataReceived = [dataReceived, labSendReceive(nodeList{labindex}(i),nodeList{labindex}(i),labindex)];
end
end

採用された回答

Edric Ellis
Edric Ellis 2020 年 7 月 20 日
The function labSendReceive requires matched communication, so the receiver always knows which lab sent the data. In your example, the nodeList entries are arranged so that there is no communication mismatch - but this will probably be difficult to arrange in the general case. I'm not quite sure where your actual problem is because your code as written completes successfully. I would consider re-writing the labSendReceive loop so that each worker communicates with each other worker in turn, like this:
spmd
dataReceived = cell(1, numlabs);
for labOffset = 1:(numlabs-1)
sendTo = 1 + mod(labindex-1 + labOffset, numlabs);
recvFrom = 1 + mod(labindex-1 - labOffset, numlabs);
dataToSend = magic(labindex);
dataReceived{recvFrom} = labSendReceive(sendTo, recvFrom, dataToSend);
end
end
  1 件のコメント
Jim Chung
Jim Chung 2020 年 7 月 20 日
Thank you again, Edric.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 7 月 20 日
The tag parameter is mostly intended to permit priority queuing. Except rather than the standard priority according to numeric values, the receiving end can query for a particular value to handle those first

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by