Next: Working with Connection Up: Programming with Collections. Previous: C++ and HPF

Interfacing HPF and pC++

Let us consider the ways in which this interface might operate:

HPF calling C++/pC++:
a.
A direct call to a C++ function from the main thread of a Fortran program. This presents no real problems that did not exist before, unless an HPF distributed array is passed as an argument.
b.
A C++ function is called as an HPF extrinsic function in a parallelized loop. Again this is only interesting if an HPF distributed array is passed as an argument.

The HPF extrinsic procedure interface which allows calls to non-HPF subprograms as extrinsic procedures may well suffice for the above two situations provided the C++ subprogram is designed to be executed on a single processor. In both cases we assume that the C++ function will not attempt to return a value of any type other than a base type like int or double. It may be possible to view a returned C++ structure as a Fortran90 instance of a user defined type, but returning a C pointer would be a big problem.
pC++ calling HPF:
a.
A call to a HPF parallel subroutine from a pC++ sequential main thread, i.e., a pC++ main program.
b.
A call to a Fortran ``node program'', i.e., a sequential or vector subroutine that is called from a parallel section of a pC++ program.

Of these we will focus on designing an interface for the case of pC++ calling Fortran. The data structure manipulation and encapsulation properties of C++ and the fast computing speed of Fortran make it natural for Fortran subroutines to be called as library routines and for C++ to act as the main controller.

Let us first consider case a. A pC++ element class which contains three arrays with two of the arrays being a special type FArrayDouble and one being a conventional C++ array is given below.


class MyElement {
  public:
   FArrayDouble x, y;
   double z[100];
   MyElement();
};
The special type FArrayDouble is used to contain double precision Fortran90 arrays and their descriptor structures. To define the constructor for the class we assume that x is a one dimensional array of a size of 100 and y is a two dimensional array of a size of .

MyElement::MyElement():x(100),y(200,50) 
{...}
To use this class in a pC++ program that calls an HPF subroutine, we need to define the Processors object and to specify the size and shape of the collection. In the following example, a one dimensional collection of a size of 64 with elements of type MyElement is constructed and an HPF subroutine, FFUN, is called.

extern "HPF" void FFUN(FArrayDouble&,
               FArrayDouble&,double*);
main(){
 Processors P(64);
 Distribution D(64,&P,BLOCK);
 Align A(64,"[ALIGN(T[i],D[i])]");
 HPFCollection<MyElement> C(&D,&A);
 FFUN(C.x,C.y,C.z);
 ...
}
The important point to consider is what the passed arguments look like in terms of HPF distributed arrays. In this case, they can be defined by the HPF directives.

!HPF$ PROCESSORS P(64)
      double precision x(100*64),
     &  y(200*64,50),z(100*64)
!HPF$ DISTRIBUTE x(BLOCK),y(BLOCK,*) ONTO P
!HPF$ DISTRIBUTE z(BLOCK) ONTO P
It is relatively easy to see how the blocked decomposition corresponds to our simple collection of array blocks. When we have a two dimensional array of virtual processors, we would have a pC++ program as below:

main(){
 Processors P(64,32);
 Distribution D(64,32,&P,BLOCK,BLOCK);
 Align A(64,32,"[ALIGN(T[i][j],D[i][j])]");
 HPFCollection<MyElement> C(&D,&A);
 FFUN(C.x,C.y,C.z);
 ...
}
In this case, the HPF function would see these structures as defined by the following sequence of directives.

!HPF$ PROCESSORS P(64,32)
      double precision x(100*64,32),
     &  y(200*64, 50*32),z(100*64,32)
!HPF$ DISTRIBUTE x(BLOCK,BLOCK) ONTO P
!HPF$ DISTRIBUTE y(BLOCK,BLOCK) ONTO P
!HPF$ DISTRIBUTE z(BLOCK,BLOCK) ONTO P
The reader will note that we have not described how to create arrays that are distributed with anything other than a BLOCK distribution and array sizes are restricted to be multiples of the processor array size. There are ways around these restrictions, but they will not be discussed here.



Next: Working with Connection Up: Programming with Collections. Previous: C++ and HPF


beckman@cica.indiana.edu
Mon Nov 21 09:49:54 EST 1994