繁体   English   中英

在Linux上启用OpenMPI

[英]Enabling OpenMPI on Linux

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

须藤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);
}

但是我得到了这个错误:

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

然后, mpicxx此处的建议,我将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库都带有特殊的编译器包装器,例如:

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

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

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

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

mpicxx -showme:link

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM