【问题标题】:Getting Fatal error when calling MPI_Reduce inside a loop在循环内调用 MPI_Reduce 时出现致命错误
【发布时间】:2021-09-06 05:16:35
【问题描述】:

我在这部分代码中有问题(这在任务之间很常见):

for (i = 0; i < m; i++) {
    // some code
    MPI_Reduce(&res, &mn, 1, MPI_INT, MPI_MIN, 0, MPI_COMM_WORLD);
    // some code
}

这工作正常,但对于较大的 m 值,我收到此错误:

    Fatal error in PMPI_Reduce: Other MPI error, error stack:
    PMPI_Reduce(1198).........................: MPI_Reduce(sbuf=008FFC80, rbuf=008FFC8C, count=1, MPI_INT, MPI_MIN, root=0, MPI_COMM_WORLD) failed
    MPIR_Reduce(764)..........................:
    MPIR_Reduce_binomial(207).................:
    MPIC_Send(41).............................:
    MPIC_Wait(513)............................:
    MPIDI_CH3i_Progress_wait(215).............: an error occurred while handling an event returned by MPIDU_Sock_Wait()
    MPIDI_CH3I_Progress_handle_sock_event(436):
    MPIDI_CH3_PktHandler_EagerShortSend(306)..: Failed to allocate memory for an unexpected message. 261895 unexpected messages queued.
    
    job aborted:
    rank: node: exit code[: error message]
    0: AmirDiab: 1
    1: AmirDiab: 1
    2: AmirDiab: 1: Fatal error in PMPI_Reduce: Other MPI error, error stack:
    PMPI_Reduce(1198).........................: MPI_Reduce(sbuf=008FFC80, rbuf=008FFC8C, count=1, MPI_INT, MPI_MIN, root=0, MPI_COMM_WORLD) failed
    MPIR_Reduce(764)..........................:
    MPIR_Reduce_binomial(207).................:
    MPIC_Send(41).............................:
    MPIC_Wait(513)............................:
    MPIDI_CH3i_Progress_wait(215).............: an error occurred while handling an event returned by MPIDU_Sock_Wait()
    MPIDI_CH3I_Progress_handle_sock_event(436):
    MPIDI_CH3_PktHandler_EagerShortSend(306)..: Failed to allocate memory for an unexpected message. 261895 unexpected messages queued.
    3: AmirDiab: 1

有什么建议吗?

【问题讨论】:

  • MPI_INTbool 不匹配(在 C++ 中使用 MPI_CXX_BOOL,请参阅 stackoverflow.com/questions/57598517/…
  • 感谢您的评论,bool 实际上是 int,正如我在代码中写 typedef int bool; 所指出的那样,我将 bool 定义为 int。如果这让人感到困惑,我很抱歉。我会编辑问题:)
  • 根本原因可能是先前内存损坏的结果。你能用minimal reproducible example 编辑你的问题吗?
  • MPI_Reduce的返回值是多少?
  • 我是 MPI 新手,不知道 reduce 在任务之间的实际工作方式,你的意思是我应该避免在循环内使用 MPI_Reduce 吗? @GillesGouaillardet

标签: c++ c mpi


【解决方案1】:

您的通信模式似乎使 MPI 负担过重。注意261895 unexpected messages queued 错误消息。那是相当多的消息。由于 MPI 会急切地尝试发送小消息的数据(例如您的单元素缩减),因此在循环中运行数十万个 MPI_Reduce 调用可能会在传输中的消息过多时导致资源耗尽。

如果可能,请尝试重新安排您的算法,以便在一次归约中处理所有 m 元素,而不是遍历它们:

int* res = malloc(m * sizeof(int));
int* ms  = malloc(m * sizeof(int));

for (i = 0; i < m; ++i) {
    ms[i] = /* ... */
}

MPI_Reduce(res, ms, m, MPI_INT, MPI_MIN, 0, MPI_COMM_WORLD);

或者,按照 cmets 中的建议,您可以在循环中每隔一段时间添加一次 MPI_Barrier() 调用,以限制未完成消息的数量。

【讨论】:

  • 太棒了!!这以良好的性能解决了我的问题。谢谢你的回答。
猜你喜欢
  • 1970-01-01
  • 2011-03-16
  • 1970-01-01
  • 1970-01-01
  • 2020-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多