C
C  This file is part of MUMPS 5.1.1, released
C  on Mon Mar 20 14:34:33 UTC 2017
C
C
C  Copyright 1991-2017 CERFACS, CNRS, ENS Lyon, INP Toulouse, Inria,
C  University of Bordeaux.
C
C  This version of MUMPS is provided to you free of charge. It is
C  released under the CeCILL-C license:
C  http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html
C
      MODULE MUMPS_ANA_ORD_WRAPPERS
      IMPLICIT NONE
       CONTAINS
#if defined(metis) || defined(parmetis) || defined(metis4) || defined(parmetis3)
#if defined(metis4) || defined(parmetis3)
      SUBROUTINE MUMPS_METIS_NODEWND_MIXEDto32( NCMP, IPE8, IW, FRERE,
     & NUMFLAG,
     & OPTIONS_METIS, LOPTIONS_METIS, IKEEP2, IKEEP1, INFO, 
     & LP, LPOK )
      IMPLICIT NONE
      INTEGER    :: INFO(2), LOPTIONS_METIS
      INTEGER    :: NCMP, NUMFLAG, IKEEP1(*), IKEEP2(*), FRERE(*)
      INTEGER    :: OPTIONS_METIS(LOPTIONS_METIS), IW(*)
      INTEGER, INTENT(IN) :: LP
      LOGICAL, INTENT(IN) :: LPOK
      INTEGER(8) :: IPE8(*)
      INTEGER,ALLOCATABLE, DIMENSION(:) :: IPE
      INTEGER :: allocok
      IF (IPE8(NCMP+1) .GE. int(huge(IW),8)) THEN
        INFO(1) = -51
        CALL MUMPS_SET_IERROR(
     &   IPE8(NCMP+1), INFO(2))
        RETURN
      ENDIF
      ALLOCATE(IPE(NCMP+1), stat=allocok)
      IF (allocok > 0) THEN
        INFO(1)=-7
        INFO(2)=NCMP+1
        IF (LPOK) WRITE(LP,'(A)') 
     &    "ERROR memory allocation in METIS_NODEWND_MIXEDto32"
        RETURN
      ENDIF
      CALL MUMPS_COPY_INT_64TO32(IPE8, NCMP+1, IPE)
      CALL METIS_NODEWND(NCMP, IPE, IW,FRERE,
     &           NUMFLAG, OPTIONS_METIS,
     &           IKEEP2, IKEEP1 )
      CALL MUMPS_COPY_INT_32TO64(IPE, NCMP+1, IPE8)
      RETURN
      END SUBROUTINE MUMPS_METIS_NODEWND_MIXEDto32
      SUBROUTINE MUMPS_METIS_NODEND_MIXEDto32( NCMP, IPE8, IW, NUMFLAG,
     & OPTIONS_METIS, LOPTIONS_METIS, IKEEP2, IKEEP1, INFO, 
     & LP, LPOK)
      IMPLICIT NONE
      INTEGER    :: INFO(2), LOPTIONS_METIS
      INTEGER    :: NCMP, NUMFLAG, IKEEP1(*), IKEEP2(*), IW(*)
      INTEGER    :: OPTIONS_METIS(LOPTIONS_METIS)
      INTEGER(8) :: IPE8(*)
      INTEGER, INTENT(IN) :: LP
      LOGICAL, INTENT(IN) :: LPOK
      INTEGER,ALLOCATABLE, DIMENSION(:) :: IPE
      INTEGER :: allocok
      IF (IPE8(NCMP+1) .GE. int(huge(IW),8)) THEN
        INFO(1) = -51
        CALL MUMPS_SET_IERROR(
     &   IPE8(NCMP+1), INFO(2))
        RETURN
      ENDIF
      ALLOCATE(IPE(NCMP+1), stat=allocok)
      IF (allocok > 0) THEN
        INFO(1)=-7
        INFO(2)=NCMP+1
        IF (LPOK) WRITE(LP,'(A)') 
     &    "ERROR memory allocation in METIS_NODEND_MIXEDto32"
        RETURN
      ENDIF
      CALL MUMPS_COPY_INT_64TO32(IPE8, NCMP+1, IPE)
      CALL METIS_NODEND(NCMP, IPE, IW,
     &           NUMFLAG, OPTIONS_METIS,
     &           IKEEP2, IKEEP1 )
      CALL MUMPS_COPY_INT_32TO64(IPE, NCMP+1, IPE8)
      DEALLOCATE(IPE)
      RETURN
      END SUBROUTINE MUMPS_METIS_NODEND_MIXEDto32
#else
      SUBROUTINE MUMPS_METIS_NODEND_MIXEDto32( NCMP, IPE8, IW, FRERE,
     & OPTIONS_METIS, LOPTIONS_METIS, IKEEP2, IKEEP1, INFO, 
     & LP, LPOK )
      IMPLICIT NONE
      INTEGER    :: INFO(2), LOPTIONS_METIS
      INTEGER    :: NCMP, IKEEP1(*), IKEEP2(*), FRERE(*), IW(*)
      INTEGER    :: OPTIONS_METIS(LOPTIONS_METIS)
      INTEGER(8) :: IPE8(*)
      INTEGER, INTENT(IN) :: LP
      LOGICAL, INTENT(IN) :: LPOK
      INTEGER,ALLOCATABLE, DIMENSION(:) :: IPE
      INTEGER :: allocok
      IF (IPE8(NCMP+1) .GE. int(huge(IW),8)) THEN
        INFO(1) = -51
        CALL MUMPS_SET_IERROR(
     &   IPE8(NCMP+1), INFO(2))
        RETURN
      ENDIF
      ALLOCATE(IPE(NCMP+1), stat=allocok)
      IF (allocok > 0) THEN
        INFO(1)=-7
        INFO(2)=NCMP+1
        IF (LPOK) WRITE(LP,'(A)') 
     &    "ERROR memory allocation in METIS_NODEND_MIXEDto32"
        RETURN
      ENDIF
      CALL MUMPS_COPY_INT_64TO32(IPE8, NCMP+1, IPE)
      CALL METIS_NODEND( NCMP, IPE, IW, FRERE,
     & OPTIONS_METIS, IKEEP2, IKEEP1)
      CALL MUMPS_COPY_INT_32TO64(IPE, NCMP+1, IPE8)
      DEALLOCATE(IPE)
      RETURN
      END SUBROUTINE MUMPS_METIS_NODEND_MIXEDto32
#endif
#endif
#if defined(metis) || defined(parmetis) || defined(metis4) || defined(parmetis3)
#if defined(metis4) || defined(parmetis3)
      SUBROUTINE MUMPS_METIS_NODEWND_MIXEDto64( NCMP, IPE8, IW, FRERE,
     & NUMFLAG,
     & OPTIONS_METIS, LOPTIONS_METIS, IKEEP2, IKEEP1, INFO, 
     & LP, LPOK, KEEP10 )
      IMPLICIT NONE
      INTEGER    :: INFO(2), LOPTIONS_METIS
      INTEGER    :: NCMP, NUMFLAG, IKEEP1(*), IKEEP2(*), FRERE(*)
      INTEGER    :: OPTIONS_METIS(LOPTIONS_METIS), IW(*)
      INTEGER(8) :: IPE8(*)
      INTEGER, INTENT(IN) :: LP, KEEP10
      LOGICAL, INTENT(IN) :: LPOK
      INTEGER(8), ALLOCATABLE, DIMENSION(:) :: IW8, FRERE8,
     &                                         IKEEP18, IKEEP28
      INTEGER :: allocok
      IF (KEEP10.EQ.1) THEN
       CALL METIS_NODEWND(NCMP, IPE8, IW ,FRERE,
     &           NUMFLAG, OPTIONS_METIS,
     &           IKEEP2, IKEEP1 )
      ELSE
       ALLOCATE(IW8(IPE8(NCMP+1)-1_8), FRERE8(NCMP),
     &         IKEEP18(NCMP), IKEEP28(NCMP), stat=allocok)
       IF (allocok > 0) THEN
        INFO(1)=-7
        CALL MUMPS_SET_IERROR(
     &   int(KEEP10,8)* (
     &   IPE8(NCMP+1)-1_8+3_8*int(NCMP,8)
     &                  )
     &             , INFO(2)
     &                      )
        IF (LPOK) WRITE(LP,'(A)') 
     &    "ERROR memory allocation in METIS_NODEWND_MIXEDto64"
        RETURN
       ENDIF
       CALL MUMPS_COPY_INT_32TO64_64C(IW   , IPE8(NCMP+1)-1_8, IW8   )
       CALL MUMPS_COPY_INT_32TO64    (FRERE, NCMP        , FRERE8)
       CALL METIS_NODEWND(NCMP, IPE8, IW8,FRERE8,
     &           NUMFLAG, OPTIONS_METIS,
     &           IKEEP2, IKEEP1 )
       CALL MUMPS_COPY_INT_64TO32(IKEEP18, NCMP, IKEEP1)
       CALL MUMPS_COPY_INT_64TO32(IKEEP28, NCMP, IKEEP2)
       DEALLOCATE(IW8, FRERE8, IKEEP18, IKEEP28)
      ENDIF
      RETURN
      END SUBROUTINE MUMPS_METIS_NODEWND_MIXEDto64
      SUBROUTINE MUMPS_METIS_NODEND_MIXEDto64( NCMP, IPE8, IW, NUMFLAG,
     & OPTIONS_METIS, LOPTIONS_METIS, IKEEP2, IKEEP1, INFO,
     & LP, LPOK, KEEP10 )
      IMPLICIT NONE
      INTEGER    :: INFO(2), LOPTIONS_METIS
      INTEGER    :: NCMP, NUMFLAG, IKEEP1(*), IKEEP2(*), IW(*)
      INTEGER    :: OPTIONS_METIS(LOPTIONS_METIS)
      INTEGER(8) :: IPE8(*)
      INTEGER, INTENT(IN) :: LP, KEEP10
      LOGICAL, INTENT(IN) :: LPOK
      INTEGER(8), ALLOCATABLE, DIMENSION(:) :: IW8,
     &                                         IKEEP18, IKEEP28
      INTEGER :: allocok
      IF (KEEP10.EQ.1) THEN
       CALL METIS_NODEND(NCMP, IPE8, IW,
     &           NUMFLAG, OPTIONS_METIS,
     &           IKEEP2, IKEEP1 )
      ELSE
       ALLOCATE(IW8(IPE8(NCMP+1)-1_8),
     &         IKEEP18(NCMP), IKEEP28(NCMP), stat=allocok)
       IF (allocok > 0) THEN
        INFO(1)=-7
        CALL MUMPS_SET_IERROR(  int(KEEP10,8)*
     &        ( IPE8(NCMP+1)-1_8+2_8*int(NCMP,8) )
     &        , INFO(2) )
        IF (LPOK) WRITE(LP,'(A)') 
     &    "ERROR memory allocation in METIS_METIS_NODEND_MIXEDto64"
        RETURN
       ENDIF
       CALL MUMPS_COPY_INT_32TO64_64C(IW   , IPE8(NCMP+1)-1_8, IW8 )
       CALL METIS_NODEND(NCMP, IPE8, IW8,
     &           NUMFLAG, OPTIONS_METIS,
     &           IKEEP28, IKEEP18 )
       CALL MUMPS_COPY_INT_64TO32(IKEEP18, NCMP, IKEEP1)
       CALL MUMPS_COPY_INT_64TO32(IKEEP28, NCMP, IKEEP2)
       DEALLOCATE(IW8, IKEEP18, IKEEP28)
      ENDIF
      RETURN
      END SUBROUTINE MUMPS_METIS_NODEND_MIXEDto64
#else
      SUBROUTINE MUMPS_METIS_NODEND_MIXEDto64( NCMP, IPE8, IW, FRERE,
     & OPTIONS_METIS, LOPTIONS_METIS, IKEEP2, IKEEP1, INFO,
     & LP, LPOK, KEEP10 )
      IMPLICIT NONE
      INTEGER    :: INFO(2)
      INTEGER    :: LOPTIONS_METIS
      INTEGER    :: NCMP, IKEEP1(*), IKEEP2(*), FRERE(*), IW(*)
      INTEGER    :: OPTIONS_METIS(LOPTIONS_METIS)
      INTEGER(8) :: IPE8(*)
      INTEGER, INTENT(IN) :: LP, KEEP10
      LOGICAL, INTENT(IN) :: LPOK
      INTEGER(8), ALLOCATABLE, DIMENSION(:) :: IW8, FRERE8,
     &                                         IKEEP18, IKEEP28,
     &                                         OPTIONS_METIS8
      INTEGER :: allocok
      IF (KEEP10.EQ.1) THEN
       CALL METIS_NODEND( NCMP, IPE8, IW, FRERE,
     &      OPTIONS_METIS, IKEEP2, IKEEP1 )
      ELSE
       ALLOCATE(IW8(IPE8(NCMP+1)-1_8), FRERE8(NCMP),
     &         IKEEP18(NCMP), IKEEP28(NCMP),
     &         OPTIONS_METIS8(LOPTIONS_METIS), stat=allocok)
       IF (allocok > 0) THEN
        INFO(1)=-7
        CALL MUMPS_SET_IERROR( 
     &       int(KEEP10,8)* (
     &           IPE8(NCMP+1)-1_8+3_8*int(NCMP,8)+int(LOPTIONS_METIS,8)
     &                        ) 
     &            , INFO(2))
        IF (LPOK) WRITE(LP,'(A)') 
     &    "ERROR memory allocation in METIS_NODEND_MIXEDto64"
        RETURN
       ENDIF
       CALL MUMPS_COPY_INT_32TO64_64C(IW   , IPE8(NCMP+1)-1_8, IW8   )
       CALL MUMPS_COPY_INT_32TO64    (FRERE, NCMP        , FRERE8)
       CALL MUMPS_COPY_INT_32TO64    (OPTIONS_METIS, LOPTIONS_METIS,
     &                               OPTIONS_METIS8)
       CALL METIS_NODEND( int(NCMP,8), IPE8, IW8, FRERE8,
     & OPTIONS_METIS8, IKEEP28, IKEEP18 )
       CALL MUMPS_COPY_INT_64TO32(IKEEP18, NCMP, IKEEP1)
       CALL MUMPS_COPY_INT_64TO32(IKEEP28, NCMP, IKEEP2)
       DEALLOCATE(IW8, FRERE8, IKEEP18, IKEEP28)
      ENDIF
      RETURN
      END SUBROUTINE MUMPS_METIS_NODEND_MIXEDto64
#endif
#endif
#if defined(scotch) || defined(ptscotch)
      SUBROUTINE MUMPS_SCOTCH_MIXEDto32(NCMP, LIW8, IPE8, PARENT, IWFR8,
     &           PTRAR, IW, IWL1, IKEEP1,
     &           IKEEP2, NCMPA, INFO, LP, LPOK)
      IMPLICIT NONE
      INTEGER,    INTENT(IN)    :: NCMP
      INTEGER(8), INTENT(IN)    :: LIW8
      INTEGER,    INTENT(OUT)   :: NCMPA
      INTEGER(8), INTENT(INOUT) :: IPE8(NCMP+1)
      INTEGER,    INTENT(OUT)   :: PARENT(NCMP)
      INTEGER(8), INTENT(IN)    :: IWFR8
      INTEGER                   :: PTRAR(NCMP)
      INTEGER                   :: IW(LIW8)
      INTEGER                   :: IWL1(NCMP)
      INTEGER,    INTENT(OUT)   :: IKEEP1(NCMP)
      INTEGER,    INTENT(OUT)   :: IKEEP2(NCMP)
      INTEGER,    INTENT(INOUT) :: INFO(2)
      INTEGER,    INTENT(IN)    :: LP
      LOGICAL,    INTENT(IN)    :: LPOK
      INTEGER, DIMENSION(:), ALLOCATABLE :: IPE
      INTEGER :: LIW8_EFF
      INTEGER :: allocok
      IF (IWFR8 .GE. int(huge(IW),8)) THEN
        INFO(1) = -51
        CALL MUMPS_SET_IERROR(IPE8(NCMP+1), INFO(2))
        RETURN
      ENDIF
      ALLOCATE(IPE(NCMP+1), stat=allocok)
      IF (allocok > 0) THEN
        IF (LPOK) WRITE(LP,'(A)') 
     &    "ERROR memory allocation in MUMPS_SCOTCH_MIXEDto32"
        INFO(1) = -7
        INFO(2) = NCMP+1
        RETURN
      ENDIF
      CALL MUMPS_COPY_INT_64TO32(IPE8,NCMP+1,IPE)
      CALL MUMPS_SCOTCH( NCMP, int(LIW8), IPE, int(IWFR8),
     &                   PTRAR, IW, IWL1, IKEEP1,
     &                   IKEEP2, NCMPA )
      PARENT(1:NCMP)=IPE(1:NCMP)
      DEALLOCATE(IPE)
      RETURN
      END SUBROUTINE MUMPS_SCOTCH_MIXEDto32
      SUBROUTINE MUMPS_SCOTCH_MIXEDto64(
     &           NCMP, LIW8, IPE8, PARENT, IWFR8,
     &           PTRAR, IW, IWL1, IKEEP1,
     &           IKEEP2, NCMPA, INFO, LP, LPOK, KEEP10)
      IMPLICIT NONE
      INTEGER,    INTENT(IN)    :: NCMP
      INTEGER(8), INTENT(IN)    :: LIW8
      INTEGER,    INTENT(OUT)   :: NCMPA
      INTEGER(8), INTENT(INOUT) :: IPE8(NCMP+1)
      INTEGER,    INTENT(OUT)   :: PARENT(NCMP)
      INTEGER(8), INTENT(IN)    :: IWFR8
      INTEGER                   :: PTRAR(NCMP)
      INTEGER                   :: IW(LIW8)
      INTEGER                   :: IWL1(NCMP)
      INTEGER,    INTENT(OUT)   :: IKEEP1(NCMP)
      INTEGER,    INTENT(OUT)   :: IKEEP2(NCMP)
      INTEGER,    INTENT(INOUT) :: INFO(2)
      INTEGER,    INTENT(IN)    :: LP
      LOGICAL,    INTENT(IN)    :: LPOK
      INTEGER,    INTENT(IN)    :: KEEP10
      INTEGER(8), DIMENSION(:), ALLOCATABLE :: 
     &                     PTRAR8, IW8, IWL18, IKEEP18,
     &                     IKEEP28
      INTEGER :: allocok
      IF (KEEP10.EQ.1) THEN
        CALL MUMPS_SCOTCH_64( NCMP, LIW8,
     &                        IPE8, 
     &                        IWFR8,
     &                        PTRAR, IW, IWL1, IKEEP1,
     &                        IKEEP2, NCMPA )
        PARENT(1:NCMP) = int(IPE8(1:NCMP))
      ELSE
        ALLOCATE( IW8(LIW8),
     &  PTRAR8(NCMP), IWL18(NCMP), IKEEP18(NCMP), IKEEP28(NCMP),
     &  stat=allocok )
        IF (allocok > 0) THEN
          IF (LPOK) WRITE(LP,*)
     &    "ERROR memory allocation in MUMPS_SCOTCH_MIXEDto64"
          INFO(1) = -7
          CALL MUMPS_SET_IERROR( int(KEEP10,8) *
     &                            ( int(NCMP,8)*4_8+LIW8 )
     &                        , INFO(2) )
         RETURN
        ENDIF
        CALL MUMPS_COPY_INT_32TO64_64C(IW,LIW8,IW8)
        CALL MUMPS_COPY_INT_32TO64(PTRAR,NCMP,PTRAR8)
        CALL MUMPS_SCOTCH_64( int(NCMP,8), LIW8,      
     &                        IPE8,                   
     &                        IWFR8,                  
     &                        PTRAR8, IW8, IWL18, IKEEP1, 
     &                        IKEEP2, NCMPA )
        IF (NCMPA .LT. 0) THEN
           IF (LPOK) WRITE(LP,*) 
     &               ' Error on output from SCOTCH, NCMPA=', NCMPA
           INFO( 1 ) = -9999
           INFO( 2 ) = 3
           GOTO 500 
        ENDIF
        CALL MUMPS_COPY_INT_64TO32(IWL18,NCMP,IWL1)
        CALL MUMPS_COPY_INT_64TO32(IKEEP18,NCMP,IKEEP1)
        CALL MUMPS_COPY_INT_64TO32(IKEEP28,NCMP,IKEEP2)
        CALL MUMPS_COPY_INT_64TO32(IPE8,NCMP,PARENT)
 500    CONTINUE
        DEALLOCATE(IW8, PTRAR8, IWL18, IKEEP18, IKEEP28)
      ENDIF
      RETURN
      END SUBROUTINE MUMPS_SCOTCH_MIXEDto64
#endif
#if defined (scotch) || defined (ptscotch)
      SUBROUTINE MUMPS_SCOTCH_KWAY_MIXEDto32(NHALO, HALOEDGENBR,
     &     IPTRHALO, JCNHALO,
     &     NBGROUPS, PARTS, LP, LPOK, KEEP10,
     &               IFLAG, IERROR)
      IMPLICIT NONE
      include 'scotchf.h'
      INTEGER(8) :: HALOEDGENBR
      INTEGER    :: NHALO, NBGROUPS
      INTEGER    :: JCNHALO(HALOEDGENBR), PARTS(NHALO)
      INTEGER(8) :: IPTRHALO(NHALO+1)
      INTEGER, INTENT(IN)    :: LP, KEEP10
      LOGICAL, INTENT(IN)    :: LPOK
      INTEGER, INTENT(INOUT) :: IFLAG, IERROR
      DOUBLE PRECISION :: GRAFDAT(SCOTCH_GRAPHDIM)
      DOUBLE PRECISION :: STRADAT(SCOTCH_STRATDIM)
      INTEGER :: BASEVAL, IERR, EDGENBR
      INTEGER, ALLOCATABLE    :: IPTRHALO_I4(:)
      INTEGER :: allocok
      IF (IPTRHALO(size(IPTRHALO)) .GE. int(huge(LP),8)) THEN
        IFLAG   = -51
        CALL MUMPS_SET_IERROR( IPTRHALO (size(IPTRHALO)), 
     &                         IERROR )
        RETURN
      ENDIF
      ALLOCATE(IPTRHALO_I4(size(IPTRHALO)), stat=allocok)
      IF (allocok > 0) THEN
        IFLAG   = -7
        IERROR  = size(IPTRHALO)
        IF (LPOK) WRITE(LP,'(A)') 
     &    "ERROR memory allocation in MUMPS_SCOTCH_KWAY_MIXEDto32"
        RETURN
      END IF
      CALL MUMPS_COPY_INT_64TO32(IPTRHALO,
     &     size(IPTRHALO), IPTRHALO_I4)
      BASEVAL = 1
      EDGENBR = IPTRHALO_I4(NHALO+1)
      CALL SCOTCHFGRAPHBUILD(GRAFDAT(1), BASEVAL, NHALO,
     &     IPTRHALO_I4(1), IPTRHALO_I4(2), IPTRHALO_I4(1),
     &     IPTRHALO_I4(1), EDGENBR, JCNHALO(1), JCNHALO(1), IERR)
      CALL SCOTCHFSTRATINIT(STRADAT, IERR)
      CALL SCOTCHFGRAPHPART(GRAFDAT(1), NBGROUPS, STRADAT(1),
     &     PARTS(1), IERR)
      CALL SCOTCHFSTRATEXIT(STRADAT)
      CALL SCOTCHFGRAPHEXIT(GRAFDAT)
      PARTS(1:NHALO) = PARTS(1:NHALO)+1
      DEALLOCATE(IPTRHALO_I4)
      RETURN
      END SUBROUTINE MUMPS_SCOTCH_KWAY_MIXEDto32
      SUBROUTINE MUMPS_SCOTCH_KWAY_MIXEDto64(NHALO, HALOEDGENBR,
     &     IPTRHALO, JCNHALO,
     &     NBGROUPS, PARTS, LP, LPOK, KEEP10,
     &               IFLAG, IERROR)
      IMPLICIT NONE
      include 'scotchf.h'
      INTEGER(8) :: HALOEDGENBR
      INTEGER    :: NHALO, NBGROUPS
      INTEGER    :: JCNHALO(HALOEDGENBR), PARTS(NHALO)
      INTEGER(8) :: IPTRHALO(NHALO+1)
      INTEGER, INTENT(IN)    :: LP, KEEP10
      LOGICAL, INTENT(IN)    :: LPOK
      INTEGER, INTENT(INOUT) :: IFLAG, IERROR
      DOUBLE PRECISION :: GRAFDAT(SCOTCH_GRAPHDIM)
      DOUBLE PRECISION :: STRADAT(SCOTCH_STRATDIM)
      INTEGER :: IERR
      INTEGER(8), ALLOCATABLE :: JCNHALO_I8(:), PARTS_I8(:)
      INTEGER(8) :: NHALO_I8, NBGROUPS_I8, EDGENBR_I8,
     &     BASEVAL_I8
      INTEGER :: allocok
      ALLOCATE(JCNHALO_I8(IPTRHALO(NHALO+1)-1_8),
     &   PARTS_I8(size(PARTS)),  stat=allocok)
      IF (allocok > 0) THEN
        IFLAG  =-7
        CALL MUMPS_SET_IERROR(
     &   int(KEEP10,8)* (IPTRHALO(NHALO+1)-1_8
     &  +int(size(PARTS),8)),
     &   IERROR)
        IF (LPOK) WRITE(LP,'(A)') 
     &    "ERROR memory allocation in MUMPS_SCOTCH_KWAY_MIXEDto64 "
       ENDIF
      CALL MUMPS_COPY_INT_32TO64_64C(JCNHALO,
     &     IPTRHALO(NHALO+1)-1, JCNHALO_I8)
      NHALO_I8    = int(NHALO,8)
      NBGROUPS_I8 = int(NBGROUPS,8)
      BASEVAL_I8  = 1_8
      EDGENBR_I8  = IPTRHALO(NHALO+1)
      CALL SCOTCHFGRAPHBUILD(GRAFDAT(1), BASEVAL_I8, NHALO_I8,
     &     IPTRHALO(1), IPTRHALO(2), IPTRHALO(1),
     &     IPTRHALO(1), EDGENBR_I8, JCNHALO_I8(1), JCNHALO_I8(1), IERR)
      CALL SCOTCHFSTRATINIT(STRADAT, IERR)
      CALL SCOTCHFGRAPHPART(GRAFDAT(1), NBGROUPS_I8, STRADAT(1),
     &     PARTS_I8(1), IERR)
      CALL SCOTCHFSTRATEXIT(STRADAT)
      CALL SCOTCHFGRAPHEXIT(GRAFDAT)
      CALL MUMPS_COPY_INT_64TO32(PARTS_I8,
     &     size(PARTS), PARTS)
      DEALLOCATE(JCNHALO_I8, PARTS_I8)      
      PARTS(1:NHALO) = PARTS(1:NHALO)+1
      RETURN
      END SUBROUTINE MUMPS_SCOTCH_KWAY_MIXEDto64
#endif
#if defined (metis) || defined (parmetis) || defined (metis4) || defined (parmetis3)
      SUBROUTINE MUMPS_METIS_KWAY_MIXEDto32(NHALO, HALOEDGENBR,
     &               IPTRHALO,
     &               JCNHALO, NBGROUPS, PARTS, LP, LPOK, KEEP10,
     &               IFLAG, IERROR)
      IMPLICIT NONE
      INTEGER(8) :: HALOEDGENBR
      INTEGER    :: NHALO, NBGROUPS
      INTEGER    :: JCNHALO(HALOEDGENBR), PARTS(NHALO)
      INTEGER(8) :: IPTRHALO(NHALO+1)
      INTEGER, INTENT(IN)    :: LP, KEEP10
      LOGICAL, INTENT(IN)    :: LPOK
      INTEGER, INTENT(INOUT) :: IFLAG, IERROR
      INTEGER, ALLOCATABLE    :: IPTRHALO_I4(:)
      INTEGER :: allocok
      IF (IPTRHALO(size(IPTRHALO)) .GE. int(huge(LP),8)) THEN
        IFLAG   = -51
        CALL MUMPS_SET_IERROR( IPTRHALO (size(IPTRHALO)), 
     &   IERROR)
        RETURN
      ENDIF
      ALLOCATE(IPTRHALO_I4(size(IPTRHALO)), stat=allocok)
      IF (allocok > 0) THEN
        IFLAG   = -7
        IERROR  = size(IPTRHALO)
        IF (LPOK) WRITE(LP,'(A)') 
     &    "ERROR memory allocation in MUMPS_METIS_KWAY_MIXEDto32"
        RETURN
      END IF
      CALL MUMPS_COPY_INT_64TO32(IPTRHALO,
     &     size(IPTRHALO), IPTRHALO_I4)
      CALL MUMPS_METIS_KWAY(NHALO, IPTRHALO_I4(1),
     &               JCNHALO(1), NBGROUPS, PARTS(1))
      DEALLOCATE(IPTRHALO_I4)
      RETURN
      END SUBROUTINE MUMPS_METIS_KWAY_MIXEDto32
      SUBROUTINE MUMPS_METIS_KWAY_MIXEDto64(NHALO, HALOEDGENBR,
     &               IPTRHALO,
     &               JCNHALO, NBGROUPS, PARTS, LP, LPOK, KEEP10,
     &               IFLAG, IERROR)
      IMPLICIT NONE
      INTEGER(8) :: HALOEDGENBR
      INTEGER    :: NHALO, NBGROUPS
      INTEGER    :: JCNHALO(HALOEDGENBR), PARTS(NHALO)
      INTEGER(8) :: IPTRHALO(NHALO+1)
      INTEGER, INTENT(IN)    :: LP, KEEP10
      LOGICAL, INTENT(IN)    :: LPOK
      INTEGER, INTENT(INOUT) :: IFLAG, IERROR
      INTEGER(8), ALLOCATABLE, DIMENSION(:) :: JCNHALO_I8, PARTS_I8
      INTEGER(8) :: NHALO_I8, NBGROUPS_I8
      INTEGER :: allocok
      ALLOCATE(JCNHALO_I8(IPTRHALO(NHALO+1)-1_8),
     &         PARTS_I8(size(PARTS)), stat=allocok)
      IF (allocok > 0) THEN
        IFLAG  = -7
        CALL MUMPS_SET_IERROR(
     &   int(KEEP10,8)* (IPTRHALO(NHALO+1)-1_8+int(size(PARTS),8)),
     &   IERROR)
        IF (LPOK) WRITE(LP,'(A)') 
     &    "ERROR memory allocation in MUMPS_METIS_KWAY_MIXEDto64 "
       ENDIF
      CALL MUMPS_COPY_INT_32TO64_64C(JCNHALO,
     &     IPTRHALO(NHALO+1)-1, JCNHALO_I8)
      NHALO_I8    = int(NHALO,8)
      NBGROUPS_I8 = int(NBGROUPS,8)
      CALL MUMPS_METIS_KWAY_64(NHALO_I8, IPTRHALO(1),
     &               JCNHALO_I8(1), NBGROUPS_I8, PARTS_I8(1))
      CALL MUMPS_COPY_INT_64TO32(PARTS_I8,
     &     size(PARTS), PARTS)
      DEALLOCATE(JCNHALO_I8, PARTS_I8)
      RETURN
      END SUBROUTINE MUMPS_METIS_KWAY_MIXEDto64
#endif      
#if defined(pord)
      SUBROUTINE MUMPS_PORDF_MIXEDto32( NVTX, NEDGES8, XADJ8, IW,
     &                                  NV, NCMPA, PARENT,
     &                                  INFO, LP, LPOK, KEEP10 )
      IMPLICIT NONE
      INTEGER, INTENT(IN)     :: LP
      LOGICAL, INTENT(IN)     :: LPOK
      INTEGER, INTENT(INOUT)  :: INFO(2)
      INTEGER, INTENT(IN)     :: NVTX
      INTEGER, INTENT(OUT)    :: NCMPA
      INTEGER(8), INTENT(IN)  :: NEDGES8
      INTEGER(8)              :: XADJ8(NVTX+1)
      INTEGER, INTENT(OUT)    :: NV(NVTX)
      INTEGER                 :: IW(NEDGES8)
      INTEGER, INTENT(OUT)    :: PARENT(NVTX)
      INTEGER, INTENT(IN)     :: KEEP10
      INTEGER, DIMENSION(:), ALLOCATABLE :: XADJ
      INTEGER :: I, allocok
      IF (NEDGES8.GT. int(huge(IW),8)) THEN
        INFO(1) = -51
        CALL MUMPS_SET_IERROR(NEDGES8,INFO(2))
        RETURN
      ENDIF
      ALLOCATE(XADJ(NVTX+1), stat=allocok)
      IF (allocok > 0) THEN
        INFO(1)=-7
        INFO(2)=NVTX+1
        IF (LPOK) WRITE(LP,'(A)') 
     &    "ERROR memory allocation in MUMPS_PORD_MIXEDto32"
        RETURN
      ENDIF
      CALL MUMPS_COPY_INT_64TO32(XADJ8, NVTX+1, XADJ)
      CALL MUMPS_PORDF( NVTX, int(NEDGES8), XADJ, IW,
     &                                    NV, NCMPA )
      DO I= 1, NVTX
        PARENT(I) = XADJ(I)
      ENDDO
      DEALLOCATE(XADJ)
      RETURN
      END SUBROUTINE MUMPS_PORDF_MIXEDto32
      SUBROUTINE MUMPS_PORDF_MIXEDto64( NVTX, NEDGES8, XADJ8, IW,
     &                                  NV, NCMPA, PARENT,
     &                                  INFO, LP, LPOK, KEEP10 )
      IMPLICIT NONE
      INTEGER, INTENT(IN)     :: LP
      LOGICAL, INTENT(IN)     :: LPOK
      INTEGER, INTENT(INOUT)  :: INFO(2)
      INTEGER, INTENT(IN)     :: NVTX
      INTEGER, INTENT(OUT)    :: NCMPA
      INTEGER(8), INTENT(IN)  :: NEDGES8
      INTEGER(8)              :: XADJ8(NVTX+1)
      INTEGER, INTENT(OUT)    :: NV(NVTX)
      INTEGER, INTENT(IN)     :: IW(NEDGES8)
      INTEGER, INTENT(OUT)    :: PARENT(NVTX)
      INTEGER, INTENT(IN)     :: KEEP10
      INTEGER(8), DIMENSION(:), ALLOCATABLE :: IW8, NV8
      INTEGER :: I, allocok
      IF (KEEP10.EQ.1) THEN
        CALL MUMPS_PORDF( int(NVTX,8), NEDGES8, XADJ8, IW,
     &                                        NV, NCMPA )
        DO I=1, NVTX
          PARENT(I)=int(XADJ8(I))
        ENDDO
      ELSE
        ALLOCATE(IW8(NEDGES8), NV8(NVTX), stat=allocok)
        IF (allocok > 0) THEN
          INFO(1)=-7
          CALL MUMPS_SET_IERROR(NEDGES8+int(NVTX,8),INFO(2))
          IF (LPOK) WRITE(LP,'(A)') 
     &      "ERROR memory allocation in MUMPS_PORD_MIXEDto64"
          RETURN
        ENDIF
        CALL MUMPS_COPY_INT_32TO64_64C(IW, NEDGES8, IW8)
        CALL MUMPS_PORDF( int(NVTX,8), NEDGES8, XADJ8, IW8,
     &                                        NV8, NCMPA )
        DO I= 1, NVTX
          PARENT(I) = int(XADJ8(I))
        ENDDO
        DO I= 1, NVTX
          NV(I) = int(NV8(I))
        ENDDO
        DEALLOCATE(IW8,NV8)
      ENDIF
      RETURN
      END SUBROUTINE MUMPS_PORDF_MIXEDto64
      SUBROUTINE MUMPS_PORDF_WND_MIXEDto32( NVTX, NEDGES8,
     &                                      XADJ8, IW,
     &                                      NV, NCMPA, N, PARENT, 
     &                                      INFO, LP, LPOK, KEEP10 )
      IMPLICIT NONE
      INTEGER, INTENT(IN)     :: LP
      LOGICAL, INTENT(IN)     :: LPOK
      INTEGER, INTENT(INOUT)  :: INFO(2)
      INTEGER, INTENT(IN)     :: NVTX, N         
      INTEGER, INTENT(OUT)    :: NCMPA           
      INTEGER, INTENT(INOUT)  :: NV(N)           
      INTEGER(8)              :: XADJ8(N+1)      
      INTEGER(8), INTENT(IN)  :: NEDGES8         
      INTEGER                 :: IW(NEDGES8)
      INTEGER, INTENT(OUT)    :: PARENT(NVTX)
      INTEGER, INTENT(IN)     :: KEEP10
      INTEGER, DIMENSION(:), ALLOCATABLE :: XADJ
      INTEGER :: I, allocok
      IF (NEDGES8.GT. int(huge(IW),8)) THEN
        INFO(1) = -51
        CALL MUMPS_SET_IERROR(NEDGES8,INFO(2))
        RETURN
      ENDIF
      ALLOCATE(XADJ(N+1), stat=allocok)
      IF (allocok > 0) THEN
        INFO(1)=-7
        INFO(2)=NVTX+1
        IF (LPOK) WRITE(LP,'(A)') 
     &    "ERROR memory allocation in MUMPS_PORDF_WND_MIXEDto32"
        RETURN
      ENDIF
      CALL MUMPS_COPY_INT_64TO32(XADJ8,N+1,XADJ)
      CALL MUMPS_PORDF_WND( NVTX, int(NEDGES8),
     &                             XADJ, IW,
     &                             NV, NCMPA, N )
      DO I= 1, NVTX
        PARENT(I) = XADJ(I)
      ENDDO
      DEALLOCATE(XADJ)
      RETURN
      END SUBROUTINE MUMPS_PORDF_WND_MIXEDto32
      SUBROUTINE MUMPS_PORDF_WND_MIXEDto64( NVTX, NEDGES8,
     &                                      XADJ8, IW,
     &                                      NV, NCMPA, N, PARENT, 
     &                                      INFO, LP, LPOK, KEEP10 )
      IMPLICIT NONE
      INTEGER, INTENT(IN)      :: LP
      LOGICAL, INTENT(IN)      :: LPOK
      INTEGER, INTENT(INOUT)   :: INFO(2)
      INTEGER, INTENT(IN)      :: NVTX, N         
      INTEGER, INTENT(OUT)     :: NCMPA           
      INTEGER, INTENT(INOUT)   :: NV(NVTX)        
      INTEGER(8)               :: XADJ8(N+1)      
      INTEGER(8), INTENT(IN)   :: NEDGES8         
      INTEGER                  :: IW(NEDGES8)
      INTEGER, INTENT(OUT)     :: PARENT(NVTX)
      INTEGER, INTENT(IN)      :: KEEP10
      INTEGER(8), DIMENSION(:), ALLOCATABLE :: IW8, NV8
      INTEGER :: allocok
      IF (KEEP10.EQ.1) THEN
        CALL MUMPS_PORDF_WND( int(NVTX,8), NEDGES8,
     &                             XADJ8, IW,
     &                             NV, NCMPA, int(N,8) )
        CALL MUMPS_COPY_INT_64TO32(XADJ8, NVTX, PARENT)
      ELSE
        ALLOCATE(IW8(NEDGES8), NV8(N), stat=allocok)
        IF (allocok > 0) THEN
          INFO(1)=-7
          CALL MUMPS_SET_IERROR(NEDGES8+int(NVTX,8),INFO(2))
          IF (LPOK) WRITE(LP,'(A)') 
     &      "ERROR memory allocation in MUMPS_PORD_MIXEDto64"
          RETURN
        ENDIF
        CALL MUMPS_COPY_INT_32TO64_64C(IW, NEDGES8, IW8)
        CALL MUMPS_COPY_INT_32TO64(NV, NVTX, NV8)
        CALL MUMPS_PORDF_WND( int(NVTX,8), NEDGES8,
     &                             XADJ8, IW8,
     &                             NV8, NCMPA, int(N,8) )
        CALL MUMPS_COPY_INT_64TO32(XADJ8, NVTX, PARENT)
        CALL MUMPS_COPY_INT_64TO32(NV8, NVTX, NV)
        DEALLOCATE(IW8, NV8)
      ENDIF
      RETURN
      END SUBROUTINE MUMPS_PORDF_WND_MIXEDto64
#endif
      SUBROUTINE MUMPS_ANA_WRAP_RETURN()
      RETURN
      END SUBROUTINE MUMPS_ANA_WRAP_RETURN
      END MODULE MUMPS_ANA_ORD_WRAPPERS
