C     Fx compiler version 2.1
CC    TEMPLATE fxp1a_t(512)
CC    DISTRIBUTE fxp1a_t(BLOCK_CYCLIC(8,64))
CC    ALIGN fxp1_a_storage(I,J) WITH fxp1a_t(I)
CC    ALIGN fxp1_a(I(-1):I+1,J) WITH fxp1a_t(I)
CC    TEMPLATE t(512)
CC    DISTRIBUTE t(BLOCK_CYCLIC(8,64))
CC    ALIGN a(I,J) WITH t(I)
C     c1 = .25
C     c2 = .25
C     c3 = .25
C     c4 = .25
C     c5 = .25
C     mytime = 0
C     DO t = 1, 10, 1
C     PDO (i = 1:512)
C     PINOUT 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) = 1.
C     ENDDO
C     fxlmidx0 = (fxlmidx0 + 1)
C     ENDDO
C     ENDLOCAL
C     ENDPDO
C     CALL timer_start()
C     PDO (x = 2:511)
C     PIN a(x + (-1):x + 1,:)
C     POUT a(x,:)
C     fxp1_a = a
C     fxp1_a_storage = a
C     LOCAL
C     fxloopstart0 = (MAX(((fxcellid * 8) + 1),2))
C     fxlmidx1 = ifxlm(fxfxp1_a_storagedesc,0,fxloopstart0)
C     fxlmidx0 = ifxlm(fxfxp1_adesc,0,fxloopstart0)
C     DO x = fxloopstart0, MIN(((fxcellid * 8) + 8),511), 1
C     fxp1_a_storage(x,2:511) = ((((c1 * fxp1_a((x + (-1)),2:511)) + 
C    $c2 * fxp1_a((x + 1),2:511)) + c3 * fxp1_a_storage(x,1:510)) + 
C    $c4 * fxp1_a_storage(x,3:512)) + c5 * fxp1_a_storage(x,2:511)
C     fxlmidx1 = (fxlmidx1 + 1)
C     fxlmidx0 = (fxlmidx0 + 1)
C     ENDDO
C     ENDLOCAL
C     a = fxp1_a_storage
C     ENDPDO
C     mytime = (mytime + timer_stop())
C     ENDDO
C     PDO (x = 2:511)
C     PIN a(x,:)
C     PMERGEVARS errors
C     LOCAL
C     PINIT
C     errors = 0
C     fxloopstart0 = (MAX(((fxcellid * 8) + 1),2))
C     fxlmidx0 = ifxlm(fxadesc,0,fxloopstart0)
C     DO x = fxloopstart0, MIN(((fxcellid * 8) + 8),511), 1
C     PBODY
C     DO y = 2, 511, 1
C     IF (a(x,y).NE.1.25) errors = (errors + 1)
C     ENDDO
C     fxlmidx0 = (fxlmidx0 + 1)
C     ENDDO
C     ENDLOCAL
C     PMERGE
C     DO fxp2_mergedepth = 5, 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 = ',errors
C     CALL prperf(mytime,512,512,10)
C     END
      PROGRAM main
      INTEGER fxindex0
      INTEGER fxindex1
      INTEGER fxindex2
      EXTERNAL fxawaitmessages
      INTEGER fxlmidx0
      INTEGER fxlmidx1
      INTEGER fxprocessor
      INTEGER fxfirst0
      INTEGER fxfirst1
      EXTERNAL left
      REAL left
      EXTERNAL fxschadd
      INTEGER fxcellid
      INTEGER fxop
      INTEGER fxold_fxp1_a_storage
      INTEGER fxloopstart0
      INTEGER fxcc0
      INTEGER fxcc1
      INTEGER fxbufdataidx
      EXTERNAL ifxfloor
      INTEGER ifxfloor
      EXTERNAL fxmerge_step
      INTEGER fxmerge_step
      EXTERNAL fx_byte_copy
      INTEGER fxp2_idle
      INTEGER fxbufoff0
      INTEGER i
      INTEGER j
      EXTERNAL fx_procstart
      INTEGER fxrslice0
      INTEGER t
      INTEGER fxstride0
      INTEGER x
      INTEGER y
      INTEGER fxlmlast0
      INTEGER fxstride1
      INTEGER fxlmlast1
      INTRINSIC float
      REAL float
      EXTERNAL right
      REAL right
      EXTERNAL ifxlm
      INTEGER ifxlm
      REAL c1
      REAL c2
      REAL c3
      REAL c4
      REAL c5
      INTEGER fxindex1_3
      INTEGER fxindex1_4
      EXTERNAL fx_deinit
      INTEGER fxdistarg
      EXTERNAL ifxschnum
      INTEGER ifxschnum
      EXTERNAL fxschnext
      EXTERNAL fxmerge_broadcast
      INTEGER fxplr1
      INTEGER fxaddr
      INTEGER fxlmfirst0
      INTEGER fxlmfirst1
      EXTERNAL net_reduce
      EXTERNAL prperf
      EXTERNAL fxcl_inita
      INTEGER mytime
      INTEGER errors
      INTEGER fxp2_rt_errors
      EXTERNAL fxinitdesc
      EXTERNAL timer_stop
      INTEGER timer_stop
      INTEGER fxlast0
      INTEGER fxlast1
      INTEGER fxlmstride0
      INTEGER fxp2_mergedepth
      INTEGER fxlmstride1
      EXTERNAL ifxceil
      INTEGER ifxceil
      EXTERNAL fxalloc
      INTEGER fxalloc
      EXTERNAL fx_init_temporary_heap
      EXTERNAL fxdsend
      EXTERNAL fx_init
      INTEGER fxawait
      INTEGER fxidiotic3_0
      EXTERNAL fxdschclear
      EXTERNAL ifxpmod
      INTEGER ifxpmod
      EXTERNAL fx_set_module_geometry
      EXTERNAL fx_sync
      EXTERNAL fxallocinit
      INTEGER fxallocinit
      EXTERNAL fxadblk1
      EXTERNAL timer_start
      INTEGER fxslice0
      INTEGER fxfxp1_adesc(71,2)
      INTEGER fxbuffer(1)
      INTEGER fxfxp1_a_storagedesc(71,2)
      REAL a(8,512)
      DOUBLE PRECISION fxdbuffer(1)
      COMPLEX fxcbuffer(1)
      LOGICAL fxlbuffer(1)
      REAL fxrbuffer(1)
      REAL fxp1_a(10,512)
      REAL fxp1_a_storage(8,512)
      DOUBLE COMPLEX fxdcbuffer(1)
      INTEGER fxadesc(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,16428)
      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,fxfxp1_a_storagedesc)
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 64
      fxdistarray(5,1) = (-1)
      fxdistarray(6,1) = 1
      fxdistarray(3,2) = 512
      CALL fxinitdesc(1,2,fxdistarray,fxfxp1_adesc)
      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 fxp1a_t(512)
C     DISTRIBUTE fxp1a_t(BLOCK_CYCLIC(8,64))
C     ALIGN fxp1_a_storage(I,J) WITH fxp1a_t(I)
C     ALIGN fxp1_a(I(-1):I+1,J) WITH fxp1a_t(I)
C     TEMPLATE t(512)
C     DISTRIBUTE t(BLOCK_CYCLIC(8,64))
C     ALIGN a(I,J) WITH t(I)
      c1 = .25
      c2 = .25
      c3 = .25
      c4 = .25
      c5 = .25
      mytime = 0
      DO t = 1, 10, 1
C     PDO (i = 1:512)
C     PINOUT 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) = 1.
          ENDDO
          fxlmidx0 = (fxlmidx0 + 1)
        ENDDO
C     ENDLOCAL
C     ENDPDO
        CALL timer_start()
C     PDO (x = 2:511)
C     PIN a(x + (-1):x + 1,:)
C     POUT a(x,:)
        CALL fx_sync()
        fxawait = 0
        CALL fxdschclear()
        DO fxindex0 = (-1), 1, 1
          DO fxindex1 = 0, 0, 1
            CALL fxschadd(ifxpmod((fxadesc(3,1) + fxindex0),64),0)
          ENDDO
        ENDDO
        DO fxindextmp = 1, ifxschnum(), 1
          CALL fxschnext(fxprocessor,fxop)
          fxbufdataidx = 4
          fxbuffer((fxbufoff0 + 1)) = 0
          fxplr1 = 0
          fxrslice0 = (MAX(((1 - fxfxp1_adesc((fxprocessor + 8),1))
     $ + (MAX((fxadesc((fxcellid + 8),1) + (-1)),0))),0))
          DO fxslice0 = MAX((((MAX(fxfxp1_adesc((fxprocessor + 8),1),
     $1)) + 1) - fxadesc((fxcellid + 8),1)),1), (MIN((((MIN((
     $fxfxp1_adesc((fxprocessor + 8),1) + 9),512)) + 1) - fxadesc((
     $fxcellid + 8),1)),8)), 1
            CALL fxadblk1(fxbufdataidx,fxbuffer((fxbufoff0 + 
     $fxbufdataidx)),fxp1_a((fxrslice0 + 1),(fxplr1 + 1)),a(fxslice0,
     $1),512,40,32,(fxcellid - fxprocessor),fxbuffer((fxbufoff0 + 1))
     $)
            fxrslice0 = (fxrslice0 + 1)
          ENDDO
          IF (fxbufdataidx.GT.4) THEN
            fxbuffer((fxbufoff0 + 2)) = 40
            fxbuffer((fxbufoff0 + 3)) = 512
            CALL fxdsend(fxprocessor,fxbuffer((fxbufoff0 + 1)),(
     $fxbufdataidx + (-1)),9)
            fxawait = (fxawait + 1)
          ENDIF
        ENDDO
        CALL fxawaitmessages(fxawait)
        CALL fxcl_inita(0,1,1,fxlast0,fxlmlast0,fxcc0,1,
     $fxfxp1_a_storagedesc((fxcellid + 8),1),512,1,8,fxfirst0,
     $fxlmfirst0)
        CALL fxcl_inita(0,1,1,fxlast1,fxlmlast1,fxcc1,1,
     $fxfxp1_a_storagedesc((fxcellid + 8),2),512,1,512,fxfirst1,
     $fxlmfirst1)
        DO fxindex1 = fxlmfirst0, fxlmlast0, 1
          DO fxindex2 = fxlmfirst1, fxlmlast1, 1
            fxp1_a_storage(fxindex1,fxindex2) = a(fxindex1,fxindex2)
          ENDDO
        ENDDO
C     LOCAL
        fxloopstart0 = (MAX(((fxcellid * 8) + 1),2))
        fxlmidx1 = ifxlm(fxfxp1_a_storagedesc,0,fxloopstart0)
        fxlmidx0 = ifxlm(fxfxp1_adesc,0,fxloopstart0)
        DO x = fxloopstart0, MIN(((fxcellid * 8) + 8),511), 1
          CALL fx_init_temporary_heap()
          fxold_fxp1_a_storage = fxalloc(fxp1_a_storage,16384,2)
          CALL fx_byte_copy(fxp1_a_storage,fxp1_a_storage((
     $fxold_fxp1_a_storage + 1),1),16384)
          fxindex1_4 = 3
          fxindex1_3 = 1
          DO fxindex1 = 2, 511, 1
            fxp1_a_storage(fxlmidx1,fxindex1) = (((((c1 * fxp1_a((
     $fxlmidx0 + (-1)),fxindex1)) + (c2 * fxp1_a((fxlmidx0 + 1),
     $fxindex1))) + (c3 * fxp1_a_storage((fxlmidx1 + 
     $fxold_fxp1_a_storage),fxindex1_3))) + (c4 * fxp1_a_storage((
     $fxlmidx1 + fxold_fxp1_a_storage),fxindex1_4))) + (c5 * 
     $fxp1_a_storage(fxlmidx1,fxindex1)))
            fxindex1_4 = (fxindex1_4 + 1)
            fxindex1_3 = (fxindex1_3 + 1)
          ENDDO
          fxlmidx1 = (fxlmidx1 + 1)
          fxlmidx0 = (fxlmidx0 + 1)
        ENDDO
C     ENDLOCAL
        CALL fxcl_inita(0,1,1,fxlast0,fxlmlast0,fxcc0,1,fxadesc((
     $fxcellid + 8),1),512,1,8,fxfirst0,fxlmfirst0)
        CALL fxcl_inita(0,1,1,fxlast1,fxlmlast1,fxcc1,1,fxadesc((
     $fxcellid + 8),2),512,1,512,fxfirst1,fxlmfirst1)
        DO fxindex1 = fxlmfirst0, fxlmlast0, 1
          DO fxindex2 = fxlmfirst1, fxlmlast1, 1
            a(fxindex1,fxindex2) = fxp1_a_storage(fxindex1,fxindex2)
          ENDDO
        ENDDO
C     ENDPDO
        mytime = (mytime + timer_stop())
      ENDDO
C     PDO (x = 2:511)
C     PIN a(x,:)
C     PMERGEVARS errors
C     LOCAL
C     PINIT
      errors = 0
      fxloopstart0 = (MAX(((fxcellid * 8) + 1),2))
      fxlmidx0 = ifxlm(fxadesc,0,fxloopstart0)
      DO x = fxloopstart0, MIN(((fxcellid * 8) + 8),511), 1
C     PBODY
        DO y = 2, 511, 1
          IF (a(fxlmidx0,y).NE.1.25) THEN
            errors = (errors + 1)
          ENDIF
        ENDDO
        fxlmidx0 = (fxlmidx0 + 1)
      ENDDO
C     ENDLOCAL
C     PMERGE
      DO fxp2_mergedepth = 5, 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 = ',errors
      ENDIF
      CALL prperf(mytime,512,512,10)
      CALL fx_deinit()
      END
C     secs = (clocks)
C     secs = (secs / 2e7)
C     flops = (((((nx + (-2)) * (ny + (-2))) * 9) * iters))
C     mflops = (flops / 1e6)
C     mflops = (mflops / secs)
C     WRITE (unit=6,fmt=*) flops,'flops'
C     WRITE (unit=6,fmt=*) secs,'seconds'
C     WRITE (unit=6,fmt=*) mflops,'mflops'
C     END
      SUBROUTINE prperf(clocks,nx,ny,iters)
      REAL secs
      INTEGER fxcellid
      EXTERNAL fx_procstart
      REAL flops
      INTEGER iters
      INTEGER fxdistarg
      INTEGER nx
      INTEGER ny
      EXTERNAL fxdblcheck
      INTEGER clocks
      EXTERNAL net_reduce
      REAL mflops
      COMMON /fxcommon/ fxcellid,fxdistarg
      CALL fxdblcheck(fxdistarg,0,'prperf')
      secs = (clocks)
      secs = (secs / 2e7)
      flops = (((((nx + (-2)) * (ny + (-2))) * 9) * iters))
      mflops = (flops / 1e6)
      mflops = (mflops / secs)
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) flops,'flops'
      ENDIF
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) secs,'seconds'
      ENDIF
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) mflops,'mflops'
      ENDIF
      END
