Subject: hpff-interpret: Table lookups

From: [email-masked]
Date: Thu, 4 Jan 1996 10:54:07 -0800

---------------------------------------------------------------------------
[email-masked] is a mailing list for corrections,
clarifications, and interpretations related to High Performance Fortran.
Instructions for adding or deleting yourself from this list appear at the
bottom of this message.
---------------------------------------------------------------------------

I'm having a bit of trouble understanding how to do table lookups.
Using some information from The Book, the only thing I have been able
to come up with is to go to local space to do the actual lookup (under
the requirement of only one table/processor):

      program foo

      real, dimension(137,NUMBER_OF_PROCESSORS) :: table
      real, dimension(1024,1024) :: AA, BB

!HPF$ DISTRIBUTE (*,BLOCK(1)) :: table
!HPF$ DISTRIBUTE (BLOCK,BLOCK) :: AA, BB

      interface
         EXTRINSIC(HPF_LOCAL) subroutine lookup (AA,BB,table)
            real, dimension(:,:), intent(INOUT) :: AA
            real, dimension(:,:), intent(IN) :: BB
            real, dimension(:,:), intent(IN)  :: table
!HPF$       DISTRIBUTE (:,:) :: AA,BB,table
         end subroutine lookup
      end interface

      data table/........./

      call lookup (AA,BB,table)

      stop
      end

      EXTRINSIC(HPF_LOCAL) subroutine lookup (AA,BB,table)

            real, dimension(:,:), intent(INOUT) :: AA
            real, dimension(:,:), intent(IN) :: BB
            real, dimension(:,:), intent(IN)  :: table
!HPF$ DISTRIBUTE (:,:) :: AA,BB,table
 
      integer i,j,k
 
!HPF$ INDEPENDENT      
      do i=lbound(AA,1),ubound(AA,1)            ! 1,ubound(AA,1)
						! should be enough
        do j=lbound(AA,2), ubound(AA,2) 
          do k=lbound(table,2),ubound(table,2)  ! hopefully this == k=1,1
                                                ! so it's just here
						! for fun
             AA(i,j) = AA(i,j) + table(BB(i,j),k)
          enddo
        enddo
      enddo

      return
      end

If this (or something close to this - I am temporarily without an HPF
compiler) works, under HPF, great.  However, I would really like to
find out if there is a way to do the table lookups - one
table/processor - that will also compile under F90 on a single CPU
system.  The above example has an HPF library function
(NUMBER_OF_PROCESSORS) and the HPF EXTRINSIC syntax.

What might be a nice solution to code this for both HPF and F90 (if it
were legal syntax) would be something like:

      program foo

      integer i,j
      real, dimension(137) :: table

!  I don't think this next statement is legal syntax
!  but it would be nice if it were - treated as a comment under
!  F90, but used under HPF.  Yes - I could use something like the
!  -dlines flag to a compiler or cpp, but that depends on the
!  compiler, rather then the language
!HPF$ real, dimension(137,NUMBER_OF_PROCESSORS) :: table_align

      real, dimension(1024,1024) :: AA, BB

!HPF$ DISTRIBUTE (*,BLOCK(1)) :: table_align
 
!HPF$ ALIGN table(i) WITH table_align(i,*)

!HPF$ DISTRIBUTE (BLOCK,BLOCK) :: AA, BB

! sorry - I can't currently check if this would as intended
!HPF$ INDEPENDENT
      do i=1,1024
        do j=1,1024
          AA(i,j) = AA(i,j) + table(BB(i,j))
        enddo
      enddo
      ......
       
The short question then is - have I missed some other ways to do
table lookups?

thanks
-dave

---------------------------------------------------------------------------
To (un)subscribe to this list, send mail to
[email-masked].
Leave the subject line blank, and in the body put the line
(un)subscribe <email-address>
---------------------------------------------------------------------------

---

From: "Dr A.C. Marshall" <[email-masked]>
Date: Fri, 5 Jan 1996 10:37:31 +0000 (GMT)

In the last mail [email-masked] said:
|
|
|I'm having a bit of trouble understanding how to do table lookups.
|Using some information from The Book, the only thing I have been able
|to come up with is to go to local space to do the actual lookup (under
|the requirement of only one table/processor):
|
|      program foo
|
|      real, dimension(137,NUMBER_OF_PROCESSORS) :: table
|      real, dimension(1024,1024) :: AA, BB
|
|!HPF$ DISTRIBUTE (*,BLOCK(1)) :: table
|!HPF$ DISTRIBUTE (BLOCK,BLOCK) :: AA, BB
|
|      interface
|         EXTRINSIC(HPF_LOCAL) subroutine lookup (AA,BB,table)
|            real, dimension(:,:), intent(INOUT) :: AA
|            real, dimension(:,:), intent(IN) :: BB
|            real, dimension(:,:), intent(IN)  :: table
|!HPF$       DISTRIBUTE (:,:) :: AA,BB,table
|         end subroutine lookup
|      end interface
|
|      data table/........./
|
|      call lookup (AA,BB,table)
|
|      stop
|      end
|
|      EXTRINSIC(HPF_LOCAL) subroutine lookup (AA,BB,table)
|
|            real, dimension(:,:), intent(INOUT) :: AA
|            real, dimension(:,:), intent(IN) :: BB
|            real, dimension(:,:), intent(IN)  :: table
|!HPF$ DISTRIBUTE (:,:) :: AA,BB,table
| 
|      integer i,j,k
| 
|!HPF$ INDEPENDENT      
|      do i=lbound(AA,1),ubound(AA,1)            ! 1,ubound(AA,1)
|						! should be enough
|        do j=lbound(AA,2), ubound(AA,2) 
|          do k=lbound(table,2),ubound(table,2)  ! hopefully this == k=1,1
|                                                ! so it's just here
|						! for fun
|             AA(i,j) = AA(i,j) + table(BB(i,j),k)
|          enddo
|        enddo
|      enddo
|
|      return
|      end
|
|If this (or something close to this - I am temporarily without an HPF
|compiler) works, under HPF, great.  However, I would really like to
|find out if there is a way to do the table lookups - one
|table/processor - that will also compile under F90 on a single CPU
|system.  The above example has an HPF library function
|(NUMBER_OF_PROCESSORS) and the HPF EXTRINSIC syntax.
|
|What might be a nice solution to code this for both HPF and F90 (if it
|were legal syntax) would be something like:
|
|      program foo
|
|      integer i,j
|      real, dimension(137) :: table
|
|!  I don't think this next statement is legal syntax
|!  but it would be nice if it were - treated as a comment under
|!  F90, but used under HPF.  Yes - I could use something like the
|!  -dlines flag to a compiler or cpp, but that depends on the
|!  compiler, rather then the language

Surely you could use a couple of cpp  "#defines" for the F90 version; you
could #define NUMBER_OF_PROCESSORS to be "1" and EXTRINSIC(HPF_LOCAL) to be
a blank space (or no space at all).

Adam Marshall

-- 
                                       |
     AC Marshall                       |
     Computing Services Department,    |
     University of Liverpool,          | 
     PO Box 147.                       | 
     L69 3BX                           |
     UK                                |
     email: [email-masked]            |
     Tel:    0151-794 3722             |
     Fax:    0151-794 3759             |

     Take a look at:     HPC Info: http://www.liv.ac.uk/HPC/HPCpage.html
			 Adam Info: http://www.liv.ac.uk/~adamm/HomePage.html
---------------------------------------------------------------------------
To (un)subscribe to this list, send mail to
[email-masked].
Leave the subject line blank, and in the body put the line
(un)subscribe <email-address>
---------------------------------------------------------------------------