How to link MPI application with PGI compilers


I have mpi program and I would like to compile and run the mpi application using PGI compiler. I have tried to use the MPICH compiler. However, i am getting some error.

$ module load mpich 
$ module load pgi 

pgc++ -Mmpi=mpich -fast -Minfo=all -ta=multicore -acc hello-world.cpp

2.32-GCCcore-8.3.0/bin/ld: cannot find -lmpich
2.32-GCCcore-8.3.0/bin/ld: cannot find -lopa
2.32-GCCcore-8.3.0/bin/ld: cannot find -lmpl

Could anyone please tell me how to link PGI with any MPI libraries, for example, Intel and OpenMPI.

Kind regards,

Hi Mathi,

Typically folks use the MPI driver, in this case mpic++ or mpicxx, instead of the compiler driver (i.e. pgc++/nvc++) which will take care adding the appropriate libraries and libraries paths. Though the MPI driver does need to be configured to use the NVHPC compilers.

The easiest thing to do is set your PATH to include one of the MPI builds that we ship. Now we did move the install directory where these are located a few years ago during the rebranding of PGI to NVHPC, so the location will be dependent on which version of the compiler you’re using. Pre-20.5, they’ll be in “$PGI//<release_year>/mpi/”, and post 20.5 they moved from the common directory to under the specific release directory: $NVHPC//<release_number>/comm_libs/".

Now the “-Mmpi” flag is legacy, and we no longer ship MPICH with the compilers. Though it should still be functional if you set the environment variable “MPIDIR” to the base install directory of you MPICH installations.

Alternatively, you can manually add the MPICH library path, “-L/path/to/mpich/lib”, and libraries, example: “-lmpich”, to the link line.


Hi Mat,

Now I have tried to use the following compilation option, but still I am getting some error.

pgc++ -Mmpi=mpich -L/opt/cray/pe/mpt/7.7.16/gni/mpich-pgi/20.1 -lmpich -fast -Minfo=all -ta=multicore -acc hello-world.cpp

line 9: catastrophic error: cannot open source file "mpi.h"
  #include <mpi.h>

Could you please give me some hints?

Kind regards,

You need to add the path to the directory containing the mpi header file. Not sure exactly where it is on you’re system, but assume it’s something like: