Open MPI "Hello, World!" is not compiling

efpies picture efpies · Dec 25, 2012 · Viewed 27.9k times · Source

Here is a simple MPI "Hello, World!" program.

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

However, it doesn't seem to compile:

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

I've googled a lot, viewed mailing lists, thousands of them. They say libmpi_cxx is not linking. But it's in the compiler flags.

Here is --showme data:

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

My compiler is g++.

Answer

DOOM picture DOOM · Dec 25, 2012

Just place the mpi.h header file above all header files sometimes that causes problem to compile

I am not sure how u execute your code. Compiling

mpic++ your_code_file.c

Execution

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