c
c	hsendrecv1.f 1.4 92/07/01 15:21:41
c
c  Copyright 1991 Intel Corporation, Inc.
c  See the "Copyright" file for complete rights and liability information.
c
c  Node 0 sends a message, posts a receive, and sets up a handler.
c  Node n receives the message and sends a reply to node 0.
c  Node 0 drops into the handler when it receives the first reply.

      include 'fcube.h'

      integer      iam
      character*30 sbuf, rbuf
      external myhandler

c  Identify self.

      iam = mynode()

c  If node 0, then ...

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

c    Send a message, post a receive, and identify a handler.

         write(sbuf, 100) iam
100      format('Hello from node ', i2)

         call hsendrecv(10, sbuf, len(sbuf), -1, mypid(),
     1                  20, rbuf, len(rbuf), myhandler)

         write(*, 200) iam, sbuf
200      format('Node ', i2, ' sent:     ', a)

c    Wait for other node(s) to complete.

         call gsync()

c    Display reply.

         write(*, 400) iam, rbuf
400      format('Node ', i2, ' received: ', a)

c    Flush any other type 20 messages to node 0.

         call flushmsg(20, 0, 0)

c  If not node 0, then...

      else

c    Receive message.

         call crecv(10, rbuf, len(rbuf))

         write(*, 400) iam, rbuf

c    Send reply.

         write(sbuf, 100) iam

         call csend(20, sbuf, len(sbuf), 0, mypid())

         write(*, 200) iam, sbuf

c    Wait for other node(s) to complete.

         call gsync()

      endif

      end
