C     Fx compiler version 2.1
CC    TEMPLATE t(512)
CC    ALIGN a(I,J) WITH t(I)
CC    ALIGN b(I,J) WITH t(I)
CC    ALIGN c(I,J) WITH t(I)
CC    DISTRIBUTE t(BLOCK_CYCLIC(8,64))
C     CALL fx_sync()
C     pclocks = 0
C     cclocks = 0
C     DO iter = 1, 10, 1
C     CALL inita(a)
C     CALL initb(b,5.)
C     c = 0.
C     DO jp = 0, 63, 1
C     CALL timer_start()
C     v = b(:,(jp * 8) + 1:(jp + 1) * 8)
C     cclocks = (cclocks + timer_stop())
C     CALL timer_start()
C     PDO (i = 1:512)
C     PIN a(i,:),c(i,:)
C     POUT c(i,:)
C     LOCAL
C     fxloopstart0 = (MAX(((fxcellid * 8) + 1),1))
C     fxlmidx0 = ifxlm(fxcdesc,0,fxloopstart0)
C     DO i = fxloopstart0, MIN(((fxcellid * 8) + 8),512), 1
C     DO j = (jp * 8) + 1, ((jp + 1) * 8), 1
C     DO k = 1, 512, 1
C     c(i,j) = (c(i,j) + (a(i,k) * v(k,(j - (jp * 8)))))
C     ENDDO
C     ENDDO
C     fxlmidx0 = (fxlmidx0 + 1)
C     ENDDO
C     ENDLOCAL
C     ENDPDO
C     pclocks = (pclocks + timer_stop())
C     ENDDO
C     CALL verify(c,5.)
C     ENDDO
C     pclocks = (pclocks / 10)
C     cclocks = (cclocks / 10)
C     efficiency = ((real(pclocks) / real((pclocks + cclocks))) * 
C    $100.)
C     WRITE (unit=6,fmt=*) 'comp=',pclocks,' comm=',cclocks,
C    $'efficiency= ',efficiency
C     WRITE (unit=6,fmt=*) ''
C     secs = ((pclocks + cclocks))
C     secs = (secs / 2e7)
C     flops = 268435456.
C     mflops = (flops / 1e6)
C     mflops = (mflops / secs)
C     WRITE (unit=6,fmt=*) 'secs  =',secs
C     WRITE (unit=6,fmt=*) 'flops =',flops
C     WRITE (unit=6,fmt=*) 'mflops=',mflops
C     END
      PROGRAM main
      INTEGER fxindex1
      INTEGER fxindex2
      INTEGER fxlmidx0
      INTRINSIC real
      REAL real
      INTEGER fxfirst0
      INTEGER fxfirst1
      REAL secs
      INTEGER iter
      INTEGER fxcellid
      EXTERNAL fxinnerloop1
      INTEGER fxloopstart0
      INTEGER fxcc0
      INTEGER fxcc1
      INTEGER fxbufdataidx
      EXTERNAL fxbcastpairs
      INTEGER fxbufoff0
      INTEGER i
      INTEGER j
      INTEGER k
      EXTERNAL fx_procstart
      INTEGER fxrslice0
      INTEGER fxstride0
      INTEGER fxstride1
      INTEGER fxlmlast0
      INTEGER fxlmlast1
      EXTERNAL inita
      EXTERNAL initb
      INTRINSIC float
      REAL float
      EXTERNAL ifxlm
      INTEGER ifxlm
      REAL flops
      EXTERNAL fx_deinit
      INTEGER fxdistarg
      INTEGER jp
      INTEGER fxaddr
      INTEGER fxlmfirst0
      INTEGER fxlmfirst1
      REAL efficiency
      EXTERNAL net_reduce
      EXTERNAL fxcl_inita
      REAL mflops
      EXTERNAL verify
      EXTERNAL fxinitdesc
      EXTERNAL timer_stop
      INTEGER timer_stop
      INTEGER fxlast0
      INTEGER fxlast1
      INTEGER fxlmstride0
      INTEGER cclocks
      INTEGER fxlmstride1
      EXTERNAL ifxceil
      INTEGER ifxceil
      EXTERNAL fxdsend
      INTEGER pclocks
      EXTERNAL fx_init
      INTEGER fxidiotic3_0
      EXTERNAL fx_set_module_geometry
      EXTERNAL fx_sync
      EXTERNAL fxallocinit
      INTEGER fxallocinit
      EXTERNAL timer_start
      INTEGER fxslice0
      INTEGER fxbuffer(1)
      REAL a(8,512)
      REAL b(8,512)
      REAL c(8,512)
      REAL v(512,8)
      COMPLEX fxcbuffer(1)
      DOUBLE PRECISION fxdbuffer(1)
      LOGICAL fxlbuffer(1)
      REAL fxrbuffer(1)
      DOUBLE COMPLEX fxdcbuffer(1)
      INTEGER fxadesc(71,2)
      INTEGER fxbdesc(71,2)
      INTEGER fxcdesc(71,2)
      INTEGER fxdistarray(6,20)
      EQUIVALENCE (fxbuffer,fxrbuffer)
      EQUIVALENCE (fxbuffer,fxlbuffer)
      EQUIVALENCE (fxbuffer,fxdbuffer)
      EQUIVALENCE (fxbuffer,fxcbuffer)
      EQUIVALENCE (fxbuffer,fxdcbuffer)
      COMMON /fxcommon/ fxcellid,fxdistarg
      CALL fx_init(fxcellid,1,1,0,0)
      CALL fx_set_module_geometry(0,0,0,8,8)
      fxdistarg = 0
      fxbufoff0 = fxallocinit(fxbuffer,512)
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 64
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 512
      CALL fxinitdesc(1,2,fxdistarray,fxcdesc)
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 64
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 512
      CALL fxinitdesc(1,2,fxdistarray,fxbdesc)
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 64
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 512
      CALL fxinitdesc(1,2,fxdistarray,fxadesc)
C     TEMPLATE t(512)
C     ALIGN a(I,J) WITH t(I)
C     ALIGN b(I,J) WITH t(I)
C     ALIGN c(I,J) WITH t(I)
C     DISTRIBUTE t(BLOCK_CYCLIC(8,64))
      CALL fx_sync()
      pclocks = 0
      cclocks = 0
      DO iter = 1, 10, 1
        fxdistarg = 1
        CALL inita(a,fxadesc)
        fxdistarg = 1
        CALL initb(b,5.,fxbdesc,(-1))
        CALL fxcl_inita(0,1,1,fxlast0,fxlmlast0,fxcc0,1,fxcdesc((
     $fxcellid + 8),1),512,1,8,fxfirst0,fxlmfirst0)
        CALL fxcl_inita(0,1,1,fxlast1,fxlmlast1,fxcc1,1,fxcdesc((
     $fxcellid + 8),2),512,1,512,fxfirst1,fxlmfirst1)
        DO fxindex1 = fxlmfirst0, fxlmlast0, 1
          DO fxindex2 = fxlmfirst1, fxlmlast1, 1
            c(fxindex1,fxindex2) = 0.
          ENDDO
        ENDDO
        DO jp = 0, 63, 1
          CALL timer_start()
          fxbufdataidx = 1
          fxrslice0 = (MAX((fxbdesc((fxcellid + 8),1) + (-1)),0))
          DO fxslice0 = 1, 8, 1
            CALL fxinnerloop1(fxbufdataidx,fxbuffer((fxbufoff0 + 
     $fxbufdataidx)),v((fxrslice0 + 1),((MAX((1 - ((jp * 8) + 1)),0))
     $ + 1)),b(fxslice0,(MAX(((jp * 8) + 1),1))),(((MIN(((jp * 8) + 8
     $),512)) - (MAX(((jp * 8) + 1),1))) + 1),2048,32,1)
            fxrslice0 = (fxrslice0 + 1)
          ENDDO
          CALL fxbcastpairs(fxbuffer((fxbufoff0 + 1)),(fxbufdataidx
     $ + (-1)),1,512)
          cclocks = (cclocks + timer_stop())
          CALL timer_start()
C     PDO (i = 1:512)
C     PIN a(i,:),c(i,:)
C     POUT c(i,:)
C     LOCAL
          fxloopstart0 = (MAX(((fxcellid * 8) + 1),1))
          fxlmidx0 = ifxlm(fxcdesc,0,fxloopstart0)
          DO i = fxloopstart0, MIN(((fxcellid * 8) + 8),512), 1
            DO j = (jp * 8) + 1, ((jp + 1) * 8), 1
              DO k = 1, 512, 1
                c(fxlmidx0,j) = (c(fxlmidx0,j) + (a(fxlmidx0,k) * v(k
     $,(j - (jp * 8)))))
              ENDDO
            ENDDO
            fxlmidx0 = (fxlmidx0 + 1)
          ENDDO
C     ENDLOCAL
C     ENDPDO
          pclocks = (pclocks + timer_stop())
        ENDDO
        fxdistarg = 1
        CALL verify(c,5.,fxcdesc,(-1))
      ENDDO
      pclocks = (pclocks / 10)
      cclocks = (cclocks / 10)
      efficiency = ((real(pclocks) / real((pclocks + cclocks))) * 
     $100.)
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) 'comp=',pclocks,' comm=',cclocks,
     $'efficiency= ',efficiency
      ENDIF
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) ''
      ENDIF
      secs = ((pclocks + cclocks))
      secs = (secs / 2e7)
      flops = 268435456.
      mflops = (flops / 1e6)
      mflops = (mflops / secs)
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) 'secs  =',secs
      ENDIF
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) 'flops =',flops
      ENDIF
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) 'mflops=',mflops
      ENDIF
      CALL fx_deinit()
      END
CC    TEMPLATE t(512)
CC    ALIGN c(I,J) WITH t(I)
CC    DISTRIBUTE t(BLOCK_CYCLIC(8,64))
C     count = 0
C     PDO (i = 1:512)
C     PIN c(i,:)
C     LOCAL
C     fxloopstart0 = (MAX(((fxcellid * 8) + 1),1))
C     fxlmidx0 = ifxlm(fxcdesc,0,fxloopstart0)
C     DO i = fxloopstart0, MIN(((fxcellid * 8) + 8),512), 1
C     DO j = 1, 512, 1
C     IF (c(i,j).NE.((i * j) * f)) THEN
C     count = (count + 1)
C     ENDIF
C     ENDDO
C     fxlmidx0 = (fxlmidx0 + 1)
C     ENDDO
C     ENDLOCAL
C     ENDPDO
C     IF (count.NE.0) WRITE (unit=6,fmt=*) count
C     END
      SUBROUTINE verify(c,f,fxcdesc,fxfdesc)
      INTEGER fxlmidx0
      INTEGER fxcellid
      INTEGER fxloopstart0
      EXTERNAL fxinitdescck
      REAL f
      INTEGER i
      INTEGER j
      EXTERNAL fx_procstart
      INTRINSIC float
      REAL float
      EXTERNAL ifxlm
      INTEGER ifxlm
      INTEGER count
      INTEGER fxdistarg
      EXTERNAL fxdblcheck
      EXTERNAL net_reduce
      EXTERNAL ifxceil
      INTEGER ifxceil
      EXTERNAL fxdistcheck
      REAL c(8,512)
      INTEGER fxcdesc(71,2)
      INTEGER fxfdesc(71,1)
      INTEGER fxdistarray(6,20)
      COMMON /fxcommon/ fxcellid,fxdistarg
      CALL fxdblcheck(fxdistarg,1,'verify')
      fxdistarg = 0
      CALL fxdistcheck(fxfdesc,0,2,'verify')
      CALL fxdistcheck(fxcdesc,1,1,'verify')
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 64
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 512
      CALL fxinitdescck(1,2,fxdistarray,fxcdesc,'c','verify')
C     TEMPLATE t(512)
C     ALIGN c(I,J) WITH t(I)
C     DISTRIBUTE t(BLOCK_CYCLIC(8,64))
      count = 0
C     PDO (i = 1:512)
C     PIN c(i,:)
C     LOCAL
      fxloopstart0 = (MAX(((fxcellid * 8) + 1),1))
      fxlmidx0 = ifxlm(fxcdesc,0,fxloopstart0)
      DO i = fxloopstart0, MIN(((fxcellid * 8) + 8),512), 1
        DO j = 1, 512, 1
          IF (c(fxlmidx0,j).NE.((i * j) * f)) THEN
            count = (count + 1)
          ENDIF
        ENDDO
        fxlmidx0 = (fxlmidx0 + 1)
      ENDDO
C     ENDLOCAL
C     ENDPDO
      IF (count.NE.0) THEN
        IF (fxcellid.EQ.0) THEN
          WRITE (unit=6,fmt=*) count
        ENDIF
      ENDIF
      END
CC    TEMPLATE t(512)
CC    ALIGN a(I,J) WITH t(I)
CC    DISTRIBUTE t(BLOCK_CYCLIC(8,64))
C     PDO (i = 1:512)
C     PIN a(i,:)
C     POUT a(i,:)
C     LOCAL
C     fxloopstart0 = (MAX(((fxcellid * 8) + 1),1))
C     fxlmidx0 = ifxlm(fxadesc,0,fxloopstart0)
C     DO i = fxloopstart0, MIN(((fxcellid * 8) + 8),512), 1
C     DO j = 1, 512, 1
C     a(i,j) = ((i * j) * 1.)
C     ENDDO
C     fxlmidx0 = (fxlmidx0 + 1)
C     ENDDO
C     ENDLOCAL
C     ENDPDO
C     END
      SUBROUTINE inita(a,fxadesc)
      INTEGER fxlmidx0
      INTEGER fxcellid
      INTEGER fxloopstart0
      EXTERNAL fxinitdescck
      INTEGER i
      INTEGER j
      EXTERNAL fx_procstart
      INTRINSIC float
      REAL float
      EXTERNAL ifxlm
      INTEGER ifxlm
      INTEGER fxdistarg
      EXTERNAL fxdblcheck
      EXTERNAL net_reduce
      EXTERNAL ifxceil
      INTEGER ifxceil
      EXTERNAL fxdistcheck
      REAL a(8,512)
      INTEGER fxadesc(71,2)
      INTEGER fxdistarray(6,20)
      COMMON /fxcommon/ fxcellid,fxdistarg
      CALL fxdblcheck(fxdistarg,1,'inita')
      fxdistarg = 0
      CALL fxdistcheck(fxadesc,1,1,'inita')
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 64
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 512
      CALL fxinitdescck(1,2,fxdistarray,fxadesc,'a','inita')
C     TEMPLATE t(512)
C     ALIGN a(I,J) WITH t(I)
C     DISTRIBUTE t(BLOCK_CYCLIC(8,64))
C     PDO (i = 1:512)
C     PIN a(i,:)
C     POUT a(i,:)
C     LOCAL
      fxloopstart0 = (MAX(((fxcellid * 8) + 1),1))
      fxlmidx0 = ifxlm(fxadesc,0,fxloopstart0)
      DO i = fxloopstart0, MIN(((fxcellid * 8) + 8),512), 1
        DO j = 1, 512, 1
          a(fxlmidx0,j) = ((i * j) * 1.)
        ENDDO
        fxlmidx0 = (fxlmidx0 + 1)
      ENDDO
C     ENDLOCAL
C     ENDPDO
      END
CC    TEMPLATE t(512)
CC    ALIGN b(I,J) WITH t(I)
CC    DISTRIBUTE t(BLOCK_CYCLIC(8,64))
C     b = 0.
C     DO i = 1, 512, 1
C     DO j = 1, 512, 1
C     IF (i.EQ.j) THEN
C     b(i,j) = f
C     ENDIF
C     ENDDO
C     ENDDO
C     END
      SUBROUTINE initb(b,f,fxbdesc,fxfdesc)
      INTEGER fxindex1
      INTEGER fxindex2
      INTEGER fxfirst0
      INTEGER fxfirst1
      INTEGER fxcellid
      INTEGER fxcc0
      INTEGER fxcc1
      EXTERNAL fxinitdescck
      REAL f
      INTEGER i
      INTEGER j
      EXTERNAL fx_procstart
      INTEGER fxstride0
      INTEGER fxstride1
      INTEGER fxlmlast0
      INTEGER fxlmlast1
      EXTERNAL ifxlm
      INTEGER ifxlm
      INTEGER fxdistarg
      EXTERNAL fxdblcheck
      INTEGER fxlmfirst0
      INTEGER fxlmfirst1
      EXTERNAL net_reduce
      EXTERNAL fxcl_inita
      INTEGER fxlast0
      INTEGER fxlast1
      INTEGER fxlmstride0
      INTEGER fxlmstride1
      EXTERNAL fxdistcheck
      EXTERNAL ifxowns
      INTEGER ifxowns
      REAL b(8,512)
      INTEGER fxbdesc(71,2)
      INTEGER fxfdesc(71,1)
      INTEGER fxdistarray(6,20)
      COMMON /fxcommon/ fxcellid,fxdistarg
      CALL fxdblcheck(fxdistarg,1,'initb')
      fxdistarg = 0
      CALL fxdistcheck(fxfdesc,0,2,'initb')
      CALL fxdistcheck(fxbdesc,1,1,'initb')
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 64
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 512
      CALL fxinitdescck(1,2,fxdistarray,fxbdesc,'b','initb')
C     TEMPLATE t(512)
C     ALIGN b(I,J) WITH t(I)
C     DISTRIBUTE t(BLOCK_CYCLIC(8,64))
      CALL fxcl_inita(0,1,1,fxlast0,fxlmlast0,fxcc0,1,fxbdesc((
     $fxcellid + 8),1),512,1,8,fxfirst0,fxlmfirst0)
      CALL fxcl_inita(0,1,1,fxlast1,fxlmlast1,fxcc1,1,fxbdesc((
     $fxcellid + 8),2),512,1,512,fxfirst1,fxlmfirst1)
      DO fxindex1 = fxlmfirst0, fxlmlast0, 1
        DO fxindex2 = fxlmfirst1, fxlmlast1, 1
          b(fxindex1,fxindex2) = 0.
        ENDDO
      ENDDO
      DO i = 1, 512, 1
        DO j = 1, 512, 1
          IF (i.EQ.j) THEN
            IF (ifxowns(fxbdesc,0,i,fxcellid).NE.0) THEN
              b(ifxlm(fxbdesc,0,i),j) = f
            ENDIF
          ENDIF
        ENDDO
      ENDDO
      END
