【问题标题】:MPI GRAPH : Send Messages to neighbours except where it came fromMPI GRAPH : 向邻居发送消息,除了消息来自的地方
【发布时间】:2016-01-08 00:01:13
【问题描述】:

我有一个有趣的情况。我试图让图中的一个节点向它的所有邻居发送消息,除了它的父节点(刚刚发送消息的节点)。我的代码似乎表明这个特定的节点( n )确实从它的所有邻居(正确)接收消息。问题在于发送,仅发送到达的第一条消息。所有其他都被忽略。 注意:这是一个星型拓扑,所有其他节点都发送到中心节点 0 这是示例输出:-

  0    received  1 from 1
  0    received  2 from 2
  0    received  3 from 3
  0    received  4 from 4
  0    received  5 from 5
  0    received  6 from 6


  Having correctly  received these values, node zero(0 ) is expected to send each message to all others in the following pattern  i.e. :-

      0 sent   1 to 2
      0 sent   1 to 3
      0 sent   1 to 4
      0 sent   1 to 5
      0 sent   1 to 6

   , 
      0 sent   2 to 1
      0 sent   2 to 3
      0 sent   2 to 4
      0 sent   2 to 5
      0 sent   2 to 6
    ,
      0 sent   3 to 2
      0 sent   3 to 1
      0 sent   3 to 4
      0 sent   3 to 5
      0 sent   3 to 6

, etc .

不幸的是,否则,只有第一条消息被发送到其他节点,其余的被忽略。即如果 1 先被 0 接收,我只会得到以下输出:-

  0 sent   1 to 2
  0 sent   1 to 3
  0 sent   1 to 4
  0 sent   1 to 5
  0 sent   1 to 6

不发送所有其他消息。

星图拓扑中心节点的代码如下所示:-

     MPI_Recv(&message , 1 , MPI_INT ,  MPI_ANY_SOURCE , echo_tag, COMM, &status ); 

//Sending just received message to neighbors, except to parent :-

    parent = status.MPI_SOURCE;

    for ( int l = 0 ; l< neighbourcount ; l++ ){
         int current_neighbour =  neighbours[l];
          if (  current_neighbour != parent ){
                    MPI_Send(&message , 1 , MPI_INT , current_neighbour , tag, COMM );
          }
    }

【问题讨论】:

  • 很难从最后的 sn-p 代码中分辨出来,但是您是否有某种“外循环”迭代接收到的消息,然后将它们一一发送给适当的邻居或您是否立即发送任何收到的消息然后返回MPI_Recv()?您能否添加更多代码以便更好地了解代码在(不)在做什么?
  • 嗨,谢谢。我刚刚编辑了没有外循环的代码。不过我似乎理解你的想法。您似乎建议我将所有代码放在重复 cout_neighbours - 1 次的循环中?
  • 是的!可能应该使用类似for (messageIdx = 0; messageIdx &lt; TOTAL_NUMBER_OF_EXPECTED_MESSAGES; ++messageIdx) { MPI_Recv(); /* the for loop for sending to the neighbours */ }
  • 这是合乎逻辑的,但是代码在完成后会挂起。即使它仅在第 1 次迭代时挂起,但已收到所有消息。
  • 由于节点 0 有 6 个邻居,在进入外部 for 循环之前定义 int message[6]; 并仅调用一次 MPI_Recv(message , 6, MPI_INT , MPI_ANY_SOURCE , echo_tag, COMM, &amp;status ); 怎么样?此外,您可能需要将对MPI_Send() 的调用更改为MPI_Send(&amp;message[messageIdx] , 1 , MPI_INT , current_neighbour , tag, COMM );。正如提到的here,您可能应该在进入外部for循环之前使用MPI_Get_count()来获取实际的TOTAL_NUMBER_OF_EXPECTED_MESSAGES

标签: c++ parallel-processing mpi distributed openmpi


【解决方案1】:

你需要一个替身来完成这项工作,像这样:

int j;
for(j = 0; j < neighbourcount; ++j) {
   for ( int l = 0 ; l< neighbourcount ; l++ ){
         int current_neighbour =  neighbours[l];
          if (  current_neighbour != parent ){
                    MPI_Send(/*send j*/ , 1 , MPI_INT , current_neighbour , tag, COMM );
          }
    }
}

【讨论】:

    猜你喜欢
    • 2015-08-20
    • 2018-05-25
    • 2015-08-10
    • 1970-01-01
    • 2018-09-29
    • 2013-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多