1

I have a code that I run on several different clusters, which all have different combinations of MPI & LAPACK.

This can cause problems. For example I currently use ifort's "-i8" option, which works fine with LAPACK, but now all MPI calls are broken, because it expects integer(4), rather than integer(8).

Is there an elegant & flexible way to adapt the integer type based on the local MPI & LAPACK installation?

Hard coding the types for every specific call seems is just very cumbersome and inflexible.

Stein
  • 3,179
  • 5
  • 27
  • 51
  • 1
    Can't think of a way to do this. But why do you want -i8? It probably ends up breaking the Fortran standard, and as such should be best avoided. – Ian Bush Jun 07 '18 at 10:00
  • -i8 means that all `integer :: a` declarations are 64bit by default rather than the standard 32bit – Stein Jun 07 '18 at 11:08
  • I know exactly what i8 does, and I agree with Valdimir that this may not be a good idea (in my experience it has never been a good idea). So why do you want to use i8? Why must all your integers be 64 bit? – Ian Bush Jun 07 '18 at 11:54

1 Answers1

6

MPI calls do not expect INTEGER(4) nor INTEGER(8), they expect just INTEGER. And, as always, remember what those (4) and (8) actually mean Fortran: integer*4 vs integer(4) vs integer(kind=4)

With -i8 you are changing what INTEGER means, to which kind it corresponds. You can do that, but you have to compile the MPI library with the same settings. The library may or may not be prepared to be compiled that way, but theoretically it should be possible.

You could also try passing integer(int32) instead of integer to MPI. If it is the correct kind which correspond to the default kind of the MPI library, the TKR checks and all other checks should pass OK. But it is not recommended.

To stay strictly within the Fortran standard, when you promote the default integer kind, you should also promote the default real and logical kind.

To stay portable use integers that correspond to the API of the library you use and make sure the library is meant to be used with that particular compiler and with that particular compiler configuration.

Usually, for portability one should not rely on promoting the default kinds but one should use specific kinds which suit the given purpose in the specific part of the code.