gpt4 book ai didi

c++ - 在 Linux 上启用 OpenMPI

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:21:56 24 4
gpt4 key购买 nike

我正在尝试使用 CodeBlocks 在 Ubuntu 上启用 OpenMPI。我已经使用以下方法下载了它:

sudo apt-get install -y  autotools-dev g++ build-essential openmpi1.6-bin openmpi1.6-doc libopenmpi1.6-dev

之后我尝试运行以下代码:

#include <stdio.h>
#include <mpi.h>

int main(int argc, char **argv)
{
int size, rank;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
printf("SIZE = %d RANK = %d\n",size,rank);
MPI_Finalize();
return(0);
}

但是我得到了这个错误:

fatal error: mpi.h: No such file or directory

然后我将 c++ 编译器从 g++ 更改为 mpicxx,这里推荐:FAQ: Compiling MPI .
但是,当我现在尝试运行我的代码时,出现了以下一堆错误:

openmpi.cpp|| undefined reference to `MPI_Init'|
openmpi.cpp|| undefined reference to `ompi_mpi_comm_world'|
openmpi.cpp|| undefined reference to `MPI_Comm_size'|
openmpi.cpp|| undefined reference to `ompi_mpi_comm_world'|
openmpi.cpp|| undefined reference to `MPI_Comm_rank'|
openmpi.cpp|| undefined reference to `MPI_Finalize'|
[...]

我想,我必须添加路径或链接库,但我不确定如何实现。我也不知道 OpenMPI 在我机器上的安装位置。
我也从网站上下载了文件夹,如果有帮助的话。

更新
mpicxx 添加到链接器和 -pthread -L/opt/openmpi/lib -lmpi_cxx -lmpi -ldl -lm -Wl,--export-dynamic -lrt -lnsl -lutil - 后lm -ldl 作为附加标志,我终于可以编译代码了。
但是现在我得到另一个错误:

[[INVALID],INVALID] ORTE_ERROR_LOG: A system-required executable either could not be found or was not executable by this user in file ess_singleton_module_c at line 231
[...]
Soory! You were supposed to get help about:
orte_init:startup:internal-failure
But I couldn't open the file:
/usr/share/openmpi/help-orte-runtime: No such file or directory.

最佳答案

大多数 MPI 库都带有特殊的编译器包装器,例如:

  • mpicc 用于 C 编译器;
  • mpic++/mpiCC/mpicxx 用于 C++ 编译器;
  • mpif77/mpif90/mpif95 Fortran 编译器;
  • 其他特定于发行版的包装器,例如mpiicc,用于带有英特尔 C 编译器的英特尔 MPI 库。

这些包装器提供了编译器查找包含文件和链接正确库所需的所有选项。

因此,您必须更新项目设置并将编译器和链接器更改为mpicxx

另一种选择是运行以下命令:

mpicxx -showme:link

它将为您提供一个选项列表,您应该将这些选项添加到项目设置中的链接器标志中,以便将可执行文件与 Open MPI 正确链接。

关于c++ - 在 Linux 上启用 OpenMPI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20206718/

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