简体   繁体   中英

Code get compiled when include 'mpif.h' but failed when switch to use mpi

I am trying to switch to use mpi for some old fortran codes I have. I got some strange errors when compiling the code.

Error: There is no specific subroutine for the generic 'mpi_type_indexed' at (1)

when I try to switch to 'use mpi' in the code. If I use 'include 'mpif.h'' then the program got compiled and is able to run correctly.

I have written a compact example to verify the program. Both the code and my example are compiled under gcc/8.1.0 and openmpi/3.1.2.

program bt

use mpi

implicit none

!include 'mpif.h'

contains

subroutine read_me()
implicit none
integer :: my_n, my_disp, my_type
integer :: ierr

my_n = 2
my_disp = 4
call MPI_Type_indexed(1, my_n, my_disp, MPI_INTEGER, my_type, ierr)

end subroutine

end program

compile it with no flag: mpif90 bt.F90

With use mpi committed and include 'mpif.h' uncommitted, everything works fine. With use mpi uncommitted and include 'mpif.h' committed, I got error says

bt.F90:23:67:

call MPI_Type_indexed(1, my_n, my_disp, MPI_INTEGER, my_type, ierr)
                                                               1
Error: There is no specific subroutine for the generic 'mpi_type_indexed' at (1)

As indicated in the comments the "problem" that has occurred is that because you have used the module rather than the include file an interface is now in scope, and the compiler can now detect that you are trying to call MPI_Type_indexed with incorrect arguments, as the 2nd and 3rd arguments should be arrays - take a look at https://www.mpi-forum.org/docs/mpi-3.1/mpi31-report/node79.htm#Node79 to see what the interface should be.

Looking at your example it looks as though the original author was assuming that a scalar and a 1 element array are the same thing - this is not the case as the former is rank 0 and the later rank 1. I say this as the first argument specifies how big the arrays should be, and in your case this has the value 1. Thus the 2nd and 3rd arguments should be single element arrays, rather than the scalars you have. The simplest solution, as these arguments are Intent( In ), is to put them in square brackets acting as an array constructor

call MPI_Type_indexed(1, [ my_n ], [ my_disp ], MPI_INTEGER, my_type, ierr)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM