320. Interlanguage Communication


Up: Language Interoperability Next: Language Bindings Summary Previous: Constants

The type matching rules for communications in MPI are not changed: the datatype specification for each item sent should match, in type signature, the datatype specification used to receive this item (unless one of the types is MPI_PACKED). Also, the type of a message item should match the type declaration for the corresponding communication buffer location, unless the type is MPI_BYTE or MPI_PACKED. Interlanguage communication is allowed if it complies with these rules.


Example In the example below, a Fortran array is sent from Fortran and received in C.


! FORTRAN CODE 
REAL R(5) 
INTEGER TYPE, IERR, MYRANK, AOBLEN(1), AOTYPE(1) 
INTEGER (KIND=MPI_ADDRESS_KIND) AODISP(1) 
 
! create an absolute datatype for array R 
AOBLEN(1) = 5 
CALL MPI_GET_ADDRESS( R, AODISP(1), IERR) 
AOTYPE(1) = MPI_REAL 
CALL MPI_TYPE_CREATE_STRUCT(1, AOBLEN,AODISP,AOTYPE, TYPE, IERR) 
CALL MPI_TYPE_COMMIT(TYPE, IERR) 
 
CALL MPI_COMM_RANK( MPI_COMM_WORLD, MYRANK, IERR) 
IF (MYRANK.EQ.0) THEN 
   CALL MPI_SEND( MPI_BOTTOM, 1, TYPE, 1, 0, MPI_COMM_WORLD, IERR) 
ELSE 
   CALL C_ROUTINE(TYPE) 
END IF 

/* C code */ 
 
void C_ROUTINE(MPI_Fint *fhandle) 
{ 
   MPI_Datatype type; 
   MPI_Status status; 
    
   type = MPI_Type_f2c(*fhandle); 
    
   MPI_Recv( MPI_BOTTOM, 1, type, 0, 0, MPI_COMM_WORLD, &status); 
} 

MPI implementors may weaken these type matching rules, and allow messages to be sent with Fortran types and received with C types, and vice versa, when those types match. I.e., if the Fortran type INTEGER is identical to the C type int, then an MPI implementation may allow data to be sent with datatype MPI_INTEGER and be received with datatype MPI_INT. However, such code is not portable.



Up: Language Interoperability Next: Language Bindings Summary Previous: Constants


Return to MPI-2.1 Standard Index
Return to MPI Forum Home Page

MPI-2.0 of July 1, 2008
HTML Generated on July 6, 2008