C     Fx compiler version 2.1
CC    TEMPLATE t(512)
CC    ALIGN a(I,J,K) WITH t(J)
CC    DISTRIBUTE t(BLOCK(16))
C     CALL gen_bit_reverse_table(brt)
C     CALL gen_w_table(w)
C     CALL timer_start()
C     CALL fx_red_led_off()
C     CALL fx_green_led_off()
C     CALL fx_yellow_led_off()
C     CALL fx_taskinit(5,1,1)
C     CALL fx_gettaskid(imodid,irow,icol,ipid,iprocs)
C     CALL fx_blocksizes(icffts_a_block,icffts_a_stride,
C    $icffts_brt_block,icffts_brt_stride,icffts_w_block,
C    $icffts_w_stride,irffts_a_block,irffts_a_stride,irffts_brt_block
C    $,irffts_brt_stride,irffts_w_block,irffts_w_stride)
C     ivar = 0
C     CALL fx_starttimer()
C     IF (imodid.EQ.0) THEN
C     ivar = (ivar + 1)
C     CALL fx_newiter()
C     ifx_target = (ifxpmod((ivar + (-1)),2) + 3)
C     CALL fx_trecv(ifx_target,ipid,iprocs,a,imain_a_block,
C    $imain_a_stride,0,2097152,2097152,1)
C     ENDIF
C     IF (imodid.EQ.1) THEN
C     DO k = 1, 100, 2
C     ivar = (ivar + 1)
C     CALL fx_newiter()
C     CALL fx_red_led_on()
C     CALL fx_gettimer()
C     CALL cffts(a,brt,w)
C     CALL fx_addtimer()
C     CALL fx_all_led_off()
C     ifx_target = (ifxpmod(((ivar * 2) + (-2)),2) + 3)
C     CALL fx_tsend(ifx_target,ipid,iprocs,a,icffts_a_block,
C    $icffts_a_stride,0,2097152,2097152,1)
C     ENDDO
C     ENDIF
C     IF (imodid.EQ.2) THEN
C     DO k = 2, 100, 2
C     ivar = (ivar + 1)
C     CALL fx_newiter()
C     CALL fx_red_led_on()
C     CALL fx_gettimer()
C     CALL cffts(a,brt,w)
C     CALL fx_addtimer()
C     CALL fx_all_led_off()
C     ifx_target = (ifxpmod(((ivar * 2) + (-1)),2) + 3)
C     CALL fx_tsend(ifx_target,ipid,iprocs,a,icffts_a_block,
C    $icffts_a_stride,0,2097152,2097152,1)
C     ENDDO
C     ENDIF
C     IF (imodid.EQ.3) THEN
C     DO k = 1, 100, 2
C     ivar = (ivar + 1)
C     CALL fx_newiter()
C     ifx_target = (ifxpmod(((ivar * 2) + (-2)),2) + 1)
C     CALL fx_trecv(ifx_target,ipid,iprocs,a,irffts_a_block,
C    $irffts_a_stride,0,2097152,2097152,1)
C     CALL fx_yellow_led_on()
C     CALL fx_gettimer()
C     CALL rffts(a,brt,w)
C     CALL fx_addtimer()
C     CALL fx_all_led_off()
C     IF (k.EQ.100) THEN
C     ifx_target = ifxpmod(((ivar * 2) + (-2)),1)
C     CALL fx_tsend(ifx_target,ipid,iprocs,a,irffts_a_block,
C    $irffts_a_stride,0,2097152,2097152,1)
C     ENDIF
C     ENDDO
C     ENDIF
C     IF (imodid.EQ.4) THEN
C     DO k = 2, 100, 2
C     ivar = (ivar + 1)
C     CALL fx_newiter()
C     ifx_target = (ifxpmod(((ivar * 2) + (-1)),2) + 1)
C     CALL fx_trecv(ifx_target,ipid,iprocs,a,irffts_a_block,
C    $irffts_a_stride,0,2097152,2097152,1)
C     CALL fx_yellow_led_on()
C     CALL fx_gettimer()
C     CALL rffts(a,brt,w)
C     CALL fx_addtimer()
C     CALL fx_all_led_off()
C     IF (k.EQ.100) THEN
C     ifx_target = ifxpmod(((ivar * 2) + (-1)),1)
C     CALL fx_tsend(ifx_target,ipid,iprocs,a,irffts_a_block,
C    $irffts_a_stride,0,2097152,2097152,1)
C     ENDIF
C     ENDDO
C     ENDIF
C     CALL fx_stoptimer()
C     CALL fx_analyztime()
C     clocks = timer_stop()
C     CALL prperf(clocks,512,9,100)
C     CALL fx_sync()
C     END
      PROGRAM main
      INTEGER irffts_w_stride
      INTEGER ipid
      INTEGER icol
      INTEGER ivar
      INTEGER fxcellid
      EXTERNAL t_gather
      INTEGER irow
      REAL fxbuffer
      EXTERNAL fx_green_led_off
      EXTERNAL fx_tsend
      EXTERNAL fx_trecv
      EXTERNAL fx_gettaskid
      INTEGER icffts_brt_block
      INTEGER irffts_brt_block
      EXTERNAL fx_yellow_led_on
      INTEGER k
      EXTERNAL fx_procstart
      EXTERNAL fx_stoptimer
      EXTERNAL cffts
      INTEGER imain_a_block
      EXTERNAL rffts
      EXTERNAL fx_red_led_on
      EXTERNAL fx_deinit
      EXTERNAL t_scatter
      INTEGER fxdistarg
      EXTERNAL fx_yellow_led_off
      EXTERNAL fx_blocksizes
      EXTERNAL gen_bit_reverse_table
      EXTERNAL fx_analyztime
      INTEGER icffts_brt_stride
      EXTERNAL fx_starttimer
      INTEGER irffts_brt_stride
      INTEGER imodid
      INTEGER clocks
      EXTERNAL fx_all_led_off
      EXTERNAL fx_red_led_off
      INTEGER icffts_a_block
      EXTERNAL msg_reduce
      EXTERNAL prperf
      INTEGER iprocs
      INTEGER irffts_a_block
      INTEGER imain_a_stride
      INTEGER ifx_target
      INTEGER icffts_w_block
      EXTERNAL fxinitdesc
      EXTERNAL fx_newiter
      INTEGER irffts_w_block
      EXTERNAL timer_stop
      INTEGER timer_stop
      EXTERNAL gen_w_table
      EXTERNAL fx_init
      EXTERNAL fx_set_module_geometry
      EXTERNAL fx_addtimer
      EXTERNAL ifxpmod
      INTEGER ifxpmod
      EXTERNAL fx_sync
      EXTERNAL fx_green_led_on
      INTEGER icffts_a_stride
      EXTERNAL fx_gettimer
      EXTERNAL fx_taskinit
      INTEGER irffts_a_stride
      EXTERNAL timer_start
      INTEGER icffts_w_stride
      REAL a(512,32,2)
      REAL w(256,2)
      INTEGER brt(512)
      INTEGER fxadesc(71,3)
      INTEGER fxdistarray(6,20)
      COMMON /fxcommon/ fxcellid,fxdistarg
      CALL fx_init(fxcellid,3,1,1,1)
      CALL fx_set_module_geometry(0,0,0,8,8)
      CALL fx_set_module_geometry(1,0,0,8,2)
      CALL fx_set_module_geometry(2,0,4,8,2)
      CALL fx_set_module_geometry(3,0,2,8,2)
      CALL fx_set_module_geometry(4,0,6,8,2)
      fxdistarg = 0
C     TEMPLATE t(512)
C     ALIGN a(I,J,K) WITH t(J)
C     DISTRIBUTE t(BLOCK(16))
      fxdistarray(1,1) = 2
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 32
      fxdistarray(4,1) = 16
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 512
      fxdistarray(3,3) = 2
      CALL fxinitdesc(1,3,fxdistarray,fxadesc)
      CALL gen_bit_reverse_table(brt)
      CALL gen_w_table(w)
      CALL timer_start()
      CALL fx_red_led_off()
      CALL fx_green_led_off()
      CALL fx_yellow_led_off()
      CALL fx_taskinit(5,1,1)
      CALL fx_gettaskid(imodid,irow,icol,ipid,iprocs)
      CALL fx_blocksizes(icffts_a_block,icffts_a_stride,
     $icffts_brt_block,icffts_brt_stride,icffts_w_block,
     $icffts_w_stride,irffts_a_block,irffts_a_stride,irffts_brt_block
     $,irffts_brt_stride,irffts_w_block,irffts_w_stride)
      ivar = 0
      CALL fx_starttimer()
      IF (imodid.EQ.0) THEN
        ivar = (ivar + 1)
        CALL fx_newiter()
        ifx_target = (ifxpmod((ivar + (-1)),2) + 3)
        CALL fx_trecv(ifx_target,ipid,iprocs,a,imain_a_block,
     $imain_a_stride,0,2097152,2097152,1)
      ENDIF
      IF (imodid.EQ.1) THEN
        DO k = 1, 100, 2
          ivar = (ivar + 1)
          CALL fx_newiter()
          CALL fx_red_led_on()
          CALL fx_gettimer()
          fxdistarg = 1
          CALL cffts(a,brt,w,fxadesc,(-1),(-1))
          CALL fx_addtimer()
          CALL fx_all_led_off()
          ifx_target = (ifxpmod(((ivar * 2) + (-2)),2) + 3)
          CALL fx_tsend(ifx_target,ipid,iprocs,a,icffts_a_block,
     $icffts_a_stride,0,2097152,2097152,1)
        ENDDO
      ENDIF
      IF (imodid.EQ.2) THEN
        DO k = 2, 100, 2
          ivar = (ivar + 1)
          CALL fx_newiter()
          CALL fx_red_led_on()
          CALL fx_gettimer()
          fxdistarg = 1
          CALL cffts(a,brt,w,fxadesc,(-1),(-1))
          CALL fx_addtimer()
          CALL fx_all_led_off()
          ifx_target = (ifxpmod(((ivar * 2) + (-1)),2) + 3)
          CALL fx_tsend(ifx_target,ipid,iprocs,a,icffts_a_block,
     $icffts_a_stride,0,2097152,2097152,1)
        ENDDO
      ENDIF
      IF (imodid.EQ.3) THEN
        DO k = 1, 100, 2
          ivar = (ivar + 1)
          CALL fx_newiter()
          ifx_target = (ifxpmod(((ivar * 2) + (-2)),2) + 1)
          CALL fx_trecv(ifx_target,ipid,iprocs,a,irffts_a_block,
     $irffts_a_stride,0,2097152,2097152,1)
          CALL fx_yellow_led_on()
          CALL fx_gettimer()
          fxdistarg = 1
          CALL rffts(a,brt,w,fxadesc,(-1),(-1))
          CALL fx_addtimer()
          CALL fx_all_led_off()
          IF (k.EQ.100) THEN
            ifx_target = ifxpmod(((ivar * 2) + (-2)),1)
            CALL fx_tsend(ifx_target,ipid,iprocs,a,irffts_a_block,
     $irffts_a_stride,0,2097152,2097152,1)
          ENDIF
        ENDDO
      ENDIF
      IF (imodid.EQ.4) THEN
        DO k = 2, 100, 2
          ivar = (ivar + 1)
          CALL fx_newiter()
          ifx_target = (ifxpmod(((ivar * 2) + (-1)),2) + 1)
          CALL fx_trecv(ifx_target,ipid,iprocs,a,irffts_a_block,
     $irffts_a_stride,0,2097152,2097152,1)
          CALL fx_yellow_led_on()
          CALL fx_gettimer()
          fxdistarg = 1
          CALL rffts(a,brt,w,fxadesc,(-1),(-1))
          CALL fx_addtimer()
          CALL fx_all_led_off()
          IF (k.EQ.100) THEN
            ifx_target = ifxpmod(((ivar * 2) + (-1)),1)
            CALL fx_tsend(ifx_target,ipid,iprocs,a,irffts_a_block,
     $irffts_a_stride,0,2097152,2097152,1)
          ENDIF
        ENDDO
      ENDIF
      CALL fx_stoptimer()
      CALL fx_analyztime()
      clocks = timer_stop()
      CALL prperf(clocks,512,9,100)
      CALL fx_sync()
      CALL fx_deinit()
      END
C     nv2 = 256
C     j = 1
C     brt(1) = j
C     DO i = 2, 512, 1
C     k = nv2
C6    CONTINUE
C     IF (k.LT.j) THEN
C     j = (j - k)
C     k = (k / 2)
C     GOTO 6 
C     ENDIF
C     j = (j + k)
C     brt(i) = j
C     ENDDO
C     RETURN 
C     END
      SUBROUTINE gen_bit_reverse_table(brt)
      INTEGER fxcellid
      INTEGER i
      INTEGER j
      INTEGER k
      EXTERNAL fx_procstart
      INTEGER fxdistarg
      EXTERNAL fxdblcheck
      EXTERNAL msg_reduce
      INTEGER nv2
      INTEGER brt(512)
      COMMON /fxcommon/ fxcellid,fxdistarg
      CALL fxdblcheck(fxdistarg,0,'gen_bit_reverse_table')
      nv2 = 256
      j = 1
      brt(1) = j
      DO i = 2, 512, 1
        k = nv2
6       CONTINUE
        IF (k.LT.j) THEN
          j = (j - k)
          k = (k / 2)
          GOTO 6 
        ENDIF
        j = (j + k)
        brt(i) = j
      ENDDO
      RETURN 
      END
C     pi = 3.141592653589793
C     wr = cos((pi / 256))
C     wi = sin((pi / 256))
C     w(1,1) = 1.
C     w(1,2) = 0.
C     ptr = 1.
C     pti = 0.
C     DO i = 2, 256, 1
C     w(i,1) = ((ptr * wr) - (pti * wi))
C     w(i,2) = ((ptr * wi) + (pti * wr))
C     ptr = w(i,1)
C     pti = w(i,2)
C     ENDDO
C     RETURN 
C     END
      SUBROUTINE gen_w_table(w)
      INTEGER fxcellid
      INTEGER i
      EXTERNAL fx_procstart
      INTEGER fxdistarg
      REAL pi
      REAL wi
      REAL wr
      EXTERNAL fxdblcheck
      EXTERNAL msg_reduce
      INTRINSIC cos
      REAL cos
      INTRINSIC sin
      REAL sin
      REAL pti
      REAL ptr
      REAL w(256,2)
      COMMON /fxcommon/ fxcellid,fxdistarg
      CALL fxdblcheck(fxdistarg,0,'gen_w_table')
      pi = 3.141592653589793
      wr = cos((pi / 256))
      wi = sin((pi / 256))
      w(1,1) = 1.
      w(1,2) = 0.
      ptr = 1.
      pti = 0.
      DO i = 2, 256, 1
        w(i,1) = ((ptr * wr) - (pti * wi))
        w(i,2) = ((ptr * wi) + (pti * wr))
        ptr = w(i,1)
        pti = w(i,2)
      ENDDO
      RETURN 
      END
CC    TEMPLATE t(512)
CC    ALIGN a(I,J,K) WITH t(J)
CC    DISTRIBUTE t(BLOCK(16))
CC    NOCHECK w,brt,a
C     a = 0.
C     a(257,257,1) = 512.
C     a(257,257,2) = 512.
C     PDO (col = 1:512)
C     PIN a(:,col,:)
C     POUT a(:,col,:)
C     LOCAL
C     IF (fxcellid.LT.16) THEN
C     fxloopstart0 = (MAX(((fxcellid * 32) + 1),1))
C     fxlmidx0 = ifxlm(fxadesc,1,fxloopstart0)
C     DO col = fxloopstart0, MIN(((fxcellid * 32) + 32),512), 1
C     DO i = 1, 512, 1
C     j = brt(i)
C     IF (i.LT.j) THEN
C     tr = a(j,col,1)
C     ti = a(j,col,2)
C     a(j,col,1) = a(i,col,1)
C     a(j,col,2) = a(i,col,2)
C     a(i,col,1) = tr
C     a(i,col,2) = ti
C     ENDIF
C     ENDDO
C     ijdiff = 1
C     stride = 2
C     spowerofw = 256
C     DO stage = 1, 9, 1
C     first = 1
C     DO powerofw = 1, 256, spowerofw
C     pwr = w(powerofw,1)
C     pwi = w(powerofw,2)
C     DO i = first, 512, stride
C     j = (i + ijdiff)
C     jr = a(j,col,1)
C     ji = a(j,col,2)
C     ir = a(i,col,1)
C     ii = a(i,col,2)
C     tr = ((jr * pwr) - (ji * pwi))
C     ti = ((jr * pwi) + (ji * pwr))
C     a(j,col,1) = (ir - tr)
C     a(j,col,2) = (ii - ti)
C     a(i,col,1) = (ir + tr)
C     a(i,col,2) = (ii + ti)
C     ENDDO
C     first = (first + 1)
C     ENDDO
C     ijdiff = stride
C     stride = (stride * 2)
C     spowerofw = (spowerofw / 2)
C     ENDDO
C     fxlmidx0 = (fxlmidx0 + 1)
C     ENDDO
C     ENDIF
C     ENDLOCAL
C     ENDPDO
C     RETURN 
C     END
      SUBROUTINE cffts(a,brt,w,fxadesc,fxbrtdesc,fxwdesc)
      INTEGER fxindex1
      INTEGER fxindex2
      INTEGER fxindex3
      INTEGER fxlmidx0
      INTEGER fxfirst0
      INTEGER fxfirst1
      INTEGER fxfirst2
      INTEGER fxcellid
      INTEGER fxloopstart0
      INTEGER fxcc0
      INTEGER fxcc1
      INTEGER fxcc2
      INTEGER powerofw
      INTEGER i
      INTEGER j
      EXTERNAL fx_procstart
      INTEGER fxstride0
      INTEGER fxlmlast0
      INTEGER fxstride1
      INTEGER fxlmlast1
      INTEGER fxstride2
      INTEGER fxlmlast2
      INTEGER stage
      INTRINSIC float
      REAL float
      EXTERNAL ifxlm
      INTEGER ifxlm
      INTEGER first
      INTEGER fxdistarg
      INTEGER spowerofw
      REAL ii
      REAL ji
      INTEGER ijdiff
      REAL ir
      REAL ti
      REAL jr
      REAL tr
      EXTERNAL fxdblcheck
      INTEGER fxlmfirst0
      INTEGER fxlmfirst1
      INTEGER fxlmfirst2
      INTEGER stride
      EXTERNAL msg_reduce
      EXTERNAL fxcl_inita
      EXTERNAL fxinitdesc
      INTEGER fxlast0
      INTEGER fxlast1
      INTEGER fxlast2
      INTEGER col
      REAL pwi
      INTEGER fxlmstride0
      INTEGER fxlmstride1
      EXTERNAL ifxceil
      INTEGER ifxceil
      INTEGER fxlmstride2
      REAL pwr
      EXTERNAL ifxowns
      INTEGER ifxowns
      REAL a(512,32,2)
      REAL w(256,2)
      INTEGER fxbrtdesc(71,1)
      INTEGER brt(512)
      INTEGER fxadesc(71,3)
      INTEGER fxwdesc(71,2)
      INTEGER fxdistarray(6,20)
      COMMON /fxcommon/ fxcellid,fxdistarg
      CALL fxdblcheck(fxdistarg,1,'cffts')
      fxdistarg = 0
C     TEMPLATE t(512)
C     ALIGN a(I,J,K) WITH t(J)
C     DISTRIBUTE t(BLOCK(16))
C     NOCHECK w,brt,a
      fxdistarray(1,1) = 2
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 32
      fxdistarray(4,1) = 16
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 512
      fxdistarray(3,3) = 2
      CALL fxinitdesc(1,3,fxdistarray,fxadesc)
      CALL fx_procstart()
      CALL fxcl_inita(0,1,1,fxlast0,fxlmlast0,fxcc0,1,fxadesc((
     $fxcellid + 8),1),512,1,512,fxfirst0,fxlmfirst0)
      CALL fxcl_inita(0,1,1,fxlast1,fxlmlast1,fxcc1,1,fxadesc((
     $fxcellid + 8),2),512,1,32,fxfirst1,fxlmfirst1)
      CALL fxcl_inita(0,1,1,fxlast2,fxlmlast2,fxcc2,1,fxadesc((
     $fxcellid + 8),3),2,1,2,fxfirst2,fxlmfirst2)
      DO fxindex1 = fxlmfirst0, fxlmlast0, 1
        DO fxindex2 = fxlmfirst1, fxlmlast1, 1
          DO fxindex3 = fxlmfirst2, fxlmlast2, 1
            a(fxindex1,fxindex2,fxindex3) = 0.
          ENDDO
        ENDDO
      ENDDO
      IF (ifxowns(fxadesc,1,257,fxcellid).NE.0) THEN
        a(257,ifxlm(fxadesc,1,257),1) = 512.
      ENDIF
      IF (ifxowns(fxadesc,1,257,fxcellid).NE.0) THEN
        a(257,ifxlm(fxadesc,1,257),2) = 512.
      ENDIF
C     PDO (col = 1:512)
C     PIN a(:,col,:)
C     POUT a(:,col,:)
C     LOCAL
      IF (fxcellid.LT.16) THEN
        fxloopstart0 = (MAX(((fxcellid * 32) + 1),1))
        fxlmidx0 = ifxlm(fxadesc,1,fxloopstart0)
        DO col = fxloopstart0, MIN(((fxcellid * 32) + 32),512), 1
          DO i = 1, 512, 1
            j = brt(i)
            IF (i.LT.j) THEN
              tr = a(j,fxlmidx0,1)
              ti = a(j,fxlmidx0,2)
              a(j,fxlmidx0,1) = a(i,fxlmidx0,1)
              a(j,fxlmidx0,2) = a(i,fxlmidx0,2)
              a(i,fxlmidx0,1) = tr
              a(i,fxlmidx0,2) = ti
            ENDIF
          ENDDO
          ijdiff = 1
          stride = 2
          spowerofw = 256
          DO stage = 1, 9, 1
            first = 1
            DO powerofw = 1, 256, spowerofw
              pwr = w(powerofw,1)
              pwi = w(powerofw,2)
              DO i = first, 512, stride
                j = (i + ijdiff)
                jr = a(j,fxlmidx0,1)
                ji = a(j,fxlmidx0,2)
                ir = a(i,fxlmidx0,1)
                ii = a(i,fxlmidx0,2)
                tr = ((jr * pwr) - (ji * pwi))
                ti = ((jr * pwi) + (ji * pwr))
                a(j,fxlmidx0,1) = (ir - tr)
                a(j,fxlmidx0,2) = (ii - ti)
                a(i,fxlmidx0,1) = (ir + tr)
                a(i,fxlmidx0,2) = (ii + ti)
              ENDDO
              first = (first + 1)
            ENDDO
            ijdiff = stride
            stride = (stride * 2)
            spowerofw = (spowerofw / 2)
          ENDDO
          fxlmidx0 = (fxlmidx0 + 1)
        ENDDO
      ENDIF
C     ENDLOCAL
C     ENDPDO
      RETURN 
      END
CC    TEMPLATE t(512)
CC    ALIGN a(I,J,K) WITH t(I)
CC    DISTRIBUTE t(BLOCK(16))
CC    NOCHECK a,w,brt
C     PDO (row = 1:512)
C     PIN a(row,:,:)
C     POUT a(row,:,:)
C     LOCAL
C     IF (fxcellid.LT.16) THEN
C     fxloopstart0 = (MAX(((fxcellid * 32) + 1),1))
C     fxlmidx0 = ifxlm(fxadesc,0,fxloopstart0)
C     DO row = fxloopstart0, MIN(((fxcellid * 32) + 32),512), 1
C     j = 1
C     DO i = 1, 512, 1
C     j = brt(i)
C     IF (i.LT.j) THEN
C     tr = a(row,j,1)
C     ti = a(row,j,2)
C     a(row,j,1) = a(row,i,1)
C     a(row,j,2) = a(row,i,2)
C     a(row,i,1) = tr
C     a(row,i,2) = ti
C     ENDIF
C     ENDDO
C     ijdiff = 1
C     stride = 2
C     spowerofw = 256
C     DO stage = 1, 9, 1
C     first = 1
C     DO powerofw = 1, 256, spowerofw
C     pwr = w(powerofw,1)
C     pwi = w(powerofw,2)
C     DO i = first, 512, stride
C     j = (i + ijdiff)
C     jr = a(row,j,1)
C     ji = a(row,j,2)
C     ir = a(row,i,1)
C     ii = a(row,i,2)
C     tr = ((jr * pwr) - (ji * pwi))
C     ti = ((jr * pwi) + (ji * pwr))
C     a(row,j,1) = (ir - tr)
C     a(row,j,2) = (ii - ti)
C     a(row,i,1) = (ir + tr)
C     a(row,i,2) = (ii + ti)
C     ENDDO
C     first = (first + 1)
C     ENDDO
C     ijdiff = stride
C     stride = (stride * 2)
C     spowerofw = (spowerofw / 2)
C     ENDDO
C     fxlmidx0 = (fxlmidx0 + 1)
C     ENDDO
C     ENDIF
C     ENDLOCAL
C     ENDPDO
C     epsilon = 1e-4
C     errors = 0
C     PDO (i = 1:512)
C     PIN a(i,:,:)
C     LOCAL
C     IF (fxcellid.LT.16) THEN
C     fxloopstart0 = (MAX(((fxcellid * 32) + 1),1))
C     fxlmidx0 = ifxlm(fxadesc,0,fxloopstart0)
C     DO i = fxloopstart0, MIN(((fxcellid * 32) + 32),512), 1
C     sign = 1
C     IF (((i / 2) * 2).EQ.i) sign = (-1)
C     DO j = 1, 512, 1
C     IF (a(i,j,1).GT.((sign * 512) + epsilon)) errors = (errors + 1)
C     IF (a(i,j,1).LT.((sign * 512) - epsilon)) errors = (errors + 1)
C     IF (a(i,j,2).GT.((sign * 512) + epsilon)) errors = (errors + 1)
C     IF (a(i,j,2).LT.((sign * 512) - epsilon)) errors = (errors + 1)
C     sign = ( -sign)
C     ENDDO
C     fxlmidx0 = (fxlmidx0 + 1)
C     ENDDO
C     ENDIF
C     ENDLOCAL
C     ENDPDO
C     IF (errors.GT.0) WRITE (unit=6,fmt=*) 'errors = ',errors
C     RETURN 
C     END
      SUBROUTINE rffts(a,brt,w,fxadesc,fxbrtdesc,fxwdesc)
      INTEGER fxlmidx0
      INTEGER sign
      INTEGER fxcellid
      INTEGER fxloopstart0
      INTEGER powerofw
      INTEGER i
      INTEGER j
      EXTERNAL fx_procstart
      INTEGER stage
      INTRINSIC float
      REAL float
      EXTERNAL ifxlm
      INTEGER ifxlm
      INTEGER first
      INTEGER fxdistarg
      INTEGER spowerofw
      REAL ii
      REAL ji
      INTEGER ijdiff
      REAL ir
      REAL ti
      REAL jr
      REAL tr
      EXTERNAL fxdblcheck
      INTEGER stride
      EXTERNAL msg_reduce
      INTEGER errors
      EXTERNAL fxinitdesc
      REAL pwi
      EXTERNAL ifxceil
      INTEGER ifxceil
      INTEGER row
      REAL pwr
      REAL epsilon
      REAL a(32,512,2)
      REAL w(256,2)
      INTEGER fxbrtdesc(71,1)
      INTEGER brt(512)
      INTEGER fxadesc(71,3)
      INTEGER fxwdesc(71,2)
      INTEGER fxdistarray(6,20)
      COMMON /fxcommon/ fxcellid,fxdistarg
      CALL fxdblcheck(fxdistarg,1,'rffts')
      fxdistarg = 0
C     TEMPLATE t(512)
C     ALIGN a(I,J,K) WITH t(I)
C     DISTRIBUTE t(BLOCK(16))
C     NOCHECK a,w,brt
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 32
      fxdistarray(4,1) = 16
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 512
      fxdistarray(3,3) = 2
      CALL fxinitdesc(1,3,fxdistarray,fxadesc)
      CALL fx_procstart()
C     PDO (row = 1:512)
C     PIN a(row,:,:)
C     POUT a(row,:,:)
C     LOCAL
      IF (fxcellid.LT.16) THEN
        fxloopstart0 = (MAX(((fxcellid * 32) + 1),1))
        fxlmidx0 = ifxlm(fxadesc,0,fxloopstart0)
        DO row = fxloopstart0, MIN(((fxcellid * 32) + 32),512), 1
          j = 1
          DO i = 1, 512, 1
            j = brt(i)
            IF (i.LT.j) THEN
              tr = a(fxlmidx0,j,1)
              ti = a(fxlmidx0,j,2)
              a(fxlmidx0,j,1) = a(fxlmidx0,i,1)
              a(fxlmidx0,j,2) = a(fxlmidx0,i,2)
              a(fxlmidx0,i,1) = tr
              a(fxlmidx0,i,2) = ti
            ENDIF
          ENDDO
          ijdiff = 1
          stride = 2
          spowerofw = 256
          DO stage = 1, 9, 1
            first = 1
            DO powerofw = 1, 256, spowerofw
              pwr = w(powerofw,1)
              pwi = w(powerofw,2)
              DO i = first, 512, stride
                j = (i + ijdiff)
                jr = a(fxlmidx0,j,1)
                ji = a(fxlmidx0,j,2)
                ir = a(fxlmidx0,i,1)
                ii = a(fxlmidx0,i,2)
                tr = ((jr * pwr) - (ji * pwi))
                ti = ((jr * pwi) + (ji * pwr))
                a(fxlmidx0,j,1) = (ir - tr)
                a(fxlmidx0,j,2) = (ii - ti)
                a(fxlmidx0,i,1) = (ir + tr)
                a(fxlmidx0,i,2) = (ii + ti)
              ENDDO
              first = (first + 1)
            ENDDO
            ijdiff = stride
            stride = (stride * 2)
            spowerofw = (spowerofw / 2)
          ENDDO
          fxlmidx0 = (fxlmidx0 + 1)
        ENDDO
      ENDIF
C     ENDLOCAL
C     ENDPDO
      epsilon = 1e-4
      errors = 0
C     PDO (i = 1:512)
C     PIN a(i,:,:)
C     LOCAL
      IF (fxcellid.LT.16) THEN
        fxloopstart0 = (MAX(((fxcellid * 32) + 1),1))
        fxlmidx0 = ifxlm(fxadesc,0,fxloopstart0)
        DO i = fxloopstart0, MIN(((fxcellid * 32) + 32),512), 1
          sign = 1
          IF (((i / 2) * 2).EQ.i) THEN
            sign = (-1)
          ENDIF
          DO j = 1, 512, 1
            IF (a(fxlmidx0,j,1).GT.((sign * 512) + epsilon)) THEN
              errors = (errors + 1)
            ENDIF
            IF (a(fxlmidx0,j,1).LT.((sign * 512) - epsilon)) THEN
              errors = (errors + 1)
            ENDIF
            IF (a(fxlmidx0,j,2).GT.((sign * 512) + epsilon)) THEN
              errors = (errors + 1)
            ENDIF
            IF (a(fxlmidx0,j,2).LT.((sign * 512) - epsilon)) THEN
              errors = (errors + 1)
            ENDIF
            sign = ( -sign)
          ENDDO
          fxlmidx0 = (fxlmidx0 + 1)
        ENDDO
      ENDIF
C     ENDLOCAL
C     ENDPDO
      IF (errors.GT.0) THEN
        IF (fxcellid.EQ.0) THEN
          WRITE (unit=6,fmt=*) 'errors = ',errors
        ENDIF
      ENDIF
      RETURN 
      END
C     secs = (clocks)
C     secs = (secs / 2e7)
C     butterflies = ((((nn * nn) * mm) * it))
C     flops = (butterflies * 10)
C     mflops = (flops / 1e6)
C     mflops = (mflops / secs)
C     WRITE (unit=6,fmt=*) 'floating operations =',flops
C     WRITE (unit=6,fmt=*) 'time (in seconds) =',secs
C     WRITE (unit=6,fmt=*) 'Megaflops =',mflops
C     END
      SUBROUTINE prperf(clocks,nn,mm,it)
      REAL secs
      INTEGER fxcellid
      EXTERNAL fx_procstart
      REAL flops
      INTEGER fxdistarg
      INTEGER mm
      INTEGER nn
      INTEGER it
      EXTERNAL fxdblcheck
      INTEGER clocks
      EXTERNAL msg_reduce
      REAL mflops
      REAL butterflies
      COMMON /fxcommon/ fxcellid,fxdistarg
      CALL fxdblcheck(fxdistarg,0,'prperf')
      secs = (clocks)
      secs = (secs / 2e7)
      butterflies = ((((nn * nn) * mm) * it))
      flops = (butterflies * 10)
      mflops = (flops / 1e6)
      mflops = (mflops / secs)
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) 'floating operations =',flops
      ENDIF
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) 'time (in seconds) =',secs
      ENDIF
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) 'Megaflops =',mflops
      ENDIF
      END
C     iarg1 = 65536
C     iarg2 = 1048576
C     iarg3 = 2048
C     iarg4 = 2048
C     iarg5 = 2048
C     iarg6 = 2048
C     iarg7 = 128
C     iarg8 = 2048
C     iarg9 = 2048
C     iarg10 = 2048
C     iarg11 = 2048
C     iarg12 = 2048
C     END
      SUBROUTINE fx_blocksizes(iarg1,iarg2,iarg3,iarg4,iarg5,iarg6,
     $iarg7,iarg8,iarg9,iarg10,iarg11,iarg12)
      INTEGER fxcellid
      INTEGER iarg1
      INTEGER iarg2
      INTEGER iarg3
      INTEGER iarg4
      INTEGER iarg5
      INTEGER iarg6
      INTEGER iarg7
      INTEGER iarg8
      INTEGER iarg9
      EXTERNAL fx_procstart
      INTEGER iarg10
      INTEGER iarg11
      INTEGER iarg12
      INTEGER fxdistarg
      EXTERNAL msg_reduce
      COMMON /fxcommon/ fxcellid,fxdistarg
      iarg1 = 65536
      iarg2 = 1048576
      iarg3 = 2048
      iarg4 = 2048
      iarg5 = 2048
      iarg6 = 2048
      iarg7 = 128
      iarg8 = 2048
      iarg9 = 2048
      iarg10 = 2048
      iarg11 = 2048
      iarg12 = 2048
      END
