mpich icon indicating copy to clipboard operation
mpich copied to clipboard

Error in `MPI_Comm_fromint` with MPI ABI

Open eschnett opened this issue 4 weeks ago • 5 comments

I have built MPICH 5.0.0b1, enabling the MPI ABI. I am calling MPI_Comm_fromint to convert an integer handle to MPI_Comm. I am using this to implement Fortran bindings for the new ABI.

I am passing the value 257 (corresponding MPI_COMM_WORLD) to MPI_Comm_fromint. This calls ABI_Comm_from_mpi internally, which converts the input from the MPICH ABI to the MPI ABI. According to my understanding this should not happen -- the value 257 should be converted to (MPI_Comm)257. Instead, the value (MPI_Comm)0 is returned.

I think that the function ABI_Comm_from_mpi should be changed from e.g. in == MPI_COMM_NULL to in == ABI_COMM_NULL.

eschnett avatar Dec 10 '25 16:12 eschnett

I am not sure the "integer"-space is supposed to be the same as the MPI object handle-space. If they are the same, then there won't be need for conversion APIs such as MPI_Comm_fromint. Nevertheless, I understand people's intuition that builtin-handles should be "NULL"-conversions. So despite my disagreement, the "fix" is here - https://github.com/pmodels/mpich/pull/7671. It will be in the 5.0.0rc1 release next week.

hzhou avatar Dec 10 '25 20:12 hzhou

Thank you!

If I recall correctly, MPI_Comm_fromint was intended to be equivalent to MPI_Comm_f2c, except that it takes an int argument instead of an MPI_Fint argument. (MPI_Fint is not defined by the MPI ABI.)

There is a need for such conversion functions since MPI_Comm might internally use 64 bits, and there needs to be a mapping to a 32-bit int.

eschnett avatar Dec 10 '25 21:12 eschnett

If I recall correctly, MPI_Comm_fromint was intended to be equivalent to MPI_Comm_f2c, except that it takes an int argument instead of an MPI_Fint argument. (MPI_Fint is not defined by the MPI ABI.)

They are.

You are assuming 267 is a valid Fortran handle for MPI_COMM_WORLD. Why do you need this assumption?

hzhou avatar Dec 10 '25 21:12 hzhou

I am using the new standard MPI ABI. It defines MPI_COMM_WORLD to be (MPI_Comm)257.

eschnett avatar Dec 10 '25 21:12 eschnett

I submit it's a lost battle for me.

hzhou avatar Dec 10 '25 21:12 hzhou

Fixed by https://github.com/pmodels/mpich/pull/7671

hzhou avatar Dec 12 '25 20:12 hzhou