68

when I compile my script with only

#include <mpi.h>

it tells me that there is no such file or directory. But when i include the path to mpi.h as

#include "/usr/include/mpi/mpi.h"

(the path is correct) it returns:

In file included from /usr/include/mpi/mpi.h:2087:0,
                 from lbm.cc:7:
/usr/include/mpi/openmpi/ompi/mpi/cxx/mpicxx.h:35:17: fatal error: mpi.h: No such file or directory
 #include "mpi.h"
                 ^
compilation terminated.

Anyone know how to fix this?

3
  • What is your compiler and operating system? Commented Nov 13, 2014 at 23:04
  • g++ on linux. and <mpi/mpi.h> doesn't work either. Commented Nov 13, 2014 at 23:34
  • 2
    Program using the Message Passing Interface should be compiled by using something like mpicc main.c -o main or mpiCC main.cpp -o main. Is it your case ? Regarding the second message : you may have two implementations of the MPI standards on your computer. You may try to know more by typing which mpicc, which mpirun, mpirun --version or module avail. The implementation (openmpi or mpich2 or...) of compiler command must be the same as the command to execute the program mpirun -np 2 main. Commented Nov 13, 2014 at 23:38

12 Answers 12

63

On my system, I was just missing the Linux package.

sudo apt install libopenmpi-dev
pip install mpi4py

(example of something that uses it that is a good instant test to see if it succeeded)

Succeded.

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

1 Comment

The first line of this solution will also work if you are getting this error while building lammps: $ cmake ../cmake -- Running check for auto-generated files from make-based build system CMake Error in /home/name/lammps-23Jun2022/build/CMakeFiles/CMakeScratch/TryCompile-Iqf2dm/CMakeLists.txt: Imported target "MPI::MPI_CXX" includes non-existent path "/usr/lib/x86_64-linux-gnu/openmpi/include" in its INTERFACE_INCLUDE_DIRECTORIES.
62

The problem is almost certainly that you're not using the MPI compiler wrappers. Whenever you're compiling an MPI program, you should use the MPI wrappers:

  • C - mpicc
  • C++ - mpiCC, mpicxx, mpic++
  • FORTRAN - mpifort, mpif77, mpif90

These wrappers do all of the dirty work for you of making sure that all of the appropriate compiler flags, libraries, include directories, library directories, etc. are included when you compile your program.

5 Comments

The conundrum lies in the fact that openmpi does not have MPI wrappers for mpicc, mpicxx, etc.
There may be some implementations that don't provide them, but Open MPI isn't one of them. It definitely has at least mpicc and mpicxx and mpifortan.
can you explain how to fix this? i am trying to make someone's program and it gives the error in the original post. it is looking for mpi.h. I installed api using apt-get. Still get the same error.
No info were given as to how to use those wrappers; adding them to the compiler like -mpiCC, installing a wrapper and including it in source file?
@user391339 and Romario By default your IDE uses cmake or so to compile the .cpp file, right?.. Instead you will use the mpi wrapper (which is simply a compiling/executing command) to compile/execute your program. An example would be: $ mpic++ main.cpp and an example to run your program would be $ mpirun -np 2 a.out
20

You can execute:

$ mpicc -showme 

result :

gcc -I/Users/<USER_NAME>/openmpi-2.0.1/include -L/Users/<USER_NAME>/openmpi-2.0.1/lib -lmp

This command shows you the necessary libraries to compile mpicc

Example:

$ mpicc -g  -I/Users/<USER_NAME>/openmpi-2.0.1/include -o [nameExec] [objetcs.o...] [program.c] -lm


$ mpicc -g  -I/Users/<USER_NAME>/openmpi-2.0.1/include -o example file_object.o my_program.c otherlib.o -lm

this command generates executable with your program in example, you can execute :

$ ./example

1 Comment

are you suggesting to use the wrappers in order to extract some information and then pass it again to the wrappers ?
9

On my system Ubuntu 16.04. I installed :

sudo apt install libopenmpi-dev

after I used mpiCC to compile and it works

Comments

5

As suggested above the inclusion of

/usr/lib/openmpi/include 

in the include path takes care of this (in my case)

1 Comment

/usr/lib64/mpi/gcc/openmpi/include/ for OpenSUSE Leap
3

Debian appears to include the following:

  • mpiCC.openmpi
  • mpic++.openmpi
  • mpicc.openmpi
  • mpicxx.openmpi
  • mpif77.openmpi
  • mpif90.openmpi

I'll test symlinks of each for mpic, etc., and see if that helps the likes of HDF5-openmpi enabled find mpi.h.

Take that back Debian includes symlinks via their alternatives system and it still cannot find the proper paths between HDF5 openmpi packages and mpi.h referenced in the H5public.h header.

Comments

2

On Ubuntu 18.04 I had to install:

sudo apt install lam4-dev

1 Comment

Lam in ancient. Don’t use it. Use Open-MPI 3+ or MPICH 3+.
1

On Fedora:

dnf install openmpi-devel

Comments

1

once you have mpi installed:

$ sudo apt install mpich

see where the library is installed, each case is different:

$ mpicc -show

in my case: (Ubuntu 20.0)

and add...

#include </usr/lib/x86_64-linux-gnu/openmpi/include/openmpi>

:-)

Comments

1

On Ubuntu 20.04, this worked for me:

apt -y install lam-runtime

Comments

0

On Mac 12.2, I installed with brew install openmpi. The header file is under /opt/homebrew/Cellar/open-mpi/x.x.x/include.

Comments

0

On CentOS, I had to augment my PATH after installing openmpi3:

$ sudo yum install openmpi3-devel
...
$ export PATH=/usr/lib64/openmpi3/bin/:$PATH
$ mpicc --version
gcc (GCC) ... 
$ pip3 install mpi4py

Comments

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.