c
c	iprobe.f 1.4 92/07/01 15:22:15
c
c  Copyright 1991 Intel Corporation, Inc.
c  See the "Copyright" file for complete rights and liability information.

      include 'fcube.h'

      integer      done1, done2, iam, id1, id2
      integer      msgid1, msgid2, mtime
      character*80 buf1, buf2

c  Identify self.

      iam = mynode()

c  If node 0, then ...

      if(iam  .eq.  0) then
         print *,'Starting ...'

c    Waste some time.

         mtime = mclock()
1        continue
         if(mclock() .lt. mtime+50) goto 1

c    Create and send message type 1.

         buf1   = 'This is message type 1' 
         msgid1 = isend(1, buf1, len(buf1), -1, mypid())

c    Wait until message is sent and then report same.

         call msgwait(msgid1)
         write(*, 100) iam
100      format('Node ', i3, ' sent message type 1.')

c    Waste some more time.

         mtime = mclock()
2        continue
         if(mclock() .lt. mtime+100) goto 2

c    Create and send message type 2.

         buf2 = 'This is message type 2' 
         msgid2 = isend(2, buf2, len(buf2), -1, mypid())

c    Wait until message is sent and then report same.

         call msgwait(msgid2)
         write(*, 200) iam
200      format('Node ', i3, ' sent message type 2.')

c  If not node 0, then ...

      else

c    Set up loop exit condition.

         done1 = 0
         done2 = 0
         do while ((done1 .eq. 0) .or. (done2 .eq. 0))

c    Receive message type 1 if available.

         if(iprobe(1) .eq. 1) then
            call crecv(1, buf1, len(buf1))
            write(*, 300) iam
300         format('Node ', i3, ' received message type 1.')
            done1 = -1

c    Receive message type 2 if available.

         else if(iprobe(2) .eq. 1) then
            call crecv(2, buf2, len(buf2))
            write(*, 400) iam
400         format('Node ', i3, ' received message type 2.')
            done2 = -1

c    Flick if neither message is available.

         else
            write(*, 500) iam
500         format('Node ', i3, ' calling flick() ...')
            call flick()
         endif

         end do

      endif

      end
