gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:20:15 26 4
gpt4 key购买 nike

我是 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com