4

I have a code on my computer uses Petsc which depends on mpi. On my computer it works well. I put it on cluster, exported paths of gcc, Petsc and openmpi (although I was using mpich on my computer I hope openmpi will also work) to LD_LIBRARY_PATH and PATH. I also changed paths in makefile. Petsc, gcc, openmpi were all available on cluster so I did not configure anything. When I did make, compiler gave error:

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

I know I did not give complete information but I can tell more if needed. How can I make the Petsc to know where is mpi.h?

Shibli
  • 5,879
  • 13
  • 62
  • 126

2 Answers2

2

Typically, you should use mpicc (or mpicxx for C++) to compile instead of gcc (or g++ for C++). These commands are simple wrappers around gcc and g++ that simply add in the appropriate -I/path/to/mpi/includes and -L/path/to/mpi/libs automatically and should be included with your openmpi install. In the absence of that, simply add -I/path/to/mpi/includes in your command to compile the appropriate files. This tells the compiler where to look for the appropriate header files.

R_Kapp
  • 2,818
  • 1
  • 18
  • 32
  • my code is written in c++ and petsc is in c. Would it be a problem if I use mpicxx only? – Shibli Dec 09 '15 at 18:09
  • How are you currently compiling petsc (I've never used it before)? If you are using g++ to compile petsc, use mpicxx; the behavior will be identical. If you are using gcc to compile petsc, use mpicc. – R_Kapp Dec 09 '15 at 18:10
-4

To answer the question. To prevent a C/C++ editor from showing errors as you tyoe in the "special code" just use:

#include </usr/include/mpi/mpi.h>

which seems to be a link -- but doing that turns off the errors in Netbeans editor so I can code without distraction. Note: Using Ubuntu 18.04 Desktop as editing machine -- and testing run machine -- but I compile manually using mpic as noted previously.

sudo mpicc c_pi.c -o c_pi

and then...
mpiexec ./c_pi

hth

DaveWR
  • 3
  • 3
  • 1
    Specifying the full path in the `#include` directive seems like a bad idea. You should be able to use `#include `, and the compiler or wrapper should figure it out. If you're using an editor that warns you about headers it can't find, you'll be better off figuring out how to tell the editor where to find `mpi.h` rather than modifying your code. – Keith Thompson May 24 '18 at 21:45