      program qrnode
*     ** node program to do qr factorization **
      parameter (ls=150000)
      integer lda,m, n, nprocs, info, lds, nbs, start, stop
      integer me, host, iarch, iord, idir, nb, temp(2),msg(4)
      integer proc, mydone, mycols, mypanel
      double precision clock0, time1,time, mflops
      real  a(600000), s(ls) , work(300000)
      integer idata(2)
      real nflops
      character*20 filename
	real b(1024)

      common /locn/ proc, mydone, mycols, mypanel

      call open0 ( nprocs, me, host )
      call setarc0 (nprocs,iarch,iord,idir)
 21   continue
      call setarc0 (nprocs,iarch,iord,idir)
*     ** receive data from the host **
      call rcvdat(n,m,lda,nb,a)
c     print *,me,n,m,lda,nb

cddd      call checkmat(m,n,nb,lds,nbs,lda,a,s,work)
c	do 20 i = 1, m
c	b(i)= 0.0
c	do 20 j= 1, n
c	b(i)=b(i)+a(i,j)
c20	continue


*
c start the clock running


*     ** begin main iteration loop for qr decomposition **

c     call tracenode(30000,0,1)
c     call tracelevel(3,3,0)

      lds = n

      idata(1) = n
      idata(2) = nb

            time1 = clock0()
      call hgeqrf(n,m,lda,nb,a,s,work,lds,nbs,info)

      time  = clock0() - time1
      nflops = (4./3.)*n*n*n

c     call traceexit()

*     **** send data back to node 0 and compute residual ****

c        ** proc sends ending s to node 0 **

c      ** do this for error-checking purposes **
      if ((proc.ne.0).and.(proc.eq.me)) call send0(s,n*nb*4,16000,0)
      if ((me.eq.0).and.(proc.ne.me)) call recv0(s,n*nb*4,16000)

      if (nb.eq.n) then
c      ** do this for error-checking purposes **
        nb = 1
        nbs = 1
      endif

       call checkmat(m,n,nb,lds,nbs,lda,a,s,work)
        work(m*n) = -1.0 * work(m*n)
        if (me .eq. 0) then
        do 100 i=n-2,n-1
        do 100 j=n-1,n
ctst        print *,work(i*n+j)
        print *,work(i*n+j)
100     continue
        end if


      call send0(time,8,16010+me,host)




      goto 21



      end
