[Mpi-forum] overloading MPI_Init etc.

Jeff Hammond jhammond at alcf.anl.gov
Sun Mar 4 20:22:40 CST 2012

I have a user who insists it is MPI-compliant to do the following:

user file mpi.h, which is included in the application with #include "mpi.h":
#include <mpi.h>


void MPI_Init(int argc, char* argv[], int& my_rank, int& mpi_size, int& Master)
  MPI::Init(argc, argv);
  my_rank = MPI::COMM_WORLD.Get_rank();
  mpi_size = MPI::COMM_WORLD.Get_size();
  Master = 0;

  std::cout << "Hello World! I am " << my_rank << " of " << mpi_size
<< std::endl;

void MPI_finalize()


I believe that it is a terrible practice, if not a violation of the
MPI standard to:
(1) define one's own mpi.h, since this may confuse the preprocessor
(or are there precedence rules in the ANSI C standard?) as to which to
include first (especially if CC=mpicc or CXX=mpicxx), and
(2) overload MPI_Init, even if one is using C++ and relying upon C++
name-mangling to avoid a symbol conflict.

The user believes that the inability to overload MPI_Init in C++ means
that MPI is not compliant with the C++ standard.



Jeff Hammond
Argonne Leadership Computing Facility
University of Chicago Computation Institute
jhammond at alcf.anl.gov / (630) 252-5381

More information about the mpi-forum mailing list