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

      integer      iam, mtime, cnode, cpid, ccode
      character*80 indent
      data         indent/' '/

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    Kill the process on node 1.

         call killproc(1, 0)
         call waitone(1, 0, cnode, cpid, ccode)
         write(*, 100) cpid, cnode, ccode
100      format('Process ', i2, ' on node ', i2, 
     1          ' finished with completion code ', i2, '.')
         call flushmsg(-1, 1, 0)

c    Waste some more time.

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

c    Kill the process on node 2.

         call killproc(2, 0)
         call waitone(2, 0, cnode, cpid, ccode)
         write(*, 100) cpid, cnode, ccode
         call flushmsg(-1, 2, 0)

c    Waste still more time.

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

c    Kill all remaining processes (including self).

         call killproc(-1, 0)
         print *, 'Processes on remaining nodes killed.'

c  If not node 0, then display greeting in infinite loop.

      else

10       continue
         write(*, 200) indent(1:3*iam), iam
200      format(a, 'Hello from node ', i2, '.')
         goto 10

      endif

      end
