c
c	msgcancel.f 1.4 92/07/01 15:24:02
c
c  Copyright 1991 Intel Corporation, Inc.
c  See the "Copyright" file for complete rights and liability information.
c
c  NOTE: You must invoke *killcube* after running this program
c        because the program blocks waiting for canceled message(s).
c        Until you invoke *killcube*, all subsequent *load* commands
c        produce the "load: Pid already in use" message.

      integer      iam, msgid
      character*60 msg1, msg2, msg3, msgbuf

c  Identify self.

      iam = mynode()

c  If node 0, ...

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

c    Build and send the first message.

         msg1 = 'Hello from node 0.'
         call csend(10, msg1, len(msg1), 1, mypid())
         write(*, 100) iam, msg1
100      format('Node ',i3, ' sent: ', a)

c    Build and send the second message.

         msg2 = 'Another hello from node 0.'
         call csend(11, msg2, len(msg2), 1, mypid())
         write(*, 100) iam, msg2

c    Build and send the third message.

         msg3 = 'Yet another hello from node 0.'
         msgid = isend(12, msg3, len(msg3), 1, mypid())
         write(*, 100) iam, msg3

c    Cancel and flush messages to node 1.

         call msgcancel(msgid)
         call flushmsg(-1, 1, 0)

c  If not node 0, then ...

      else

c    Receive and display the third message.

         call cprobe(12)
         call crecv(10, msgbuf, len(msgbuf))

         write(*, 200) iam, msgbuf
200      format('Node ', i3, ' received: ', a)

c    Receive and display the second message.

         call cprobe(11)
         call crecv(11, msgbuf, len(msgbuf))
         write(*, 200) iam, msgbuf

c    Receive and display the first message.

         call cprobe(10)
         call crecv(12, msgbuf, len(msgbuf))
         write(*, 200) iam, msgbuf

      endif

      end
