2

I'm trying to enable OpenMPI on Ubuntu using CodeBlocks. I have already downloaded it using:

sudo apt-get install -y  autotools-dev g++ build-essential openmpi1.6-bin openmpi1.6-doc libopenmpi1.6-dev

Afterwards I tried to run the following code:

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

But I got this error:

fatal error: mpi.h: No such file or directory

Then I changed the c++ compiler from g++ to mpicxx as it's recommended here: FAQ: Compiling MPI.
But when I try to run my code now, I get the following bunch of errors:

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'|
[...]

I assume, I have to add the Path or link the library, but I'm not sure how to achieve this. I also don't know where OpenMPI has been installed on my machine.
I have downloaded the folder from the website, as well, if that can help.

Update
After adding mpicxx to the linker and -pthread -L/opt/openmpi/lib -lmpi_cxx -lmpi -ldl -lm -Wl,--export-dynamic -lrt -lnsl -lutil -lm -ldl as additional flags, I finally can compile the code.
But now I get another error:

[[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.
1
  • You don't have to add the long list of options to the linker flags if you change the linker to mpicxx. Only add them if you keep the original linker, e.g. ld. Commented Nov 26, 2013 at 11:12

1 Answer 1

2

Most MPI libraries come with special compiler wrappers, e.g.:

  • mpicc for the C compiler;
  • mpic++/mpiCC/mpicxx for the C++ compiler;
  • mpif77/mpif90/mpif95 for the Fortran compiler;
  • other distribution-specific wrappers, e.g. mpiicc for Intel MPI library with Intel C Compiler.

These wrappers provide all options that are needed by the compiler in order to find the include files and link the proper libraries.

Therefore you have to update your project settings and change both the compiler and the linker to mpicxx.

Another option would be to run the following command:

mpicxx -showme:link

It will give you a list of options that you should add to the linker flags in your project's settings in order to properly link the executable with Open MPI.

Sign up to request clarification or add additional context in comments.

2 Comments

@user1170330, I find it strange that you've added Ubuntu Open MPI packages via apt-get and yet the flags that you get from mpicxx -showme point to /opt/openmpi/lib. Packages supplied by the distribution usually have their files in /usr. Do you happen to have both system Open MPI packages and a version that you have compiled by yourself?
Remove /opt/openmpi/bin from the path and use the libraries that come with the distribution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.