Stein
Stein

Reputation: 3277

Using the default integer in MPI

If I want to use the 64-bit interface I can specify the -i8 compiler Flag for ifort or -fdefault-integer-8 for gfortran.

In MPI however MPI_INTEGER is defined as a fixed 32 bit integer: https://www.ibm.com/support/knowledgecenter/SSFK3V_2.3.0/com.ibm.cluster.pe.v2r3.pe400.doc/am106_pmd.htm

If I have a simple call such as:

MPI_Bcast(buffer, count, MPI_DATATYPE, root, MPI_COMM_WORLD, ierr)

How can I pass MPI_DATATYPE such that it takes the default value? I.e. MPI_INTEGER8 if -i8 is set or MPI_INTEGER4 if not?

I was considering doing it trough a constant, but I don't know what the type of MPI_DATATYPE is. Is it integer(4) just like MPI_COMM_WORLD is?

Edit: I just realized, that different MPI implementations behave differently:

program main
    use mpi
    integer(4)    :: sz
    integer(4)    :: ierr

    call MPI_Init(ierr)
    call MPI_Type_size(MPI_INTEGER4, sz, ierr)
    write (* ,* ) "4 =  ", sz
    call MPI_Type_size(MPI_INTEGER8, sz, ierr)
    write (* ,* ) "8 =  ", sz
    call MPI_Type_size(MPI_INTEGER, sz, ierr)
    write (* ,* ) "? =  ", sz
    call MPI_Finalize(ierr)


end program main

IntelMPI:

> $ ./bla.x                                                                               
 4 =             4
 8 =             8
 ? =             4

OpenMPI:

> $ ./bla.x                                                                               
 4 =                       4
 8 =                       8
 ? =                       8

Upvotes: 0

Views: 1446

Answers (1)

"In MPI however MPI_INTEGER is defined as a fixed 32 bit integer" It is not. That only is true for that particular MPI library you link to. If you link true MPI answer, link to the official MPI specifications.

If you want to use special flags changing the default behaviour so drastically, you would have to compile the MPI library to know about that flags. The implementation may or may not support such a change, but theoretically it should be possible.

There are tutorials on the web that show such compilation for certain MPI implementations. Use your search engine to find links as http://diracprogram.org/doc/release-12/installation/int64/mpi.html http://linuxtoolkit.blogspot.cz/2013/08/building-openmpi-libraries-for-64-bit.html and others.

If you want to be portable without caring about the default integer the compiler decided to use today and needing to have the MPI library synchronized with that, just use integer variables with some fixed storage size like integer(int32) and integer(int64). Those kind constants are defined in the iso_fortran_env module.

Or do not use/change these ugly flags so that you can be sure that the MPI library has the same settings as the compiler's default.

Upvotes: 2

Related Questions