Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper way to handle MPI communicators in Fortran?

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?

like image 644
Tarek Avatar asked Jan 06 '17 14:01

Tarek


People also ask

What is MPI in Fortran?

MPI stands for Message Passing Interface. • It is a library of subroutines/functions, not a computer. language. • Programmer writes fortran/C code, insert appropriate MPI. subroutine/function calls, compile and finally link with MPI message passing library.

What is MPI Comm_world?

COMM_WORLD. This is a communicator (group) containing all processes available to the program. size = MPI::COMM_WORLD. Get_size(); The Get_size() function returns the size of the COMM_WORLD, or the total number of processes available to the program.

What is Mpif H?

The mpif. h file is a header and will be in the include directory ( /home/hamid/edpacks/mpich-install/include in your case). – Timothy Brown.


1 Answers

The use mpi_f08 interface introduces different wrapper types for the different MPI handle objects. While in mpif.h and the use mpi interfaces all handles are simply INTEGERs, in the use mpi_f08 interface there are TYPE(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.,

INTEGER :: newcomm

becomes

TYPE(MPI_Comm) :: newcomm

On the binary level there is no change since all those MPI_Xyz types are simply an INTEGER wrapped in a TYPE specifier, which makes them layout compatible. Old Fortran code can still exchange MPI handles with modern Fortran code and vice versa - the INTEGER handle value can be set or extracted via newcomm%MPI_VAL.

like image 98
Hristo Iliev Avatar answered Oct 23 '22 16:10

Hristo Iliev