gpt4 book ai didi

c++ - OpenMPI:错误: ‘MPI’ 尚未声明

转载 作者:搜寻专家 更新时间:2023-10-31 01:31:04 24 4
gpt4 key购买 nike

在运行 OpenMPI 命令“mpicxx hello_cxx.cc -o hello”时总是出现以下错误

hello_cxx.cc: In function ‘int main(int, char**)’: 
hello_cxx.cc:25:5: error: ‘MPI’ has not been declared
MPI::Init();
^~~ hello_cxx.cc:26:12: error: ‘MPI’ has not been declared
rank = MPI::COMM_WORLD.Get_rank();
^~~ hello_cxx.cc:27:12: error: ‘MPI’ has not been declared
size = MPI::COMM_WORLD.Get_size();
^~~ hello_cxx.cc:31:5: error: ‘MPI’ has not been declared
MPI::Finalize();
^~~

最佳答案

您的应用程序正在使用 MPI C++ 绑定(bind)。请记住,C++ 绑定(bind)已从 MPI 标准中删除。

从 Open MPI 的角度来看,C++ 绑定(bind)仍然存在,但自 Open MPI 2.0.0 以来,它们不再是默认构建的。

因此,如果您使用的是 Open MPI 2.0.0 或更高版本,则首先需要确保构建了 C++ 绑定(bind)。如果没有,您需要重建 Open MPI,并使用 --enable-mpi-cxx 选项进行配置。

从长远来看,您真的应该远离 MPI C++ 绑定(bind)。您可以使用纯 C 绑定(bind),也可以探索其他 C++ 绑定(bind),例如流行的 Boost:MPI 库。

关于c++ - OpenMPI:错误: ‘MPI’ 尚未声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46409575/

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