Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open MPI "Hello, World!" is not compiling

Tags:

c++

g++

mpi

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++.

like image 372
efpies Avatar asked Dec 25 '12 06:12

efpies


3 Answers

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
like image 165
DOOM Avatar answered Oct 23 '22 02:10

DOOM


A few notes:

  1. Note that Open MPI 1.5 is ancient. Please upgrade to the latest version in the Open MPI 1.6.x series (which is currently 1.6.3, but note that the www.open-mpi.org web site is currently undergoing a planned year-end maintenance and won't be back up until later today, Thursday, December 28, 2012).

  2. I'm curious: why are you compiling a C program with mpic++? You only need to use mpicc -- the C MPI wrapper compiler. That would definitely avoid your issue. However, if you are using this small C hello world program as a simple example and your actual target is to compile a C++ MPI program, then mpic++ is the correct wrapper to try (even with a simple C program). If that's the case, then you have some kind of incompatibility / misconfiguration between your C++ compiler and the C++ compiler that Open MPI was compiled/installed with.

  3. Looking at your mpic++ --showme output, it looks like you have some kind of package distribution of Open MPI -- -R is not put in the flags by default, for example. Where did you get this Open MPI installation? It's quite possible that it is not (fully) compatible with your g++ installation (e.g., if it was compiled with a different version of g++).

  4. That being said, your mpic++ --showme output is also weird in that it lists -lmpi_cxx at the end of the line. It should be to the left of -lmpi, not to the right of it. I'm not show how your installation got borked like that, but that is another possible cause.

So to sum up, my answer is:

  1. Please try upgrading Open MPI and see if the problem goes away.
  2. Double check that your installation of Open MPI is compatible with your system.
like image 24
Jeff Squyres Avatar answered Oct 23 '22 02:10

Jeff Squyres


It is a also much easer and more flexible to compile openmpi and mpi programs in a "Eclipse for Parallel Application Developers" IDE.

http://www.eclipse.org/downloads/packages/eclipse-parallel-application-developers/junosr1

like image 30
user1436187 Avatar answered Oct 23 '22 02:10

user1436187