      PROGRAM HOST
      IMPLICIT NONE
         
      include 'defn.h'

*
*     Host program for distributed memory BLOCK LU
*     Runs on iPSC/860 at Rice University
*
*     -- NPAC, Syracuse University --
*     Manish Parashar
*     April 1992
*
*     .. Local Variables ...
      integer lda, n, m, nb
      integer numpanels
      integer nodes, me, host
      integer msg(4)
      integer HostMsgType, TimeMsgType
      integer i,dummy
      double precision time, mflops, max_time

      integer nprob(10)
      integer nprocs(5)
      integer npanels(8)
c     integer ip, ia, ib
      integer userinput, j

c     character*22 tracefile

      data HostMsgType /2100/
      data TimeMsgType /2200/
      data nprocs /2,4,8,16,32/
      data nprob /64, 128, 256, 512, 1024, 1536, 1792, 2048, 2560, 3072/
      data npanels /2,4,8,10,12,16,32,64/
	
      nodes = max_procs
 100  j = UserInput(lda,nb,nodes)
      if (j .le. 0) goto 200

      call open0 ( nodes, me, host )
      call load0 ( 'node', -1)
      call setarc0 (nodes, 3, 0, 1)

c     do ip=2,2,-1
c       nodes = nprocs(ip)

c       print *, ' TOPOLOGY:  UNIDIRECTIONAL RING '

c       do ia=1,6
c         lda = nprob(ia)
	  n = lda
	  m = lda

c         do ib=1,7
c	    nb = npanels(ib)
            numpanels = (n+nb-1)/nb
            print *,'Experiment: ',m*n, m,n,nodes,nb

c	    call makefilename(tracefile,'SAXPY',m,n,nodes,nb)
c           call traceenable(tracefile,0)

            call setarc0 (nodes, 3, 0, 1)
*           ** broadcast n, m, lda, nb to the nodes **
            msg(1) = n
            msg(2) = m
            msg(3) = lda
            msg(4) = nb

            call bcast0 (msg,16,HostMsgType,host)

*           receive timing back from node 0 **

	    max_time = 0.0

            do i=0,nodes-1
               call recv0(time,8,TimeMsgType+i)
               if (max_time .lt. time) then
                    max_time = time
               end if
             end do
             mflops = ((2./3.)*LDA*LDA*LDA)/(1.0e6*max_time)
             print *,'Result:',nodes,lda,nb,max_time,mflops

             call recv0(dummy,4,HostMsgType)
          
c          end do

c       end do

c     end do

      call close0(1)

      goto 100

200   end
