Fpm with Intel MPI

Hello, I am new to the fpm and experimenting with its functionality. It’s probably trivial but I am having troubles with building a project using Intel MPI library. Say I want to build the following hello_world using mpi:

program helloworld
    use mpi
    implicit none
    integer :: rank, comsize, ierr
    call MPI_Init(ierr)
    call MPI_Comm_size(MPI_COMM_WORLD, comsize, ierr)
    call MPI_Comm_rank(MPI_COMM_WORLD, rank, ierr)
    print *,'Hello World, from task ', rank, 'of', comsize
    call MPI_Finalize(ierr)
  end program helloworld

I tried multiple combinations of commands from fpm but I keep getting the following error message:
<ERROR>*cmd_build*:target error:Unable to find source for module dependency: "mpi" used by "app/hello_mpi.f90"

I have Intel MPI loaded as a module on the cluster I am working on. Is there a way to build it using fpm? Thanks in advance.

Welcome! :wave:

To build with Intel MPI you to have specify the dependency on the MPI module on the fpm.toml file:

 external-modules = "mpi"

and then use the MPI wrapper to compile the program:

fpm build --compiler 'mpiifort'

and that should do it.


Just beat me to it. But for further reference, you may want to checkout the Manifest Reference, where these kind of options are documented.

1 Like

Each MPI setup varies, and so how to run the program can vary from having
to use fpm run --runner ‘mpirun …’ to having to make a customized compiler
script but for a basic MPI program using the Intel software on Linux or Unix
it is just a matter of specifying mpiifort instead of ifort as your compiler
and specifying that the mpi module is external to your package.

You want to make sure to look at the fpm(1) manifest file format. In

In particular that means to add the ‘external-modules - “mpi”’ line to
your fpm.toml file.

Then, depending on which fpm(1) version you have you can set the FPM_FC
environment variable to “mpiifort”. Note the two "i"s.

If that does not work, add the “–compiler mpiifort” option to any build,
run, test subcommands.

For simpler projects you are ready to go. You may find setting some
of the options for more complex projects is done more easily through
an Intel ifort configuration variable or file, but try to do as much
with the fpm.toml file as possible, as it will not be a self-contained
package if it depends on such files and would be harder to make into a
remote dependency package for others to use.

name = "mpi"
version = "0.1.0"
license = "license"
author = "Jane Doe"
maintainer = "jane.doe@example.com"
copyright = "Copyright 2021, Jane Doe"
auto-executables = true
auto-tests = true
auto-examples = true

external-modules = "mpi"

library = false

Ahh, looks like this got answers while I was trying out some options with other MPI packages and platforms and got sidetracked. At least we all agree :>

I think a “hello world” program for common MPI variants, OpenMP, and LAPACK in particular would be a great subsection for the fpm documentation page.


Thanks a lot for your insights. I got my mpi code working with fpm.