这是一个简单的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);
}
Run Code Online (Sandbox Code Playgroud)
但是,它似乎没有编译:
Undefined first referenced
symbol in file
MPI::Datatype::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
Run Code Online (Sandbox Code Playgroud)
我搜索了很多,查看了邮件列表,数以千计.他们说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
Run Code Online (Sandbox Code Playgroud)
我的编译器是g ++.
小智 10
只需将mpi.h头文件置于所有头文件的上方,有时会导致编译问题
我不确定你是如何执行你的代码的.编译
mpic++ your_code_file.c
Run Code Online (Sandbox Code Playgroud)
执行
mpirun -np <no. of Processors> ./a.out
Run Code Online (Sandbox Code Playgroud)