c++ - 为什么我会收到使用 MPI 屏障 [c++] 的 fatal error

标签 c++ ubuntu runtime-error mpi barrier

我是 MPI 新手,在尝试使用障碍时遇到了 fatal error 。我有一个简单的 for 循环,它以循环方式将索引分配给每个进程,紧随其后的是 MPI 屏障:

mpi.cc

#include <iostream>
#include <mpi.h>
#include <vector>
#include <sstream>

int main() {
    int name_len, rank, comm_size;
    char processor_name[MPI_MAX_PROCESSOR_NAME];
    MPI_Init(NULL, NULL);
    MPI_Get_processor_name(processor_name, &name_len);
    MPI_Comm comm = MPI_COMM_WORLD;
    MPI_Comm_rank(comm, &rank);
    MPI_Comm_size(comm, &comm_size);
    std::stringstream ss;    
    ss << "hello from: " << processor_name << " " << "Rank: " << rank << " Comm size: " << comm_size << "\n";

    for (int i =0; i < 20; i++) {
        if (i%comm_size != rank) continue;
        ss << "   " << i << "\n";
    }

    MPI_Barrier(comm);                          // Fails here
    std::cout << ss.str();
    MPI_Finalize();
}

我编译:
mpicxx mpi.cc -o mpi

然后使用以下命令在我的 2 节点集群上运行:
mpirun -ppn 1 --hosts node1,node2 ./mpi

我收到以下错误:
Fatal error in PMPI_Barrier: Unknown error class, error stack:
PMPI_Barrier(414).....................: MPI_Barrier(MPI_COMM_WORLD) failed
MPIR_Barrier_impl(321)................: Failure during collective
MPIR_Barrier_impl(316)................: 
MPIR_Barrier(281).....................: 
MPIR_Barrier_intra(162)...............: 
MPIDU_Complete_posted_with_error(1137): Process failed
Fatal error in PMPI_Barrier: Unknown error class, error stack:
PMPI_Barrier(414).....................: MPI_Barrier(MPI_COMM_WORLD) failed
MPIR_Barrier_impl(321)................: Failure during collective
MPIR_Barrier_impl(316)................: 
MPIR_Barrier(281).....................: 
MPIR_Barrier_intra(162)...............: 
MPIDU_Complete_posted_with_error(1137): Process failed

在一个节点上运行有效,但在 2 上运行时失败。有什么想法可能会出错吗?

最佳答案

我设法解决了我的问题。代替

mpirun -ppn 1 --hosts node1,node2 ./mpi

我分别明确使用了node1和node2的IP地址,不再有问题。看来问题出在我的/etc/hosts 文件上:
127.0.0.1   localhost
127.0.0.1   node1

主机似乎试图访问 localhost 而不是 node1。更多信息 here .

关于c++ - 为什么我会收到使用 MPI 屏障 [c++] 的 fatal error ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60491070/

相关文章:

linux - docker build 在 Ubuntu 16.04 上运行命令失败,但在具有相同 Docker 版本的 18.04 上运行命令失败

c - 为什么第 12 行被打印了两次?

c++ - 从两个 4x64 位整数数组中取模

c++ - 没有对 'pthread_create' 的匹配函数调用

node.js - 使用 curl 在 Ubuntu 中安装 Node

Javascript:使用源映射调试堆栈跟踪

JavaScript 错误 : "The resource was realized on the wrong render target"

c++ - 警告 : defaulted move assignment operator of X will move assign virtual base class Y multiple times

c++ - STL位集问题

java - 如何在不破坏当前设置的情况下安装多个版本的JDK?