Mixed language inter-operability

(no name) (Andrew.Lumsdaine@nd.edu)
Wed, 1 May 1996 07:52:21 -0500 (EST)

An issue came up during the bindings discussion at the recent MPI
Forum meeting about mixed language inter-operability. In particular,
it was suggested that it might be useful to be able to re-use C
structures as C++ classes -- implying that the C++ classes defined for
the C++ bindings could not have virtual member functions.

There are two issues regarding mixed-language programming that need to
be addressed, namely the user interface (the MPI API) aspect as well
as the implementor aspect.

For the API issue, if I understand the discussion from the meeting
correctly, what is desired is to be able to call C MPI-based library
functions directly from a C++ program. For example, a C++ program
might look like

...

MPI_Comm a(MPI_COMM_WORLD);

CLib_call(a, arg1, arg2, arg3);
...

Here, CLib_call is assumed to be a library function, written in C,
that uses the C bindings for MPI -- with the MPI_comm that is passed
in.

It seems to me that we cannot mandate that this must work. The C++
bindings do mandate that MPI_Comm (for instance) be an object, but the
C bindings only mandate that MPI_Comm be a handle. If that handle
were guaranteed to be a pointer to a structure, then the above could
be mandated, but handles, even in C, may be integers -- as is the case
with the IBM implementation of MPI.

Therefore, we have the following alternative proposal. The C++
MPI classes must have a member function that returns the equivalent C
handle. Similarly, it should have a member function that returns the
equivalent Fortran handle (I gag as I write this).

The example above would thus look like

...

MPI_Comm a(MPI_COMM_WORLD);

CLib_call(a.C_handle, arg1, arg2, arg3);
...

Now, the second issue has to do with implementing the C++ bindings.
Here, again it would be nice for structure and classes to be easily
translated so that code can be reused and so forth. A better
approach, IMHO, would be to perhaps derive the C++ classes from
whatever internal C structures may be lurking about. Among other
things, the C_handle() member function above would be trivially
realizable in many cases. More importantly, the C++ bindings could
be realized as a thin layer on top of the C bindings or on top of
whatever the C bindings are layered on top of.

Cheers,
Andrew Lumsdaine