c
c	numnodes.f 1.4 92/07/01 15:25:10
c
c  Copyright 1991 Intel Corporation, Inc.
c  See the "Copyright" file for complete rights and liability information.
c
c  An eight-element vector is distributed over a two-node
c  cube (as four elements per node).  Each node:
c     *  calculates the normalized dot product of its portion, and
c     *  collects the contributions from the other node.
c  Finally, node 0 displays the resulting vector.

      integer          count, dpsize, iam, xsize, ysize, nbrnodes
      parameter        (xsize = 4)
      parameter        (ysize = 16)
      double precision x(xsize), y(ysize), dot, norm, work
      character*80     msg

c  Initialize.

      count    = 0
      dpsize   = 8
      dot      = 0.0
      nbrnodes = numnodes()

c  Identify self.

      iam = mynode()

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

c  Each node creates and displays its four-element vector.

      do 1, i = 1, xsize
         x(i) = iam * (xsize) + i-1
         write(*, 100) iam, i, x(i)
100      format('Node ', i1, ' x(', i1, ') = ', f3.1)
1     continue

c  Each node calculates and displays its dot product.

      do 2, i = 1, xsize
         dot = dot + x(i)*x(i)
2     continue
      write(*, 200) iam, dot
200   format('Node ', i1, ' dot = ', f10.6)

c  Each node sums the dot products of all nodes.

      call gdsum(dot, 1, work)

c  Node 0 displays the resulting dot product.

      if(iam .eq. 0) write(*, 300) dot
300   format('dot = ', f10.6)

c  Each node normalizes its dot products.

      norm = dsqrt(dot)
      do 3, i = 1, xsize
         x(i) = x(i)/norm 
3     continue

c  Each node collects contributions from other node.

      call gcol(x, xsize*dpsize, y, nbrnodes*xsize*dpsize, count)

c  Node 0 displays the resulting vector.

      if(iam .eq. 0) then
         do 4, i = 1, nbrnodes*xsize
            write(*, 400) i, y(i)
400         format('y(', i1, ') = ', f3.1)
4        continue

      endif

      end
