fatal error: mpi.h: No such file or directory #include <mpi.h>
Solution 1
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.
Solution 2
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.
Solution 3
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
Solution 4
As suggested above the inclusion of
/usr/lib/openmpi/include
in the include path takes care of this (in my case)
Solution 5
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.
user2804865
Updated on July 21, 2022Comments
-
user2804865 almost 2 years
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?
-
Marc J. Driftmeyer over 9 yearsThe conundrum lies in the fact that openmpi does not have MPI wrappers for mpicc, mpicxx, etc.
-
Wesley Bland over 9 yearsThere may be some implementations that don't provide them, but Open MPI isn't one of them. It definitely has at least
mpicc
andmpicxx
andmpifortan
. -
user391339 almost 8 yearscan 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.
-
Max over 7 years/usr/lib64/mpi/gcc/openmpi/include/ for OpenSUSE Leap
-
Gilles Gouaillardet about 6 yearsare you suggesting to use the wrappers in order to extract some information and then pass it again to the wrappers ?
-
Terry over 4 yearsNo 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? -
Hasnaa Ibraheem over 4 years@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
-
Jeff Hammond about 3 yearsLam in ancient. Don’t use it. Use Open-MPI 3+ or MPICH 3+.