c
c	gxhigh.f 1.4 92/07/01 15:20:52
c
c  Copyright 1991 Intel Corporation, Inc.
c  See the "Copyright" file for complete rights and liability information.
c
c  Determines the minimum and maximum values across all nodes.
c
c  The gdhigh() and gshigh() calls work similarly to gihigh().
c  The gdlow() and gslow() calls work similarly to gilow().

      integer*4 iam, max, maxval, min, minval, size, seed, work 
      parameter (size = 10)
      integer   list(size) 

c  Identify self.

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

c  Each node creates list of random integers in the range 0..100.

      seed = (2 * mclock()/(iam+1)) + 1
      do 1, i = 1, size
         list(i) = int(100*ran(seed))
1     continue

      write(*, 100) iam, (list(i), i = 1, size)
100   format('List for node ', i3, ' is: ', 10i4)

c  Each node finds smallest and largest values in its list.

      min = 1 
      max = 1 
      do 2, i = 2, size 
         if(list(i) .gt. list(max)) max = i 
         if(list(i) .lt. list(min)) min = i 
2     continue 
      minval = list(min) 
      maxval = list(max) 

c  Each node finds smallest and largest values across all nodes.

      call gilow(minval, 1, work) 
      call gihigh(maxval, 1, work) 

c  Node 0 displays global minimum and maximum values.

      if(iam .eq. 0) write(*, 200) minval, maxval
200   format('Minimum value is ', i4, /, 'Maximum value is ', i4)

      end
