c
c	gsync.f 1.5 92/07/01 09:22:14
c
c  Copyright 1991 Intel Corporation, Inc.
c  See the "Copyright" file for complete rights and liability information.
c
c  Requires at least a two-node cube.  Node 0 creates and writes to the file;
c  other nodes read from it.
c
c  Note:  To ensure that the cfs file "/cfs/mydata" exists in a
c         known state, load the program in the file "myfile.f" first.

      include 'fcube.h'

      integer      iam
      character*13 sbuf, rbuf

c  Open existing file.

      open(unit = 12, file = '/cfs/mydata',
     1     status = 'old', form = 'unformatted')

c  Set I/O mode for individual file pointers.

      call setiomode(12, 0)

c  Identify self.

      iam = mynode()

c  If node 0, then ...

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

c    Write to the file.

         sbuf = 'Hello, world!'
         call cwrite(12, 'Hello, world!', 13)

         write(*, 100) iam, sbuf
100      format('Node ',i3, ' wrote: ', a13)

c    Force other nodes to wait for the write to complete.

         call gsync()

c  If not node 0, then ...

      else

c    Wait for the write to complete.

         call gsync()

c    Read the file.

         call cread(12, rbuf, 13)

c    Display the data.

         write(*, 130) iam, rbuf
130      format('Node ', i3, ' read:  ', a13)

      endif

      end
