c
c	gcolx.f 1.4 92/07/01 15:19:59
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.
c
c  This example is essentially the same as the example for gcol().
c  However, because the contribution from each node is known to have
c  the same number of elements, gcolx() is used to increase speed.

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

c  Initialize.

      count    = 0
      dpsize   = 8
      dot      = 0.0
      nbrnodes = numnodes()
      do 1, i = 1, nbrnodes
         xlen(i) = xsize*dpsize
1     continue

c  Identify self.

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

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

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

c  Each node calculates and displays its dot product.

      do 3, i = 1, xsize
         dot = dot + x(i)*x(i)
3     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 4, i = 1, xsize
         x(i) = x(i)/norm 
4     continue

c  Each node collects contributions from other node.

      call gcolx(x, xlen, y)

c  Node 0 displays the resulting vector.

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

      endif

      end
