OStack程序员社区-中国程序员成长平台

标题: c++ - Open MPI "Hello, World!"未编译 [打印本页]

作者: 菜鸟教程小白    时间: 2022-10-25 09:09
标题: c++ - Open MPI "Hello, World!"未编译

这是一个简单的 MPI “Hello, World!”程序。

#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);
}

但是,它似乎没有编译:

Undefined                       first referenced
 symbol                             in file
MPI:atatype::Free()               /var/tmp//ccE6aG2w.o
MPI::Win::Free()                    /var/tmp//ccE6aG2w.o
MPI::Comm::Comm()                   /var/tmp//ccE6aG2w.o
ld: fatal: symbol referencing errors. No output written to main
collect2: ld returned 1 exit status

我搜索了很多,查看了邮件列表,其中有数千个。他们说 libmpi_cxx 没有链接。但它在编译器标志中。

这里是--showme数据:

mpic++ --showme:compile
-I/usr/openmpi/ompi-1.5/include -I/usr/openmpi/ompi-1.5/include/openmpi

mpic++ --showme:link
-R/opt/mx/lib -R/usr/openmpi/ompi-1.5/lib -L/usr/openmpi/ompi-1.5/lib -lmpi -lopen-rte -lopen-pal -lnsl -lrt -lm -ldl -lsocket -lmpi_cxx

我的编译器是 g++。



Best Answer-推荐答案


只需将 mpi.h 头文件放在所有头文件之上 有时会导致编译问题

我不确定你如何执行你的代码。 编译

mpic++ your_code_file.c

执行

mpirun -np <no. of Processors> ./a.out

关于c++ - Open MPI "Hello, World!"未编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14028136/






欢迎光临 OStack程序员社区-中国程序员成长平台 (http://ostack.cn/) Powered by Discuz! X3.4