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.
mpicxx. Only add them if you keep the original linker, e.g.ld.