I read that is recommended to use the MPI module rather than include mpif.h file. However, I get the following error
Error: There is no specific subroutine for the generic ‘mpi_comm_split’
when I run this program
program hello_world
use mpi_f08
implicit none
! include 'mpif.h'
integer :: ierr, num_procs, my_id,newcomm
integer :: color,key
call MPI_INIT ( ierr )
color =1; key=0
call MPI_COMM_RANK (MPI_COMM_WORLD, my_id, ierr)
call MPI_COMM_SIZE (MPI_COMM_WORLD, num_procs, ierr)
call MPI_Comm_split(MPI_COMM_WORLD, color,key,newcomm, ierr)
call MPI_FINALIZE ( ierr )
end
The error disappears if I include 'mpif.h' instead of using the MPI module. Why is that?
The
use mpi_f08
interface introduces different wrapper types for the different MPI handle objects. While inmpif.h
and theuse mpi
interfaces all handles are simplyINTEGER
s, in theuse mpi_f08
interface there areTYPE(MPI_Comm)
,TYPE(MPI_File)
, etc. This allows the compiler to perform checks for things like passing a communicator handle where a file handle is expected.This is a breaking change on the source level as code must be rewritten, e.g.,
becomes
On the binary level there is no change since all those
MPI_Xyz
types are simply anINTEGER
wrapped in aTYPE
specifier, which makes them layout compatible. Old Fortran code can still exchange MPI handles with modern Fortran code and vice versa - theINTEGER
handle value can be set or extracted vianewcomm%MPI_VAL
.