Search code examples
fortranmpiintel-fortran

Intel MPI_SIZEOF not working for Fortran complex type


Given the following fortran code:

integer, parameter :: double = kind(1.0d0)

integer :: integerTest
real(double) :: doubleTest
complex(double) :: complexTest
integer :: testSize
integer :: ierr

integerTest = 0
doubleTest = real(0.d0, kind=double)
complexTest = cmplx(0.d0, 0.d0, kind=double)

call MPI_SIZEOF(integerTest, testSize, ierr)
! ...
call MPI_SIZEOF(doubleTest, testSize, ierr)
! ...
call MPI_SIZEOF(complexTest, testSize, ierr)

When compiling with Intel MPI, I get the error:

error #6285: There is no matching specific subroutine for this generic subroutine call. [MPI_SIZEOF]

on the line

 call MPI_SIZEOF(complexTest, testSize, ierr)

This code compiles and executes with no issue using OpenMPI. What is the cause of this error? It seems like it's looking for a specific match for the type of complexTest, but isn't the whole point of MPI_SIZEOF is to work generically with nearly any type?


Solution

  • Probably a bug in the MPI library, they might have forgotten to add this specific function to the module. BTW "nearly any type" is certainly wrong, MPI_SIZEOF is only intended to work for intrinsic types.

    As a workaround you can use

    testSize = storage_size(complexTest) / character_storage_size
    

    (or just / 8)