c %Z% %M% %I% (IDS) %G%

      subroutine get_lsd_comm_rng(width, lo1, up1, jj, max_iter,
     *                            ny, ny0, nysth)

      include "slgcm.slgprm"
      include "slgcm.mp"

      integer lo1,
     &        up1,
     &        width,
     &        max_iter(2),
c
c    !!! Change Dimensions of jj to jj(imp3, max_col_p3)
c
C     &        jj(4,4),
     &         jj(imp3, max_col_p3),
     &        ny, ny0, nysth

C        integer mp_timer_clear
C        integer mp_timer_start
C        integer mp_timer_stop
C        real*8 mp_elapsed_time
C        real*8   etime

      implicit none

        integer lmax_iter(2),
     &           dist,
     &           ownp0, ownp4, i, j, tmp
  
	lmax_iter(1) = 0
        lmax_iter(2) = 0
        dist      = 0
  
          do j = lo1, up1
           do i = 1, imp3
              ownp0 = int((jj(i,j)) / width)
              ownp4 = int((jj(i,j)+4) / width)

              tmp = mod(jj(i,j), width)
              if (tmp .eq. 0) then
                 ownp0 = ownp0 -1
              else if (ownp0 .ge. ny) then
                 ownp0 = ny -1
              endif
                 
              if (mod(jj(i,j)+4, width) .eq. 0) then
                 ownp4 = ownp4 -1
              else if (ownp4 .ge. ny) then
                 ownp4 = ny -1
              endif

C
C	      Shift address of current node ny0 to 0.  
C             Thus ownp0, ownp4 will be shifted accordingly.
C             Then try to find the shortest path to the further
C             of the two in either the southerly or northerly 
C             direction.
C
		ownp4 = ownp4 - ny0
		ownp0 = ownp0 - ny0

		if (ownp4 .lt. 0) ownp4 = ny + ownp4
		if (ownp0 .lt. 0) ownp0 = ny + ownp0

                if (ownp0 .gt. ny / 2) then
    		  dist = ny - ownp0
		  if (lmax_iter(2) .lt. dist) lmax_iter(2) = dist  
                else 
		  dist = ownp0
		  if (lmax_iter(1) .lt. dist) lmax_iter(1) = dist
		endif

                if (ownp4 .gt. ny / 2) then
    		  dist = ny - ownp4
		  if (lmax_iter(2) .lt. dist) lmax_iter(2) = dist  
                else 
		  dist = ownp4
		  if (lmax_iter(1) .lt. dist) lmax_iter(1) = dist
		endif
           enddo
        enddo

C***    Timing Code 
C	tmp = mp_timer_clear(1)
C        if (tmp .eq. -1) then
C           print *, 'Failure in clearing timer'
C           stop
C        end if
C        tmp = mp_timer_start(1)
C        if (tmp .eq. -1) then
C           print *, 'Failure in starting timer'
C           stop
C        end if
C***    Timing Code 

C!        max_iter(1) = cmmd_reduce_int(lmax_iter(1), CMMD_combiner_max)
C!        max_iter(2) = cmmd_reduce_int(lmax_iter(2), CMMD_combiner_max)
        max_iter(1) = lmax_iter(1)
        max_iter(2) = lmax_iter(2)
C***    Timing Code 
C        tmp = mp_timer_stop(1)
C        if (tmp .eq. -1) then
C           print *, 'Failure in stopping timer'
C           stop
C        end if
C        etime = mp_elapsed_time(1)
C
C         print 200, ">Node : ", ny0, " , Global Comm. Time: ",
C     &             etime
 200    format (A, I4, A, E22.15.3)

C***    Timing Code 
D        print *, "L Max Iter is : ", lmax_iter(1), " (N), ", 
D     &            lmax_iter(2), " (S)", " Node : ", ny0


      end
