在Linux上启用OpenMPI
Enabling OpenMPI on Linux
我正在尝试使用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正确链接。
相关文章:
- 编译时未启用intel oneApi CUDA支持
- OpenGL在启用深度测试时不会丢弃我的碎片
- Visual C++GC接口如何启用它以及要包含哪个库
- 如何在自定义类中启用'auto loops'?
- 根据某个函数是否存在启用模板
- 视觉工作室 2017;启用 /permissive 时,类型 "const wchar_t *" 的参数与类型 "PWSTR" 的参数不兼容
- 启用从"vector<const T>&"到"const vector&"的隐式转换<T>
- C++ win32 如何使密码字段可选并启用复制和粘贴?
- 在 Eclipse 上启用 C++17 以使用 'std::byte'
- 如何要求 macports 用英特尔编译器包装 openmpi?
- 当 noexcept 函数尝试在 gcc 或 clang 中调用非 noexcept 函数时启用警告
- 如何为一段代码启用 -permissive
- 是否可以/希望创建不可复制的共享指针模拟(以启用weak_ptr跟踪/借用类型语义)?
- 在 GCC 中启用"differing levels of indirection"警告/错误
- 使用 Doxygen 记录枚举类值,而不启用EXTRACT_ALL
- '_HAS_CXX17'宏是否可用于自定义项目标头以启用C++17 语言集功能?
- 如何启用转换模板参数 T 以常量 T?
- 在使用 gSoap 链接多个 SOAP 服务时启用保持活动状态
- 如何启用标准::实验::atomic_shared_pointer
- 在Linux上启用OpenMPI