在Linux上启用OpenMPI

Enabling OpenMPI on Linux

本文关键字:OpenMPI 启用 Linux      更新时间:2023-10-16

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

sudo apt-get-install-y-autotools-dev g++build essentialopenmpi1.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 = %dn",size,rank);
   MPI_Finalize();   
   return(0);
}

但我得到了这个错误:

致命错误:mpi.h:没有这样的文件或目录

然后,我将c++编译器从g++更改为mpicxx,如下所示:常见问题解答:编译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'|
[...]

我想,我必须添加Path或链接库,但我不确定如何实现这一点。我也不知道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库都带有特殊的编译器包装器,例如:

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

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

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

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

mpicxx -showme:link

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