C     Fx compiler version 3.0
C     SUBROUTINE doit(blksize)
CC    TEMPLATE ta(60000)
CC    TEMPLATE tb(30000)
CC    ALIGN a(I) WITH ta(I)
CC    ALIGN b(I) WITH tb(I)
CC    DISTRIBUTE ta(BLOCK_CYCLIC(blksize,4))
CC    DISTRIBUTE tb(BLOCK_CYCLIC(blksize,4))
C     PDO (i = 1:60000)
C     POUT a(i)
C     LOCAL
C     IF (fxcellid.LT.4) THEN
C     fxloopstart0 = (MAX((((fxcellid * (MIN(blksize,60000))) + 1) + 
C    $(ifxceil(((1 - ((fxcellid + 1) * (MIN(blksize,60000)))) / real(
C    $((MIN(blksize,60000)) * 4)))) * ((MIN(blksize,60000)) * 4))),1)
C    $)
C     fxlmidx0 = ifxlm(fxadesc,0,fxloopstart0)
C     DO fxp0_blkno0 = ifxceil(((1 - ((fxcellid + 1) * (MIN(blksize,
C    $60000)))) / real(((MIN(blksize,60000)) * 4)))), ifxfloor((59999
C    $ / real(((MIN(blksize,60000)) * 4))))
C     DO i = MAX((((fxcellid * (MIN(blksize,60000))) + 1) + (
C    $fxp0_blkno0 * ((MIN(blksize,60000)) * 4))),1), (MIN(((((
C    $fxcellid * (MIN(blksize,60000))) + 1) + (fxp0_blkno0 * ((MIN(
C    $blksize,60000)) * 4))) + ((MIN(blksize,60000)) + (-1))),60000))
C     a(i) = i
C     fxlmidx0 = (fxlmidx0 + 1)
C     ENDDO
C     ENDDO
C     ENDIF
C     ENDLOCAL
C     ENDPDO
C     PDO (i = 1:30000)
C     POUT b(i)
C     LOCAL
C     IF (fxcellid.LT.4) THEN
C     fxloopstart0 = (MAX((((fxcellid * (MIN(blksize,30000))) + 1) + 
C    $(ifxceil(((1 - ((fxcellid + 1) * (MIN(blksize,30000)))) / real(
C    $((MIN(blksize,30000)) * 4)))) * ((MIN(blksize,30000)) * 4))),1)
C    $)
C     fxlmidx0 = ifxlm(fxbdesc,0,fxloopstart0)
C     DO fxp1_blkno0 = ifxceil(((1 - ((fxcellid + 1) * (MIN(blksize,
C    $30000)))) / real(((MIN(blksize,30000)) * 4)))), ifxfloor((29999
C    $ / real(((MIN(blksize,30000)) * 4))))
C     DO i = MAX((((fxcellid * (MIN(blksize,30000))) + 1) + (
C    $fxp1_blkno0 * ((MIN(blksize,30000)) * 4))),1), (MIN(((((
C    $fxcellid * (MIN(blksize,30000))) + 1) + (fxp1_blkno0 * ((MIN(
C    $blksize,30000)) * 4))) + ((MIN(blksize,30000)) + (-1))),30000))
C     b(i) = ( -i)
C     fxlmidx0 = (fxlmidx0 + 1)
C     ENDDO
C     ENDDO
C     ENDIF
C     ENDLOCAL
C     ENDPDO
C     a(::6) = b(::3)
C     PDO (i = 1:60000)
C     PIN a(i)
C     PMERGEVARS errors
C     PCOMMUTATIVE
C     LOCAL
C     PINIT
C     errors = 0
C     IF (fxcellid.LT.4) THEN
C     fxloopstart0 = (MAX((((fxcellid * (MIN(blksize,60000))) + 1) + 
C    $(ifxceil(((1 - ((fxcellid + 1) * (MIN(blksize,60000)))) / real(
C    $((MIN(blksize,60000)) * 4)))) * ((MIN(blksize,60000)) * 4))),1)
C    $)
C     fxlmidx0 = ifxlm(fxadesc,0,fxloopstart0)
C     DO fxp2_blkno0 = ifxceil(((1 - ((fxcellid + 1) * (MIN(blksize,
C    $60000)))) / real(((MIN(blksize,60000)) * 4)))), ifxfloor((59999
C    $ / real(((MIN(blksize,60000)) * 4))))
C     DO i = MAX((((fxcellid * (MIN(blksize,60000))) + 1) + (
C    $fxp2_blkno0 * ((MIN(blksize,60000)) * 4))),1), (MIN(((((
C    $fxcellid * (MIN(blksize,60000))) + 1) + (fxp2_blkno0 * ((MIN(
C    $blksize,60000)) * 4))) + ((MIN(blksize,60000)) + (-1))),60000))
C     PBODY
C     idx = ((i + (-1)) / 6)
C     IF ((idx * 6).EQ.(i + (-1))) THEN
C     IF (a(i).NE.( -((idx * 3) + 1))) THEN
C     WRITE (unit=6,fmt=*) i,a(i),( -(idx * 3) + 1)
C     errors = (errors + 1)
C     ENDIF
C     ELSE
C     IF (a(i).NE.i) THEN
C     WRITE (unit=6,fmt=*) i,a(i)
C     errors = (errors + 1)
C     ENDIF
C     ENDIF
C     fxlmidx0 = (fxlmidx0 + 1)
C     ENDDO
C     ENDDO
C     ENDIF
C     ENDLOCAL
C     PMERGE
C     DO fxp2_mergedepth = 1, 0, (-1)
C     fxp2_idle = fxmerge_step(errors,fxp2_rt_errors,1,
C    $fxp2_mergedepth)
C     IF (fxp2_idle.NE.0) THEN
C     errors = (errors + fxp2_rt_errors)
C     ENDIF
C     ENDDO
C     CALL fxmerge_broadcast(errors,1)
C     ENDPDO
C     WRITE (unit=6,fmt=*) errors
C     END


      SUBROUTINE doit(blksize)
      INTEGER blksize
      INTEGER errors
      INTEGER i
      INTEGER idx
      INTEGER fxdistarg
      INTEGER fxcellid
      INTEGER fxccbdesc(1,11)
      INTEGER fxbdesc(519,1)
      INTEGER fxccadesc(1,11)
      INTEGER fxadesc(519,1)
      EXTERNAL fxdblcheck
      INTEGER fxlmidx0
      EXTERNAL ifxceil
      INTEGER ifxceil
      INTRINSIC real
      REAL real
      INTEGER fxp0_blkno0
      EXTERNAL ifxfloor
      INTEGER ifxfloor
      INTEGER fxloopstart0
      EXTERNAL ifxlm
      INTEGER ifxlm
      INTEGER fxp1_blkno0
      INTEGER fxp2_rt_errors
      INTEGER fxp2_blkno0
      INTEGER fxp2_mergedepth
      INTEGER fxp2_idle
      EXTERNAL fxmerge_step
      INTEGER fxmerge_step
      EXTERNAL fxmerge_broadcast
      EXTERNAL fx_procstart
      INTEGER fxdistarray(6,20)
      EXTERNAL fxinitdesc
      EXTERNAL ccom_fun_0
      EXTERNAL ccom_fun_1
      EXTERNAL msg_reduce
      EXTERNAL ccom_fun_2
      INTEGER fxabase(1)
      INTEGER fxaoffset
      EXTERNAL fxallocp
      INTEGER fxallocp
      EXTERNAL fxfreep
      INTEGER fxbbase(1)
      INTEGER fxboffset
      COMMON /fxcommon/ fxcellid,fxdistarg

      CALL fxdblcheck(fxdistarg,0,'doit')
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = blksize
      fxdistarray(4,1) = 4
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      CALL fxinitdesc(1,1,fxdistarray,fxbdesc,(-1),(-1))
      CALL ccom_fun_0(blksize,fxccbdesc)
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = blksize
      fxdistarray(4,1) = 4
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      CALL fxinitdesc(1,1,fxdistarray,fxadesc,(-1),(-1))
      CALL ccom_fun_1(blksize,fxccadesc)
      fxaoffset = fxallocp(fxabase,((MIN(((MIN(blksize,60000)) * ((
     $fxadesc(2,1) + 59999) / fxadesc(2,1))),60000)) * 8),3,1)
      fxboffset = fxallocp(fxbbase,((MIN(((MIN(blksize,30000)) * ((
     $fxbdesc(2,1) + 29999) / fxbdesc(2,1))),30000)) * 8),3,0)
C     TEMPLATE ta(60000)
C     TEMPLATE tb(30000)
C     ALIGN a(I) WITH ta(I)
C     ALIGN b(I) WITH tb(I)
C     DISTRIBUTE ta(BLOCK_CYCLIC(blksize,4))
C     DISTRIBUTE tb(BLOCK_CYCLIC(blksize,4))
C     PDO (i = 1:60000)
C     POUT a(i)
C     LOCAL
      IF (fxcellid.LT.4) THEN
        fxloopstart0 = (MAX((((fxcellid * (MIN(blksize,60000))) + 1)
     $ + (ifxceil(((1 - ((fxcellid + 1) * (MIN(blksize,60000)))) / 
     $real(((MIN(blksize,60000)) * 4)))) * ((MIN(blksize,60000)) * 4)
     $)),1))
        fxlmidx0 = ifxlm(fxadesc,0,fxloopstart0)
        DO fxp0_blkno0 = ifxceil(((1 - ((fxcellid + 1) * (MIN(blksize
     $,60000)))) / real(((MIN(blksize,60000)) * 4)))), ifxfloor((
     $59999 / real(((MIN(blksize,60000)) * 4))))
          DO i = MAX((((fxcellid * (MIN(blksize,60000))) + 1) + (
     $fxp0_blkno0 * ((MIN(blksize,60000)) * 4))),1), (MIN(((((
     $fxcellid * (MIN(blksize,60000))) + 1) + (fxp0_blkno0 * ((MIN(
     $blksize,60000)) * 4))) + ((MIN(blksize,60000)) + (-1))),60000))
            fxabase((fxaoffset + fxlmidx0)) = i
            fxlmidx0 = (fxlmidx0 + 1)
          ENDDO
        ENDDO
      ENDIF
C     ENDLOCAL
C     ENDPDO
C     PDO (i = 1:30000)
C     POUT b(i)
C     LOCAL
      IF (fxcellid.LT.4) THEN
        fxloopstart0 = (MAX((((fxcellid * (MIN(blksize,30000))) + 1)
     $ + (ifxceil(((1 - ((fxcellid + 1) * (MIN(blksize,30000)))) / 
     $real(((MIN(blksize,30000)) * 4)))) * ((MIN(blksize,30000)) * 4)
     $)),1))
        fxlmidx0 = ifxlm(fxbdesc,0,fxloopstart0)
        DO fxp1_blkno0 = ifxceil(((1 - ((fxcellid + 1) * (MIN(blksize
     $,30000)))) / real(((MIN(blksize,30000)) * 4)))), ifxfloor((
     $29999 / real(((MIN(blksize,30000)) * 4))))
          DO i = MAX((((fxcellid * (MIN(blksize,30000))) + 1) + (
     $fxp1_blkno0 * ((MIN(blksize,30000)) * 4))),1), (MIN(((((
     $fxcellid * (MIN(blksize,30000))) + 1) + (fxp1_blkno0 * ((MIN(
     $blksize,30000)) * 4))) + ((MIN(blksize,30000)) + (-1))),30000))
            fxbbase((fxboffset + fxlmidx0)) = ( -i)
            fxlmidx0 = (fxlmidx0 + 1)
          ENDDO
        ENDDO
      ENDIF
C     ENDLOCAL
C     ENDPDO
      CALL ccom_fun_2(fxabase((fxaoffset + 1)),fxbbase((fxboffset + 1
     $)),blksize)
C     PDO (i = 1:60000)
C     PIN a(i)
C     PMERGEVARS errors
C     PCOMMUTATIVE
C     LOCAL
C     PINIT
      errors = 0
      IF (fxcellid.LT.4) THEN
        fxloopstart0 = (MAX((((fxcellid * (MIN(blksize,60000))) + 1)
     $ + (ifxceil(((1 - ((fxcellid + 1) * (MIN(blksize,60000)))) / 
     $real(((MIN(blksize,60000)) * 4)))) * ((MIN(blksize,60000)) * 4)
     $)),1))
        fxlmidx0 = ifxlm(fxadesc,0,fxloopstart0)
        DO fxp2_blkno0 = ifxceil(((1 - ((fxcellid + 1) * (MIN(blksize
     $,60000)))) / real(((MIN(blksize,60000)) * 4)))), ifxfloor((
     $59999 / real(((MIN(blksize,60000)) * 4))))
          DO i = MAX((((fxcellid * (MIN(blksize,60000))) + 1) + (
     $fxp2_blkno0 * ((MIN(blksize,60000)) * 4))),1), (MIN(((((
     $fxcellid * (MIN(blksize,60000))) + 1) + (fxp2_blkno0 * ((MIN(
     $blksize,60000)) * 4))) + ((MIN(blksize,60000)) + (-1))),60000))
C     PBODY
            idx = ((i + (-1)) / 6)
            IF ((idx * 6).EQ.(i + (-1))) THEN
              IF (fxabase((fxaoffset + fxlmidx0)).NE.( -((idx * 3) + 
     $1))) THEN
                WRITE (unit=6,fmt=*) i,fxabase(fxaoffset + fxlmidx0),
     $( -((idx * 3) + 1))
                errors = (errors + 1)
              ENDIF
            ELSE
              IF (fxabase((fxaoffset + fxlmidx0)).NE.i) THEN
                WRITE (unit=6,fmt=*) i,fxabase(fxaoffset + fxlmidx0)
                errors = (errors + 1)
              ENDIF
            ENDIF
            fxlmidx0 = (fxlmidx0 + 1)
          ENDDO
        ENDDO
      ENDIF
C     ENDLOCAL
C     PMERGE
      DO fxp2_mergedepth = 1, 0, (-1)
        fxp2_idle = fxmerge_step(errors,fxp2_rt_errors,1,
     $fxp2_mergedepth)
        IF (fxp2_idle.NE.0) THEN
          errors = (errors + fxp2_rt_errors)
        ENDIF
      ENDDO
      CALL fxmerge_broadcast(errors,1)
C     ENDPDO
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) errors
      ENDIF
      END


C
C     ------------------------------------------------- 
C

C     PROGRAM alltoall
C     CALL doit(17)
C     END


      PROGRAM alltoall
      INTEGER fxcellid
      EXTERNAL doit
      INTEGER fxdistarg
      EXTERNAL fx_procstart
      EXTERNAL fx_init
      EXTERNAL ccom_init
      COMMON /fxcommon/ fxcellid,fxdistarg

      CALL fx_init(fxcellid,1,0,0,0,4)
      CALL ccom_init(0)
      fxdistarg = 0
      CALL doit(17)
      END


C
C     ------------------------------------------------- 
C

