Subject: Proposal for irregular mappings

From: Piyush Mehrotra <[email-masked]>
Date: Fri, 21 Jul 1995 09:31:20 -0400

Irregular mapping:

Proposal by:  Barbara Chapman, Piyush Mehrotra, Guy Robinson and Hans Zima

TO H309 add

	dist-format     is BLOCK ...
			or CYCLIC ....
			or *
			or INDIRECT (int-array)

	Constraint: int-array must be a one-dimensional integer array
	of size equal to the extent of the corresponding
	dimension of the array being distributed.

Here, the int-array acts as a mapping array and provides 
the processor number onto which the array element is mapped.

Thus, array element i is mapped to processor index int-array(i).

Example:

	PARAMETER (map = /1,2,4,3,3,2,1,4, ..../)
!HPF$ PROCESSORS P(4)
	REAL A(100)
        INTEGER map(100)
!HPF$ DISTRIBUTE A( INDIRECT(map) ) ONTO P

Indirect distributions using map arrays have been implemented
in the Vienna Fortran Compilation System.


Mapping of derived type components:

	Remove the first constraints under H303-311 and H312-318.

That is, a distributee or an alignee may be a subobject designator.

Add the constraint:

	Constraint:  
	If a component of a derived type is mapped
	(either through a distribute or an align statement)
	then no other component below or above it 
	in the derived type tree may be mapped.

{the above constraint needs to use more precise language
about "below" and "above" in the "derived type tree"}

Note that a subcomponent of a derived type can be declared DYNAMIC
and can be redistributed or realigned as long as the above
constraint is not violated.

Example:
! MULTI is an array of MESHes each of which has components of type GRID

    TYPE GRID
         ....
         REAL S(100)
!HPF$ DISTRIBUTE S(BLOCK)
    END TYPE GRID

    TYPE MESH
           INTEGER SIZE
           REAL RV(100,100)
           INTEGER KV(100,100)
! Both RV and KV can be distributed
!HPF$ DISTRIBUTE (BLOCK, BLOCK):: RV, KV

           TYPE(GRID) SG(100)
!Illegal:  SG cannot be distributed since a subobject (S) is already distributed
!HPF$ DISTRIBUTE SG(BLOCK)
    END TYPE MESH

    TYPE(GRID) MULTI(20)
!Illegal distribution
!HPF$ DISTRIBUTE MULTI(BLOCK)

Here, the derived type tree is as follows:

	MULTI
	  |
	  |
	MESH
	  |
	  |
	GRID

Since a subobject of GRID is distributed and subobjects of MESH
of TYPE GRID cannot be distributed. Other subobjects of MESH can
be distributed. However, MULTI cannot be distributed since
its subobjects are distributed.

Here is another example:
allocation of blocks in a multiblock code; 

!HPF$ PROCESSORS P( number_of_processors() )

     TYPE SUBGRID
          INTEGER size
          INTEGER lo, hi	! target subset of processors
          REAL, POINTER bl(:)
!HPF$ DYNAMIC bl
     END TYPE SUBGRID

     TYPE (SUBGRID), ALLOCATABLE:: grid(:)

     READ (*,*) gridnos
     ALLOCATE GRID(gridnos)

     DO i = 1, gridnos
         READ(*,*) isize
         grid(i)%size = isize
     END DO

! Computes processor subsets for each subgrid setting the lo, hi values
     CALL procs ( grid, number_of_processors()) 

! Allocate each subgrid and distribute to computed subset 
     DO i = 1, gridnos
         ALLOCATE(grid(i)%bl(isize))
!HPF$ REDISTRIBUTE  grid(i)%bl(BLOCK) ONTO P( grid(i)%lo: grid(i)%hi)
     END DO

     ....