C     Fx compiler version 2.1
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(3,1,0)
C     CALL fx_gettaskid(imodid,irow,icol,ipid,iprocs)
C     CALL fx_blocksizes(istereo_x_block,istereo_x_stride,
C    $istereo_y_block,istereo_y_stride)
C     ivar = 0
C     IF (imodid.EQ.0) THEN
C     ivar = (ivar + 1)
C     ifx_target = (ifxpmod((ivar + (-1)),1) + 1)
C     CALL fx_trecv(ifx_target,ipid,iprocs,x,imain_x_block,
C    $imain_x_stride,0,4,0,1,0)
C     ifx_target = (ifxpmod((ivar + (-1)),1) + 2)
C     CALL fx_trecv(ifx_target,ipid,iprocs,y,imain_y_block,
C    $imain_y_stride,0,4,0,1,1)
C     ENDIF
C     IF (imodid.EQ.1) THEN
C     DO count = 1, 50, 1
C     ivar = (ivar + 1)
C     CALL fx_red_led_on()
C     CALL stereo(x)
C     CALL fx_all_led_off()
C     IF (count.EQ.50) THEN
C     ifx_target = ifxpmod((ivar + (-1)),1)
C     CALL fx_tsend(ifx_target,ipid,iprocs,x,istereo_x_block,
C    $istereo_x_stride,0,4,0,1,2)
C     ENDIF
C     ENDDO
C     ENDIF
C     IF (imodid.EQ.2) THEN
C     DO count = 1, 50, 1
C     ivar = (ivar + 1)
C     CALL fx_green_led_on()
C     CALL stereo(y)
C     CALL fx_all_led_off()
C     IF (count.EQ.50) THEN
C     ifx_target = ifxpmod((ivar + (-1)),1)
C     CALL fx_tsend(ifx_target,ipid,iprocs,y,istereo_y_block,
C    $istereo_y_stride,0,4,0,1,3)
C     ENDIF
C     ENDDO
C     ENDIF
C     alltime = timer_stop()
C     CALL fx_sync()
C     WRITE (unit=6,fmt=*) 'dp2.fx'
C     WRITE (unit=6,fmt=*) 'images=',50
C     WRITE (unit=6,fmt=*) 240,'x',256,' images '
C     WRITE (unit=6,fmt=*) 'clocks/image =',alltime
C     WRITE (unit=6,fmt=*) 'secs/image =',(alltime * 5e-8) / 50
C     WRITE (unit=6,fmt=*) 'images/sec =',(1. / ((alltime * 5e-8) / 
C    $50)) * 2.
C     WRITE (unit=6,fmt=*) ' '
C     END
      PROGRAM main
      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
      EXTERNAL fx_yellow_led_on
      EXTERNAL fx_procstart
      EXTERNAL fx_stoptimer
      INTEGER x
      INTEGER y
      INTEGER istereo_x_stride
      INTEGER istereo_y_stride
      EXTERNAL fx_red_led_on
      INTEGER count
      EXTERNAL fx_deinit
      INTEGER imain_x_block
      INTEGER imain_y_block
      EXTERNAL t_scatter
      INTEGER fxdistarg
      EXTERNAL fx_yellow_led_off
      EXTERNAL fx_blocksizes
      EXTERNAL fx_analyztime
      EXTERNAL fx_starttimer
      INTEGER imodid
      EXTERNAL fx_all_led_off
      EXTERNAL fx_red_led_off
      EXTERNAL msg_reduce
      INTEGER iprocs
      EXTERNAL stereo
      INTEGER ifx_target
      EXTERNAL fx_newiter
      INTEGER imain_x_stride
      INTEGER imain_y_stride
      EXTERNAL timer_stop
      INTEGER timer_stop
      INTEGER alltime
      EXTERNAL fx_init
      EXTERNAL fx_set_module_geometry
      EXTERNAL fx_addtimer
      EXTERNAL ifxpmod
      INTEGER ifxpmod
      EXTERNAL fx_sync
      EXTERNAL fx_green_led_on
      EXTERNAL fx_gettimer
      EXTERNAL fx_taskinit
      INTEGER istereo_x_block
      INTEGER istereo_y_block
      EXTERNAL timer_start
      COMMON /fxcommon/ fxcellid,fxdistarg
      CALL fx_init(fxcellid,3,1,1,0)
      CALL fx_set_module_geometry(0,0,0,8,8)
      CALL fx_set_module_geometry(1,0,0,4,8)
      CALL fx_set_module_geometry(2,4,0,4,8)
      fxdistarg = 0
      CALL timer_start()
      CALL fx_red_led_off()
      CALL fx_green_led_off()
      CALL fx_yellow_led_off()
      CALL fx_taskinit(3,1,0)
      CALL fx_gettaskid(imodid,irow,icol,ipid,iprocs)
      CALL fx_blocksizes(istereo_x_block,istereo_x_stride,
     $istereo_y_block,istereo_y_stride)
      ivar = 0
      IF (imodid.EQ.0) THEN
        ivar = (ivar + 1)
        ifx_target = (ifxpmod((ivar + (-1)),1) + 1)
        CALL fx_trecv(ifx_target,ipid,iprocs,x,imain_x_block,
     $imain_x_stride,0,4,0,1,0)
        ifx_target = (ifxpmod((ivar + (-1)),1) + 2)
        CALL fx_trecv(ifx_target,ipid,iprocs,y,imain_y_block,
     $imain_y_stride,0,4,0,1,1)
      ENDIF
      IF (imodid.EQ.1) THEN
        DO count = 1, 50, 1
          ivar = (ivar + 1)
          CALL fx_red_led_on()
          CALL stereo(x)
          CALL fx_all_led_off()
          IF (count.EQ.50) THEN
            ifx_target = ifxpmod((ivar + (-1)),1)
            CALL fx_tsend(ifx_target,ipid,iprocs,x,istereo_x_block,
     $istereo_x_stride,0,4,0,1,2)
          ENDIF
        ENDDO
      ENDIF
      IF (imodid.EQ.2) THEN
        DO count = 1, 50, 1
          ivar = (ivar + 1)
          CALL fx_green_led_on()
          CALL stereo(y)
          CALL fx_all_led_off()
          IF (count.EQ.50) THEN
            ifx_target = ifxpmod((ivar + (-1)),1)
            CALL fx_tsend(ifx_target,ipid,iprocs,y,istereo_y_block,
     $istereo_y_stride,0,4,0,1,3)
          ENDIF
        ENDDO
      ENDIF
      alltime = timer_stop()
      CALL fx_sync()
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) 'dp2.fx'
      ENDIF
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) 'images=',50
      ENDIF
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) 240,'x',256,' images '
      ENDIF
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) 'clocks/image =',alltime
      ENDIF
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) 'secs/image =',(alltime * 5e-8) / 50
      ENDIF
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) 'images/sec =',(1. / ((alltime * 5e-8)
     $ / 50)) * 2.
      ENDIF
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) ' '
      ENDIF
      CALL fx_deinit()
      END
CC    PROCESSOR (4 ,8 )
CC    TEMPLATE t1(253)
CC    ALIGN dim(I,J) WITH t1(I)
CC    ALIGN m2(I,J) WITH t1(I)
CC    ALIGN m1(I,J) WITH t1(I)
CC    ALIGN ref(I,J) WITH t1(I)
CC    DISTRIBUTE t1(BLOCK_CYCLIC(8,32))
CC    TEMPLATE t2(253)
CC    ALIGN cbd(I,J) WITH t2(I)
CC    ALIGN cbe(I,J) WITH t2(I)
CC    DISTRIBUTE t2(BLOCK_CYCLIC(8,32))
C     CALL getdata(ref,m1,m2)
C     cbe = 99999999.
C     cbd = 0
C     DO curdisp = 0, 15, 1
C     CALL gendiffimg(ref,m1,m2,dim,curdisp)
C     CALL generrorimg(dim,cbe,cbd,curdisp)
C     ENDDO
C     END
      SUBROUTINE stereo(x)
      INTEGER fxindex1
      INTEGER fxindex2
      INTEGER fxfirst0
      INTEGER fxfirst1
      INTEGER fxcellid
      INTEGER fxcc0
      INTEGER fxcc1
      EXTERNAL fx_procstart
      INTEGER fxstride0
      INTEGER fxlmlast0
      INTEGER fxstride1
      INTEGER fxlmlast1
      INTEGER fxdistarg
      EXTERNAL fxdblcheck
      INTEGER fxlmfirst0
      EXTERNAL gendiffimg
      INTEGER fxlmfirst1
      EXTERNAL msg_reduce
      EXTERNAL fxcl_inita
      EXTERNAL fxinitdesc
      EXTERNAL timer_stop
      INTEGER timer_stop
      INTEGER fxlast0
      INTEGER fxlast1
      EXTERNAL getdata
      INTEGER fxlmstride0
      INTEGER fxlmstride1
      INTEGER curdisp
      EXTERNAL generrorimg
      EXTERNAL timer_start
      INTEGER difftime(16)
      INTEGER fxcbddesc(71,2)
      INTEGER fxcbedesc(71,2)
      INTEGER fxdimdesc(71,2)
      INTEGER fxrefdesc(71,2)
      INTEGER m1(8,256)
      INTEGER m2(8,256)
      INTEGER errortime(16)
      INTEGER cbd(8,256)
      REAL cbe(8,256)
      REAL dim(8,256)
      INTEGER ref(8,256)
      INTEGER fxm1desc(71,2)
      INTEGER fxm2desc(71,2)
      INTEGER fxdistarray(6,20)
      COMMON /fxcommon/ fxcellid,fxdistarg
      CALL fxdblcheck(fxdistarg,0,'stereo')
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 32
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 256
      CALL fxinitdesc(1,2,fxdistarray,fxcbedesc)
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 32
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 256
      CALL fxinitdesc(1,2,fxdistarray,fxcbddesc)
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 32
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 256
      CALL fxinitdesc(1,2,fxdistarray,fxrefdesc)
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 32
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 256
      CALL fxinitdesc(1,2,fxdistarray,fxm1desc)
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 32
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 256
      CALL fxinitdesc(1,2,fxdistarray,fxm2desc)
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 32
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 256
      CALL fxinitdesc(1,2,fxdistarray,fxdimdesc)
C     PROCESSOR (4 ,8 )
C     TEMPLATE t1(253)
C     ALIGN dim(I,J) WITH t1(I)
C     ALIGN m2(I,J) WITH t1(I)
C     ALIGN m1(I,J) WITH t1(I)
C     ALIGN ref(I,J) WITH t1(I)
C     DISTRIBUTE t1(BLOCK_CYCLIC(8,32))
C     TEMPLATE t2(253)
C     ALIGN cbd(I,J) WITH t2(I)
C     ALIGN cbe(I,J) WITH t2(I)
C     DISTRIBUTE t2(BLOCK_CYCLIC(8,32))
      fxdistarg = 1
      CALL getdata(ref,m1,m2,fxrefdesc,fxm1desc,fxm2desc)
      CALL fxcl_inita(0,1,1,fxlast0,fxlmlast0,fxcc0,1,fxcbedesc((
     $fxcellid + 8),1),240,1,8,fxfirst0,fxlmfirst0)
      CALL fxcl_inita(0,1,1,fxlast1,fxlmlast1,fxcc1,1,fxcbedesc((
     $fxcellid + 8),2),256,1,256,fxfirst1,fxlmfirst1)
      DO fxindex1 = fxlmfirst0, fxlmlast0, 1
        DO fxindex2 = fxlmfirst1, fxlmlast1, 1
          cbe(fxindex1,fxindex2) = 99999999.
        ENDDO
      ENDDO
      CALL fxcl_inita(0,1,1,fxlast0,fxlmlast0,fxcc0,1,fxcbddesc((
     $fxcellid + 8),1),240,1,8,fxfirst0,fxlmfirst0)
      CALL fxcl_inita(0,1,1,fxlast1,fxlmlast1,fxcc1,1,fxcbddesc((
     $fxcellid + 8),2),256,1,256,fxfirst1,fxlmfirst1)
      DO fxindex1 = fxlmfirst0, fxlmlast0, 1
        DO fxindex2 = fxlmfirst1, fxlmlast1, 1
          cbd(fxindex1,fxindex2) = 0
        ENDDO
      ENDDO
      DO curdisp = 0, 15, 1
        fxdistarg = 1
        CALL gendiffimg(ref,m1,m2,dim,curdisp,fxrefdesc,fxm1desc,
     $fxm2desc,fxdimdesc,(-1))
        fxdistarg = 1
        CALL generrorimg(dim,cbe,cbd,curdisp,fxdimdesc,fxcbedesc,
     $fxcbddesc,(-1))
      ENDDO
      END
CC    PROCESSOR (4 ,8 )
CC    TEMPLATE t2(253)
CC    ALIGN dim(I,J) WITH t2(I)
CC    ALIGN m2(I,J) WITH t2(I)
CC    ALIGN m1(I,J) WITH t2(I)
CC    ALIGN ref(I,J) WITH t2(I)
CC    DISTRIBUTE t2(BLOCK_CYCLIC(8,32))
CC    NOCHECK dim,m2,m1,ref
C     PDO (i = 1:253)
C     PIN ref(i,:),m1(i,:),m2(i,:)
C     POUT dim(i,:)
C     LOCAL
C     IF (fxcellid.LT.32) THEN
C     fxloopstart0 = (MAX(((fxcellid * 8) + 1),1))
C     fxlmidx0 = ifxlm(fxdimdesc,0,fxloopstart0)
C     DO i = fxloopstart0, MIN(((fxcellid * 8) + 8),253), 1
C     DO j = 1, 256 - (curdisp * 2), 1
C     dim(i,j) = ((((ref(i,j) - m1(i,(j + curdisp))) ** 2) + ((ref(i,
C    $j) - m2(i,(j + (curdisp * 2)))) ** 2)))
C     ENDDO
C     fxlmidx0 = (fxlmidx0 + 1)
C     ENDDO
C     ENDIF
C     ENDLOCAL
C     ENDPDO
C     RETURN 
C     END
      SUBROUTINE gendiffimg(ref,m1,m2,dim,curdisp,fxrefdesc,fxm1desc,
     $fxm2desc,fxdimdesc,fxcurdispdesc)
      INTEGER fxlmidx0
      INTEGER fxcellid
      INTEGER fxloopstart0
      INTEGER i
      INTEGER j
      EXTERNAL fx_procstart
      INTRINSIC float
      REAL float
      EXTERNAL ifxlm
      INTEGER ifxlm
      INTEGER fxdistarg
      EXTERNAL fxdblcheck
      EXTERNAL msg_reduce
      EXTERNAL fxinitdesc
      EXTERNAL ifxceil
      INTEGER ifxceil
      INTEGER curdisp
      EXTERNAL fxdistcheck
      INTEGER fxdimdesc(71,2)
      INTEGER fxrefdesc(71,2)
      INTEGER m1(8,256)
      INTEGER m2(8,256)
      INTEGER fxcurdispdesc(71,1)
      REAL dim(8,256)
      INTEGER ref(8,256)
      INTEGER fxm1desc(71,2)
      INTEGER fxm2desc(71,2)
      INTEGER fxdistarray(6,20)
      COMMON /fxcommon/ fxcellid,fxdistarg
      CALL fxdblcheck(fxdistarg,1,'gendiffimg')
      fxdistarg = 0
      CALL fxdistcheck(fxcurdispdesc,0,5,'gendiffimg')
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 32
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 256
      CALL fxinitdesc(1,2,fxdistarray,fxrefdesc)
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 32
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 256
      CALL fxinitdesc(1,2,fxdistarray,fxm1desc)
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 32
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 256
      CALL fxinitdesc(1,2,fxdistarray,fxm2desc)
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 32
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 256
      CALL fxinitdesc(1,2,fxdistarray,fxdimdesc)
C     PROCESSOR (4 ,8 )
C     TEMPLATE t2(253)
C     ALIGN dim(I,J) WITH t2(I)
C     ALIGN m2(I,J) WITH t2(I)
C     ALIGN m1(I,J) WITH t2(I)
C     ALIGN ref(I,J) WITH t2(I)
C     DISTRIBUTE t2(BLOCK_CYCLIC(8,32))
C     NOCHECK dim,m2,m1,ref
C     PDO (i = 1:253)
C     PIN ref(i,:),m1(i,:),m2(i,:)
C     POUT dim(i,:)
C     LOCAL
      IF (fxcellid.LT.32) THEN
        fxloopstart0 = (MAX(((fxcellid * 8) + 1),1))
        fxlmidx0 = ifxlm(fxdimdesc,0,fxloopstart0)
        DO i = fxloopstart0, MIN(((fxcellid * 8) + 8),253), 1
          DO j = 1, 256 - (curdisp * 2), 1
            dim(fxlmidx0,j) = ((((ref(fxlmidx0,j) - m1(fxlmidx0,(j + 
     $curdisp))) ** 2) + ((ref(fxlmidx0,j) - m2(fxlmidx0,(j + (
     $curdisp * 2)))) ** 2)))
          ENDDO
          fxlmidx0 = (fxlmidx0 + 1)
        ENDDO
      ENDIF
C     ENDLOCAL
C     ENDPDO
      RETURN 
      END
CC    TEMPLATE fxp1dim_t(253)
CC    DISTRIBUTE fxp1dim_t(BLOCK_CYCLIC(8,32))
CC    ALIGN fxp1_dim(I+0:I+13,J) WITH fxp1dim_t(I)
CC    PROCESSOR (4 ,8 )
CC    TEMPLATE t2(253)
CC    ALIGN dim(I,J) WITH t2(I)
CC    DISTRIBUTE t2(BLOCK_CYCLIC(8,32))
CC    TEMPLATE t1(253)
CC    ALIGN cbd(I,J) WITH t1(I)
CC    ALIGN cbe(I,J) WITH t1(I)
CC    DISTRIBUTE t1(BLOCK_CYCLIC(8,32))
CC    NOCHECK curdisp,cbd,cbe,dim
C     flag = .TRUE.
C     PDO (i = 1:240)
C     PIN dim(i:i + 13,:)
C     PINOUT cbe(i,:),cbd(i,:)
C     fxp1_dim = dim
C     LOCAL
C     IF (fxcellid.LT.32) THEN
C     fxloopstart0 = (MAX(((fxcellid * 8) + 1),1))
C     fxlmidx1 = ifxlm(fxfxp1_dimdesc,0,fxloopstart0)
C     fxlmidx0 = ifxlm(fxcbddesc,0,fxloopstart0)
C     DO i = fxloopstart0, MIN(((fxcellid * 8) + 8),240), 1
C     PBODY
C     IF (flag) THEN
C     DO j = 1, 256, 1
C     csum(j) = 0.
C     DO k = 0, 12, 1
C     csum(j) = (csum(j) + fxp1_dim((i + k),j))
C     ENDDO
C     ENDDO
C     flag = .FALSE.
C     ENDIF
C     sum = 0.
C     DO j = 1, 7, 1
C     sum = (sum + csum(j))
C     ENDDO
C     IF (sum.LT.cbe(i,1)) THEN
C     cbe(i,1) = sum
C     cbd(i,1) = curdisp
C     ENDIF
C     DO j = 2, 7, 1
C     sum = (sum + csum((j + 6)))
C     IF (sum.LT.cbe(i,j)) THEN
C     cbe(i,j) = sum
C     cbd(i,j) = curdisp
C     ENDIF
C     ENDDO
C     DO j = 8, 250, 1
C     sum = (sum - csum((j + (-7))))
C     sum = (sum + csum((j + 6)))
C     IF (sum.LT.cbe(i,j)) THEN
C     cbe(i,j) = sum
C     cbd(i,j) = curdisp
C     ENDIF
C     ENDDO
C     DO j = 251, 256, 1
C     sum = (sum - csum((j + (-7))))
C     IF (sum.LT.cbe(i,j)) THEN
C     cbe(i,j) = sum
C     cbd(i,j) = curdisp
C     ENDIF
C     ENDDO
C     DO j = 1, 256, 1
C     csum(j) = ((csum(j) - fxp1_dim(i,j)) + fxp1_dim((i + 13),j))
C     ENDDO
C     fxlmidx1 = (fxlmidx1 + 1)
C     fxlmidx0 = (fxlmidx0 + 1)
C     ENDDO
C     ENDIF
C     ENDLOCAL
C     ENDPDO
C     RETURN 
C     END
      SUBROUTINE generrorimg(dim,cbe,cbd,curdisp,fxdimdesc,fxcbedesc,
     $fxcbddesc,fxcurdispdesc)
      INTEGER fxindex0
      INTEGER fxindex1
      EXTERNAL fxawaitmessages
      LOGICAL flag
      INTEGER fxlmidx0
      INTEGER fxlmidx1
      INTEGER fxprocessor
      EXTERNAL fxschadd
      INTEGER fxcellid
      INTEGER fxop
      INTEGER fxloopstart0
      INTEGER fxbufdataidx
      EXTERNAL ifxfloor
      INTEGER ifxfloor
      INTEGER fxbufoff0
      INTEGER i
      INTEGER j
      INTEGER k
      EXTERNAL fx_procstart
      INTEGER fxrslice0
      INTRINSIC float
      REAL float
      EXTERNAL ifxlm
      INTEGER ifxlm
      INTEGER fxdistarg
      EXTERNAL ifxschnum
      INTEGER ifxschnum
      EXTERNAL fxschnext
      INTEGER fxplr1
      INTEGER fxaddr
      EXTERNAL fxdblcheck
      EXTERNAL msg_reduce
      EXTERNAL fxinitdesc
      EXTERNAL ifxceil
      INTEGER ifxceil
      REAL sum
      EXTERNAL fxdsend
      INTEGER fxawait
      INTEGER fxidiotic3_0
      EXTERNAL fxdschclear
      EXTERNAL ifxpmod
      INTEGER ifxpmod
      INTEGER curdisp
      EXTERNAL fx_sync
      EXTERNAL fxallocinit
      INTEGER fxallocinit
      EXTERNAL fxadblk1
      INTEGER fxslice0
      REAL csum(256)
      INTEGER fxbuffer(1)
      INTEGER fxcbddesc(71,2)
      INTEGER fxcbedesc(71,2)
      INTEGER fxdimdesc(71,2)
      COMPLEX fxcbuffer(1)
      DOUBLE PRECISION fxdbuffer(1)
      LOGICAL fxlbuffer(1)
      REAL fxrbuffer(1)
      INTEGER fxcurdispdesc(71,1)
      INTEGER fxfxp1_dimdesc(71,2)
      DOUBLE COMPLEX fxdcbuffer(1)
      INTEGER cbd(8,256)
      REAL cbe(8,256)
      REAL dim(8,256)
      REAL fxp1_dim(21,256)
      INTEGER fxdistarray(6,20)
      EQUIVALENCE (fxbuffer,fxrbuffer)
      EQUIVALENCE (fxbuffer,fxlbuffer)
      EQUIVALENCE (fxbuffer,fxdbuffer)
      EQUIVALENCE (fxbuffer,fxcbuffer)
      EQUIVALENCE (fxbuffer,fxdcbuffer)
      COMMON /fxcommon/ fxcellid,fxdistarg
      CALL fxdblcheck(fxdistarg,1,'generrorimg')
      fxdistarg = 0
      fxbufoff0 = fxallocinit(fxbuffer,8236)
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 32
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 13
      fxdistarray(3,2) = 256
      CALL fxinitdesc(1,2,fxdistarray,fxfxp1_dimdesc)
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 32
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 256
      CALL fxinitdesc(1,2,fxdistarray,fxcbedesc)
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 32
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 256
      CALL fxinitdesc(1,2,fxdistarray,fxcbddesc)
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 32
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 256
      CALL fxinitdesc(1,2,fxdistarray,fxdimdesc)
C     TEMPLATE fxp1dim_t(253)
C     DISTRIBUTE fxp1dim_t(BLOCK_CYCLIC(8,32))
C     ALIGN fxp1_dim(I+0:I+13,J) WITH fxp1dim_t(I)
C     PROCESSOR (4 ,8 )
C     TEMPLATE t2(253)
C     ALIGN dim(I,J) WITH t2(I)
C     DISTRIBUTE t2(BLOCK_CYCLIC(8,32))
C     TEMPLATE t1(253)
C     ALIGN cbd(I,J) WITH t1(I)
C     ALIGN cbe(I,J) WITH t1(I)
C     DISTRIBUTE t1(BLOCK_CYCLIC(8,32))
C     NOCHECK curdisp,cbd,cbe,dim
      flag = .TRUE.
C     PDO (i = 1:240)
C     PIN dim(i:i + 13,:)
C     PINOUT cbe(i,:),cbd(i,:)
      CALL fx_sync()
      fxawait = 0
      CALL fxdschclear()
      DO fxindex0 = (-2), 0, 1
        DO fxindex1 = 0, 0, 1
          CALL fxschadd(ifxpmod((fxdimdesc(3,1) + fxindex0),32),0)
        ENDDO
      ENDDO
      DO fxindextmp = 1, ifxschnum(), 1
        CALL fxschnext(fxprocessor,fxop)
        fxbufdataidx = 4
        fxbuffer((fxbufoff0 + 1)) = 0
        fxplr1 = 0
        fxrslice0 = (MAX(((1 - fxfxp1_dimdesc((fxprocessor + 8),1))
     $ + (MAX((fxdimdesc((fxcellid + 8),1) + (-1)),0))),0))
        DO fxslice0 = MAX((((MAX(fxfxp1_dimdesc((fxprocessor + 8),1),
     $1)) + 1) - fxdimdesc((fxcellid + 8),1)),1), (MIN((((MIN((
     $fxfxp1_dimdesc((fxprocessor + 8),1) + 20),253)) + 1) - 
     $fxdimdesc((fxcellid + 8),1)),8)), 1
          CALL fxadblk1(fxbufdataidx,fxbuffer((fxbufoff0 + 
     $fxbufdataidx)),fxp1_dim((fxrslice0 + 1),(fxplr1 + 1)),dim(
     $fxslice0,1),256,84,32,(fxcellid - fxprocessor),fxbuffer((
     $fxbufoff0 + 1)))
          fxrslice0 = (fxrslice0 + 1)
        ENDDO
        IF (fxbufdataidx.GT.4) THEN
          fxbuffer((fxbufoff0 + 2)) = 84
          fxbuffer((fxbufoff0 + 3)) = 256
          CALL fxdsend(fxprocessor,fxbuffer((fxbufoff0 + 1)),(
     $fxbufdataidx + (-1)),9)
          fxawait = (fxawait + 1)
        ENDIF
      ENDDO
      CALL fxawaitmessages(fxawait)
C     LOCAL
      IF (fxcellid.LT.32) THEN
        fxloopstart0 = (MAX(((fxcellid * 8) + 1),1))
        fxlmidx1 = ifxlm(fxfxp1_dimdesc,0,fxloopstart0)
        fxlmidx0 = ifxlm(fxcbddesc,0,fxloopstart0)
        DO i = fxloopstart0, MIN(((fxcellid * 8) + 8),240), 1
C     PBODY
          IF (flag) THEN
            DO j = 1, 256, 1
              csum(j) = 0.
              DO k = 0, 12, 1
                csum(j) = (csum(j) + fxp1_dim((fxlmidx1 + k),j))
              ENDDO
            ENDDO
            flag = .FALSE.
          ENDIF
          sum = 0.
          DO j = 1, 7, 1
            sum = (sum + csum(j))
          ENDDO
          IF (sum.LT.cbe(fxlmidx0,1)) THEN
            cbe(fxlmidx0,1) = sum
            cbd(fxlmidx0,1) = curdisp
          ENDIF
          DO j = 2, 7, 1
            sum = (sum + csum((j + 6)))
            IF (sum.LT.cbe(fxlmidx0,j)) THEN
              cbe(fxlmidx0,j) = sum
              cbd(fxlmidx0,j) = curdisp
            ENDIF
          ENDDO
          DO j = 8, 250, 1
            sum = (sum - csum((j + (-7))))
            sum = (sum + csum((j + 6)))
            IF (sum.LT.cbe(fxlmidx0,j)) THEN
              cbe(fxlmidx0,j) = sum
              cbd(fxlmidx0,j) = curdisp
            ENDIF
          ENDDO
          DO j = 251, 256, 1
            sum = (sum - csum((j + (-7))))
            IF (sum.LT.cbe(fxlmidx0,j)) THEN
              cbe(fxlmidx0,j) = sum
              cbd(fxlmidx0,j) = curdisp
            ENDIF
          ENDDO
          DO j = 1, 256, 1
            csum(j) = ((csum(j) - fxp1_dim(fxlmidx1,j)) + fxp1_dim((
     $fxlmidx1 + 13),j))
          ENDDO
          fxlmidx1 = (fxlmidx1 + 1)
          fxlmidx0 = (fxlmidx0 + 1)
        ENDDO
      ENDIF
C     ENDLOCAL
C     ENDPDO
      RETURN 
      END
CC    PROCESSOR (4 ,8 )
CC    TEMPLATE t2(253)
CC    ALIGN m2(I,J) WITH t2(I)
CC    ALIGN m1(I,J) WITH t2(I)
CC    ALIGN ref(I,J) WITH t2(I)
CC    DISTRIBUTE t2(BLOCK_CYCLIC(8,32))
C     PDO (i = 1:6)
C     POUT ref(i,:),m1(i,:),m2(i,:)
C     LOCAL
C     IF (fxcellid.LT.32) THEN
C     fxloopstart0 = (MAX(((fxcellid * 8) + 1),1))
C     fxlmidx0 = ifxlm(fxm2desc,0,fxloopstart0)
C     DO i = fxloopstart0, MIN(((fxcellid * 8) + 8),6), 1
C     PBODY
C     DO j = 1, 256, 1
C     ref(i,j) = 0
C     m1(i,j) = 0
C     m2(i,j) = 0
C     ENDDO
C     fxlmidx0 = (fxlmidx0 + 1)
C     ENDDO
C     ENDIF
C     ENDLOCAL
C     ENDPDO
C     PDO (i = 1:253)
C     POUT ref(i,:),m1(i,:),m2(i,:)
C     LOCAL
C     IF (fxcellid.LT.32) THEN
C     fxloopstart0 = (MAX(((fxcellid * 8) + 1),1))
C     fxlmidx0 = ifxlm(fxm2desc,0,fxloopstart0)
C     DO i = fxloopstart0, MIN(((fxcellid * 8) + 8),253), 1
C     PBODY
C     DO j = 1, 256, 1
C     ref(i,j) = (i + j)
C     m1(i,j) = (i + j)
C     m2(i,j) = (i + j)
C     ENDDO
C     fxlmidx0 = (fxlmidx0 + 1)
C     ENDDO
C     ENDIF
C     ENDLOCAL
C     ENDPDO
C     PDO (i = 247:253)
C     POUT ref(i,:),m1(i,:),m2(i,:)
C     LOCAL
C     IF (fxcellid.LT.32) THEN
C     fxloopstart0 = (MAX(((fxcellid * 8) + 1),247))
C     fxlmidx0 = ifxlm(fxm2desc,0,fxloopstart0)
C     DO i = fxloopstart0, MIN(((fxcellid * 8) + 8),253), 1
C     PBODY
C     DO j = 1, 256, 1
C     ref(i,j) = 0
C     m1(i,j) = 0
C     m2(i,j) = 0
C     ENDDO
C     fxlmidx0 = (fxlmidx0 + 1)
C     ENDDO
C     ENDIF
C     ENDLOCAL
C     ENDPDO
C     ipos = 107
C     jpos = 97
C     PDO (i = ipos:ipos + 36)
C     POUT ref(i,:),m1(i,:),m2(i,:)
C     LOCAL
C     IF (fxcellid.LT.32) THEN
C     fxloopstart0 = (MAX(ipos,((fxcellid * 8) + 1)))
C     fxlmidx0 = ifxlm(fxm2desc,0,fxloopstart0)
C     DO i = fxloopstart0, MIN((ipos + 36),((fxcellid * 8) + 8)), 1
C     PBODY
C     DO j = jpos, jpos + 36, 1
C     ref(i,j) = (((i - ipos) + 1) + ((j - jpos) + 1))
C     m1(i,(j + 12)) = (((i - ipos) + 1) + ((j - jpos) + 1))
C     m2(i,(j + 24)) = (((i - ipos) + 1) + ((j - jpos) + 1))
C     ENDDO
C     fxlmidx0 = (fxlmidx0 + 1)
C     ENDDO
C     ENDIF
C     ENDLOCAL
C     ENDPDO
C     RETURN 
C     END
      SUBROUTINE getdata(ref,m1,m2,fxrefdesc,fxm1desc,fxm2desc)
      INTEGER fxlmidx0
      INTEGER fxcellid
      INTEGER ipos
      INTEGER jpos
      INTEGER fxloopstart0
      EXTERNAL fxinitdescck
      INTEGER i
      INTEGER j
      EXTERNAL fx_procstart
      INTRINSIC float
      REAL float
      EXTERNAL ifxlm
      INTEGER ifxlm
      INTEGER fxdistarg
      EXTERNAL fxdblcheck
      EXTERNAL msg_reduce
      EXTERNAL ifxceil
      INTEGER ifxceil
      EXTERNAL fxdistcheck
      INTEGER fxrefdesc(71,2)
      INTEGER m1(8,256)
      INTEGER m2(8,256)
      INTEGER ref(8,256)
      INTEGER fxm1desc(71,2)
      INTEGER fxm2desc(71,2)
      INTEGER fxdistarray(6,20)
      COMMON /fxcommon/ fxcellid,fxdistarg
      CALL fxdblcheck(fxdistarg,1,'getdata')
      fxdistarg = 0
      CALL fxdistcheck(fxm2desc,1,3,'getdata')
      CALL fxdistcheck(fxm1desc,1,2,'getdata')
      CALL fxdistcheck(fxrefdesc,1,1,'getdata')
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 32
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 256
      CALL fxinitdescck(1,2,fxdistarray,fxrefdesc,'ref','getdata')
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 32
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 256
      CALL fxinitdescck(1,2,fxdistarray,fxm1desc,'m1','getdata')
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 32
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 256
      CALL fxinitdescck(1,2,fxdistarray,fxm2desc,'m2','getdata')
C     PROCESSOR (4 ,8 )
C     TEMPLATE t2(253)
C     ALIGN m2(I,J) WITH t2(I)
C     ALIGN m1(I,J) WITH t2(I)
C     ALIGN ref(I,J) WITH t2(I)
C     DISTRIBUTE t2(BLOCK_CYCLIC(8,32))
C     PDO (i = 1:6)
C     POUT ref(i,:),m1(i,:),m2(i,:)
C     LOCAL
      IF (fxcellid.LT.32) THEN
        fxloopstart0 = (MAX(((fxcellid * 8) + 1),1))
        fxlmidx0 = ifxlm(fxm2desc,0,fxloopstart0)
        DO i = fxloopstart0, MIN(((fxcellid * 8) + 8),6), 1
C     PBODY
          DO j = 1, 256, 1
            ref(fxlmidx0,j) = 0
            m1(fxlmidx0,j) = 0
            m2(fxlmidx0,j) = 0
          ENDDO
          fxlmidx0 = (fxlmidx0 + 1)
        ENDDO
      ENDIF
C     ENDLOCAL
C     ENDPDO
C     PDO (i = 1:253)
C     POUT ref(i,:),m1(i,:),m2(i,:)
C     LOCAL
      IF (fxcellid.LT.32) THEN
        fxloopstart0 = (MAX(((fxcellid * 8) + 1),1))
        fxlmidx0 = ifxlm(fxm2desc,0,fxloopstart0)
        DO i = fxloopstart0, MIN(((fxcellid * 8) + 8),253), 1
C     PBODY
          DO j = 1, 256, 1
            ref(fxlmidx0,j) = (i + j)
            m1(fxlmidx0,j) = (i + j)
            m2(fxlmidx0,j) = (i + j)
          ENDDO
          fxlmidx0 = (fxlmidx0 + 1)
        ENDDO
      ENDIF
C     ENDLOCAL
C     ENDPDO
C     PDO (i = 247:253)
C     POUT ref(i,:),m1(i,:),m2(i,:)
C     LOCAL
      IF (fxcellid.LT.32) THEN
        fxloopstart0 = (MAX(((fxcellid * 8) + 1),247))
        fxlmidx0 = ifxlm(fxm2desc,0,fxloopstart0)
        DO i = fxloopstart0, MIN(((fxcellid * 8) + 8),253), 1
C     PBODY
          DO j = 1, 256, 1
            ref(fxlmidx0,j) = 0
            m1(fxlmidx0,j) = 0
            m2(fxlmidx0,j) = 0
          ENDDO
          fxlmidx0 = (fxlmidx0 + 1)
        ENDDO
      ENDIF
C     ENDLOCAL
C     ENDPDO
      ipos = 107
      jpos = 97
C     PDO (i = ipos:ipos + 36)
C     POUT ref(i,:),m1(i,:),m2(i,:)
C     LOCAL
      IF (fxcellid.LT.32) THEN
        fxloopstart0 = (MAX(ipos,((fxcellid * 8) + 1)))
        fxlmidx0 = ifxlm(fxm2desc,0,fxloopstart0)
        DO i = fxloopstart0, MIN((ipos + 36),((fxcellid * 8) + 8)), 1
C     PBODY
          DO j = jpos, jpos + 36, 1
            ref(fxlmidx0,j) = (((i - ipos) + 1) + ((j - jpos) + 1))
            m1(fxlmidx0,(j + 12)) = (((i - ipos) + 1) + ((j - jpos)
     $ + 1))
            m2(fxlmidx0,(j + 24)) = (((i - ipos) + 1) + ((j - jpos)
     $ + 1))
          ENDDO
          fxlmidx0 = (fxlmidx0 + 1)
        ENDDO
      ENDIF
C     ENDLOCAL
C     ENDPDO
      RETURN 
      END
CC    PROCESSOR (4 ,8 )
CC    TEMPLATE t1(253)
CC    ALIGN disp(I,J) WITH t1(I)
CC    DISTRIBUTE t1(BLOCK_CYCLIC(8,32))
C     WRITE (unit=6,fmt=*) 'testing data'
C     ipos = 101
C     jpos = 97
C     DO i = ipos + 10, (ipos + 26), 1
C     DO j = jpos + 10, (jpos + 26), 1
C     IF (disp(i,j).NE.12) THEN
C     WRITE (unit=6,fmt=100) i,j,12,disp(i,j)
C     ENDIF
C     ENDDO
C     ENDDO
C     DO i = 1, ipos + (-10), 1
C     DO j = 1, jpos + 70, 1
C     IF (disp(i,j).NE.0) THEN
C     WRITE (unit=6,fmt=100) i,j,0,disp(i,j)
C     ENDIF
C     ENDDO
C     ENDDO
C     DO i = 1, ipos + 46, 1
C     DO j = jpos + 70, 256, 1
C     IF (disp(i,j).NE.0) THEN
C     WRITE (unit=6,fmt=100) i,j,0,disp(i,j)
C     ENDIF
C     ENDDO
C     ENDDO
C     DO i = ipos + 46, 240, 1
C     DO j = jpos + (-10), 256, 1
C     IF (disp(i,j).NE.0) THEN
C     WRITE (unit=6,fmt=100) i,j,0,disp(i,j)
C     ENDIF
C     ENDDO
C     ENDDO
C     DO i = ipos + (-10), 240, 1
C     DO j = 1, jpos + (-10), 1
C     IF (disp(i,j).NE.0) THEN
C     WRITE (unit=6,fmt=100) i,j,0,disp(i,j)
C     ENDIF
C     ENDDO
C     ENDDO
C100  FORMAT ("Error at position (",i3,",",i3,") - expected disp ",i
C    $," but got ",i)
C     RETURN 
C     END
      SUBROUTINE testdata(disp,fxdispdesc)
      INTEGER ifxtemp0
      INTEGER fxcellid
      INTEGER ipos
      INTEGER jpos
      EXTERNAL fxinitdescck
      INTEGER i
      INTEGER j
      EXTERNAL fx_procstart
      EXTERNAL ifxlm
      INTEGER ifxlm
      INTEGER fxdistarg
      EXTERNAL ifxownsol
      INTEGER ifxownsol
      EXTERNAL fxdblcheck
      EXTERNAL msg_reduce
      EXTERNAL fxdistcheck
      EXTERNAL fxbroadcast
      EXTERNAL fxreceive_bcast
      EXTERNAL ifxowns
      INTEGER ifxowns
      INTEGER disp(8,256)
      INTEGER fxdispdesc(71,2)
      INTEGER fxdistarray(6,20)
      COMMON /fxcommon/ fxcellid,fxdistarg
      CALL fxdblcheck(fxdistarg,1,'testdata')
      fxdistarg = 0
      CALL fxdistcheck(fxdispdesc,1,1,'testdata')
      fxdistarray(1,1) = 1
      fxdistarray(2,1) = 0
      fxdistarray(3,1) = 8
      fxdistarray(4,1) = 32
      fxdistarray(5,1) = 0
      fxdistarray(6,1) = 0
      fxdistarray(3,2) = 256
      CALL fxinitdescck(1,2,fxdistarray,fxdispdesc,'disp','testdata')
C     PROCESSOR (4 ,8 )
C     TEMPLATE t1(253)
C     ALIGN disp(I,J) WITH t1(I)
C     DISTRIBUTE t1(BLOCK_CYCLIC(8,32))
      IF (fxcellid.EQ.0) THEN
        WRITE (unit=6,fmt=*) 'testing data'
      ENDIF
      ipos = 101
      jpos = 97
      DO i = ipos + 10, (ipos + 26), 1
        DO j = jpos + 10, (jpos + 26), 1
          IF (ifxowns(fxdispdesc,0,i,fxcellid).NE.0) THEN
            ifxtemp0 = disp(ifxlm(fxdispdesc,0,i),j)
            CALL fxbroadcast(ifxtemp0,1)
          ELSE
            CALL fxreceive_bcast(ifxtemp0,1)
          ENDIF
          IF (ifxtemp0.NE.12) THEN
            IF (ifxowns(fxdispdesc,0,i,fxcellid).NE.0) THEN
              ifxtemp0 = disp(ifxlm(fxdispdesc,0,i),j)
              CALL fxbroadcast(ifxtemp0,1)
            ELSE
              CALL fxreceive_bcast(ifxtemp0,1)
            ENDIF
            IF (fxcellid.EQ.0) THEN
              WRITE (unit=6,fmt=100) i,j,12,ifxtemp0
            ENDIF
          ENDIF
        ENDDO
      ENDDO
      DO i = 1, ipos + (-10), 1
        DO j = 1, jpos + 70, 1
          IF (ifxowns(fxdispdesc,0,i,fxcellid).NE.0) THEN
            ifxtemp0 = disp(ifxlm(fxdispdesc,0,i),j)
            CALL fxbroadcast(ifxtemp0,1)
          ELSE
            CALL fxreceive_bcast(ifxtemp0,1)
          ENDIF
          IF (ifxtemp0.NE.0) THEN
            IF (ifxowns(fxdispdesc,0,i,fxcellid).NE.0) THEN
              ifxtemp0 = disp(ifxlm(fxdispdesc,0,i),j)
              CALL fxbroadcast(ifxtemp0,1)
            ELSE
              CALL fxreceive_bcast(ifxtemp0,1)
            ENDIF
            IF (fxcellid.EQ.0) THEN
              WRITE (unit=6,fmt=100) i,j,0,ifxtemp0
            ENDIF
          ENDIF
        ENDDO
      ENDDO
      DO i = 1, ipos + 46, 1
        DO j = jpos + 70, 256, 1
          IF (ifxowns(fxdispdesc,0,i,fxcellid).NE.0) THEN
            ifxtemp0 = disp(ifxlm(fxdispdesc,0,i),j)
            CALL fxbroadcast(ifxtemp0,1)
          ELSE
            CALL fxreceive_bcast(ifxtemp0,1)
          ENDIF
          IF (ifxtemp0.NE.0) THEN
            IF (ifxowns(fxdispdesc,0,i,fxcellid).NE.0) THEN
              ifxtemp0 = disp(ifxlm(fxdispdesc,0,i),j)
              CALL fxbroadcast(ifxtemp0,1)
            ELSE
              CALL fxreceive_bcast(ifxtemp0,1)
            ENDIF
            IF (fxcellid.EQ.0) THEN
              WRITE (unit=6,fmt=100) i,j,0,ifxtemp0
            ENDIF
          ENDIF
        ENDDO
      ENDDO
      DO i = ipos + 46, 240, 1
        DO j = jpos + (-10), 256, 1
          IF (ifxowns(fxdispdesc,0,i,fxcellid).NE.0) THEN
            ifxtemp0 = disp(ifxlm(fxdispdesc,0,i),j)
            CALL fxbroadcast(ifxtemp0,1)
          ELSE
            CALL fxreceive_bcast(ifxtemp0,1)
          ENDIF
          IF (ifxtemp0.NE.0) THEN
            IF (ifxowns(fxdispdesc,0,i,fxcellid).NE.0) THEN
              ifxtemp0 = disp(ifxlm(fxdispdesc,0,i),j)
              CALL fxbroadcast(ifxtemp0,1)
            ELSE
              CALL fxreceive_bcast(ifxtemp0,1)
            ENDIF
            IF (fxcellid.EQ.0) THEN
              WRITE (unit=6,fmt=100) i,j,0,ifxtemp0
            ENDIF
          ENDIF
        ENDDO
      ENDDO
      DO i = ipos + (-10), 240, 1
        DO j = 1, jpos + (-10), 1
          IF (ifxowns(fxdispdesc,0,i,fxcellid).NE.0) THEN
            ifxtemp0 = disp(ifxlm(fxdispdesc,0,i),j)
            CALL fxbroadcast(ifxtemp0,1)
          ELSE
            CALL fxreceive_bcast(ifxtemp0,1)
          ENDIF
          IF (ifxtemp0.NE.0) THEN
            IF (ifxowns(fxdispdesc,0,i,fxcellid).NE.0) THEN
              ifxtemp0 = disp(ifxlm(fxdispdesc,0,i),j)
              CALL fxbroadcast(ifxtemp0,1)
            ELSE
              CALL fxreceive_bcast(ifxtemp0,1)
            ENDIF
            IF (fxcellid.EQ.0) THEN
              WRITE (unit=6,fmt=100) i,j,0,ifxtemp0
            ENDIF
          ENDIF
        ENDDO
      ENDDO
100   FORMAT ("Error at position (",i3,",",i3,") - expected disp ",i
     $," but got ",i)
      RETURN 
      END
C     iarg1 = 4
C     iarg2 = 4
C     iarg3 = 4
C     iarg4 = 4
C     END
      SUBROUTINE fx_blocksizes(iarg1,iarg2,iarg3,iarg4)
      INTEGER fxcellid
      INTEGER iarg1
      INTEGER iarg2
      INTEGER iarg3
      INTEGER iarg4
      EXTERNAL fx_procstart
      INTEGER fxdistarg
      EXTERNAL msg_reduce
      COMMON /fxcommon/ fxcellid,fxdistarg
      iarg1 = 4
      iarg2 = 4
      iarg3 = 4
      iarg4 = 4
      END
