! -*- Mode: F90; -*- 
!
!  (C) 2004 by Argonne National Laboratory.
!      See COPYRIGHT in top-level directory.
!
       MODULE MPI_SIZEOFS
!      This module contains the definitions for MPI_SIZEOF for the
!      predefined, named types in Fortran 90.  This is provided
!      as a separate module to allow MPI_SIZEOF to supply the
!      basic size information even when we do not provide the
!      arbitrary choice types
       IMPLICIT NONE
!
       PUBLIC :: MPI_SIZEOF
       INTERFACE MPI_SIZEOF
           MODULE PROCEDURE MPI_SIZEOF_I, MPI_SIZEOF_R,                &
     &                      MPI_SIZEOF_L, MPI_SIZEOF_CH, MPI_SIZEOF_CX,&
     &           MPI_SIZEOF_IV, MPI_SIZEOF_RV,                         &
     &           MPI_SIZEOF_LV, MPI_SIZEOF_CHV, MPI_SIZEOF_CXV
@REQD@           MODULE PROCEDURE MPI_SIZEOF_D, MPI_SIZEOF_DV
@REQI1@          MODULE PROCEDURE MPI_SIZEOF_I1, MPI_SIZEOF_I1V
@REQI2@          MODULE PROCEDURE MPI_SIZEOF_I2, MPI_SIZEOF_I2V
@REQI8@          MODULE PROCEDURE MPI_SIZEOF_I8, MPI_SIZEOF_I8V
       END INTERFACE ! MPI_SIZEOF
!
       CONTAINS
!
       SUBROUTINE MPI_SIZEOF_I( X, SIZE, IERROR )
       INTEGER X
       INTEGER SIZE, IERROR
       SIZE = @SIZEOF_FC_INTEGER@
       IERROR = 0
       END SUBROUTINE MPI_SIZEOF_I
!
       SUBROUTINE MPI_SIZEOF_R( X, SIZE, IERROR )
       REAL X
       INTEGER SIZE, IERROR
       SIZE = @SIZEOF_FC_REAL@
       IERROR = 0
       END SUBROUTINE MPI_SIZEOF_R
!
! If reals and doubles have been forced to the same size (e.g., with 
! -i8 -r8 to compilers like g95), then the compiler may refuse to 
! allow interfaces that use real and double precision (failing to 
! determine which one is intended)
@REQD@       SUBROUTINE MPI_SIZEOF_D( X, SIZE, IERROR )
@REQD@       DOUBLE PRECISION X
@REQD@       INTEGER SIZE, IERROR
@REQD@       SIZE = @SIZEOF_FC_DOUBLE_PRECISION@
@REQD@       IERROR = 0
@REQD@       END SUBROUTINE MPI_SIZEOF_D
!
       SUBROUTINE MPI_SIZEOF_L( X, SIZE, IERROR )
       LOGICAL X
       INTEGER SIZE, IERROR
       SIZE = @SIZEOF_FC_INTEGER@
       IERROR = 0
       END SUBROUTINE MPI_SIZEOF_L
!
       SUBROUTINE MPI_SIZEOF_CH( X, SIZE, IERROR )
       CHARACTER X
       INTEGER SIZE, IERROR
       SIZE = @SIZEOF_FC_CHARACTER@
       IERROR = 0
       END SUBROUTINE MPI_SIZEOF_CH
!
       SUBROUTINE MPI_SIZEOF_CX( X, SIZE, IERROR )
       COMPLEX X
       INTEGER SIZE, IERROR
       SIZE = 2*@SIZEOF_FC_REAL@
       IERROR = 0
       END SUBROUTINE MPI_SIZEOF_CX
!
       SUBROUTINE MPI_SIZEOF_IV( X, SIZE, IERROR )
       INTEGER X(*)
       INTEGER SIZE, IERROR
       SIZE = @SIZEOF_FC_INTEGER@
       IERROR = 0
       END SUBROUTINE MPI_SIZEOF_IV
!
       SUBROUTINE MPI_SIZEOF_RV( X, SIZE, IERROR )
       REAL X(*)
       INTEGER SIZE, IERROR
       SIZE = @SIZEOF_FC_REAL@
       IERROR = 0
       END SUBROUTINE MPI_SIZEOF_RV
!
! If reals and doubles have been forced to the same size (e.g., with 
! -i8 -r8 to compilers like g95), then the compiler may refuse to 
! allow interfaces that use real and double precision (failing to 
! determine which one is intended)
@REQD@       SUBROUTINE MPI_SIZEOF_DV( X, SIZE, IERROR )
@REQD@       DOUBLE PRECISION X(*)
@REQD@       INTEGER SIZE, IERROR
@REQD@       SIZE = @SIZEOF_FC_DOUBLE_PRECISION@
@REQD@       IERROR = 0
@REQD@       END SUBROUTINE MPI_SIZEOF_DV
!
       SUBROUTINE MPI_SIZEOF_LV( X, SIZE, IERROR )
       LOGICAL X(*)
       INTEGER SIZE, IERROR
       SIZE = @SIZEOF_FC_INTEGER@
       IERROR = 0
       END SUBROUTINE MPI_SIZEOF_LV
!
       SUBROUTINE MPI_SIZEOF_CHV( X, SIZE, IERROR )
       CHARACTER X(*)
       INTEGER SIZE, IERROR
       SIZE = @SIZEOF_FC_CHARACTER@
       IERROR = 0
       END SUBROUTINE MPI_SIZEOF_CHV
!
       SUBROUTINE MPI_SIZEOF_CXV( X, SIZE, IERROR )
       COMPLEX X(*)
       INTEGER SIZE, IERROR
       SIZE = 2*@SIZEOF_FC_REAL@
       IERROR = 0
       END SUBROUTINE MPI_SIZEOF_CXV
!
! Support for the optional Integer*8 type
! Note that we may want to replace this with code that handles
! MPI_OFFSET_KIND or MPI_ADDRESS_KIND integers
@REQI8@       SUBROUTINE MPI_SIZEOF_I8( X, SIZE, IERROR )
@REQI8@       INTEGER*8 X
@REQI8@       INTEGER SIZE, IERROR
@REQI8@       SIZE = 8
@REQI8@       IERROR = 0
@REQI8@       END SUBROUTINE MPI_SIZEOF_I8
@REQI8@       SUBROUTINE MPI_SIZEOF_I8V( X, SIZE, IERROR )
@REQI8@       INTEGER*8 X(*)
@REQI8@       INTEGER SIZE, IERROR
@REQI8@       SIZE = 8
@REQI8@       IERROR = 0
@REQI8@       END SUBROUTINE MPI_SIZEOF_I8V
!
@REQI1@       SUBROUTINE MPI_SIZEOF_I1( X, SIZE, IERROR )
@REQI1@       INTEGER*1 X
@REQI1@       INTEGER SIZE, IERROR
@REQI1@       SIZE = 1
@REQI1@       IERROR = 0
@REQI1@       END SUBROUTINE MPI_SIZEOF_I1
@REQI1@       SUBROUTINE MPI_SIZEOF_I1V( X, SIZE, IERROR )
@REQI1@       INTEGER*1 X(*)
@REQI1@       INTEGER SIZE, IERROR
@REQI1@       SIZE = 1
@REQI1@       IERROR = 0
@REQI1@       END SUBROUTINE MPI_SIZEOF_I1V
!
@REQI2@       SUBROUTINE MPI_SIZEOF_I2( X, SIZE, IERROR )
@REQI2@       INTEGER*2 X
@REQI2@       INTEGER SIZE, IERROR
@REQI2@       SIZE = 2
@REQI2@       IERROR = 0
@REQI2@       END SUBROUTINE MPI_SIZEOF_I2
@REQI2@       SUBROUTINE MPI_SIZEOF_I2V( X, SIZE, IERROR )
@REQI2@       INTEGER*2 X(*)
@REQI2@       INTEGER SIZE, IERROR
@REQI2@       SIZE = 2
@REQI2@       IERROR = 0
@REQI2@       END SUBROUTINE MPI_SIZEOF_I2V
! 
!
! We don't include double complex.  If we did, we'd need to include the
! same hack as for real and double above if the compiler has been forced
! to make them the same size.
       END MODULE MPI_SIZEOFS
