MPI.jl icon indicating copy to clipboard operation
MPI.jl copied to clipboard

Guidelines/rules for datatypes in constants files

Open sloede opened this issue 3 years ago • 7 comments

I am currently looking through some of the constants files to understand which datatype is used when. For example, it seems like

@const_ref MPI_VARNAME Cint 12345

Is used both for constants defined as enums and as #defines in the corresponding MPI implementation's mpi.h. Why is it OK to map these (ostensibly) different source types to the same Julia type? And why are some other constants defined as

const MPI_MAX_ERROR_STRING = Cint(256)

That is, as proper integer constants, even though in mpi.h they are also just #defines?

Also, I noticed that sometimes C types are translated to Julia C types and sometimes to regular Julia types, and for some there does not seem to be a 1-to-1 correspondence used. For example, for OpenMPI's there is https://github.com/JuliaParallel/MPI.jl/blob/e4479cfe16f1fdbbdab7423eca03c98764b0c671/src/consts/openmpi.jl#L18-L21

While in the OpenMPI headers on HLRS' Hawk I find

  • MPI_Aint to be of ptrdiff_t type, which is implementation defined (Q: isn't that a potential issue that it can vary?)
  • MPI_Fint to be of int type (Q: why use Int32 and not Cint?)
  • MPI_Count and MPI_Offset to be of long long type (Q: why not use Clong then?)

Right afterwards in the definition of MPI_Status, the C types are used again: https://github.com/JuliaParallel/MPI.jl/blob/e4479cfe16f1fdbbdab7423eca03c98764b0c671/src/consts/openmpi.jl#L24-L30

Maybe it is documented somewhere but I was not able to find it in the docs. Any help understanding how to properly understand (and possibly create) such a constants file would be appreciated!

sloede avatar Apr 23 '22 06:04 sloede

As a follow-up questions, was it intentional to remove all typed pointers for https://github.com/JuliaParallel/MPI.jl/blob/e4479cfe16f1fdbbdab7423eca03c98764b0c671/src/consts/openmpi.jl#L245-L248

While in mpi.h the first two should be pointers to int/Cint (ref)?

sloede avatar Apr 23 '22 06:04 sloede

As a follow-up questions, was it intentional to remove all typed pointers for

This was fixed by #598

simonbyrne avatar May 29 '22 17:05 simonbyrne

  • MPI_Aint to be of ptrdiff_t type, which is implementation defined (Q: isn't that a potential issue that it can vary?)

    • MPI_Fint to be of int type (Q: why use Int32 and not Cint?)

    • MPI_Count and MPI_Offset to be of long long type (Q: why not use Clong then?)

Mostly it was trial and error on my part: it would probably make sense to use the C aliases if that is how they're defined in the headers.

simonbyrne avatar May 29 '22 17:05 simonbyrne

  • MPI_Aint to be of ptrdiff_t type, which is implementation defined (Q: isn't that a potential issue that it can vary?)

    • MPI_Fint to be of int type (Q: why use Int32 and not Cint?)
    • MPI_Count and MPI_Offset to be of long long type (Q: why not use Clong then?)

Mostly it was trial and error on my part: it would probably make sense to use the C aliases if that is how they're defined in the headers.

I added a note regarding this to the docs in ff29239.

sloede avatar May 29 '22 17:05 sloede

Would you mind making a PR on the existing const files?

simonbyrne avatar May 29 '22 18:05 simonbyrne

Would you mind making a PR on the existing const files?

What do you mean exactly? One that fixes the types I've pointed out above?

sloede avatar May 29 '22 18:05 sloede

What do you mean exactly? One that fixes the types I've pointed out above?

yes

simonbyrne avatar May 29 '22 18:05 simonbyrne