The following function allows assignment from a C MPI-/ handle to a C++ MPI-/ handle.
MPI::<CLASS>& MPI::<CLASS>::operator=(const MPI_<CLASS>& data)
The constructor below creates a C++ MPI-/ object from a C MPI-/ handle. This allows the automatic promotion of a C MPI-/ handle to a C++ MPI-/ handle.
MPI::<CLASS>::<CLASS>(const MPI_<CLASS>& data)
// C++ library function prototype void cpp_lib_call(MPI::Comm& cpp_comm); // Exported C function prototype extern "C" { void c_interface(MPI_Comm c_comm); } void c_interface(MPI_Comm c_comm) { // the MPI_Comm (c_comm) is automatically promoted to MPI::Comm cpp_lib_call(c_comm); }
The following function allows conversion from C++ objects to C MPI-/ handles. In this case, the casting operator is overloaded to provide the functionality.
MPI::<CLASS>::operator MPI_<CLASS>() const
// C function prototype extern "C" { void c_lib_call(MPI_Comm c_comm); } void cpp_function() { // Create a C++ communicator, and initialize it with a dup of // MPI::COMM_WORLD MPI::Intracomm cpp_comm(MPI::COMM_WORLD.Dup()); c_lib_call(cpp_comm); }
It is important to note that all C++ objects and their corresponding C handles can be used interchangeably by an application. For example, an application can cache an attribute on MPI_COMM_WORLD and later retrieve it from MPI::COMM_WORLD.
MPI-Standard for MARMOT