Hi,
I just compiled my library with version 1.0 of OpenMPI and I had two problems.
First the MPI_Offset datatype is defined as a preprocessor macro as follow in mpi.h:
/* Type of MPI_Offset */
#define MPI_Offset long long
This generate a syntax error when MPI_Offset is used in C++ for what Stroustrup call a value construction (e.g. type ( expr_list ) c.f. section 6.2 in The C++ programming language).
For example the following code:
MPI_Offset ofs,size;
int nbr;
// compute ofs, size and nbr.
ofs += MPI_Offset(nbr)*size;
cannot compile if MPI_Offset is defined as it is currently.
The obvious solution is to define MPI_Offset as a typedef as follow:
/* Type of MPI_Offset */
typedef long long MPI_Offset;
Note that a similar typedef is used for MPI_Aint:
typedef long MPI_Aint;
The seccond problem is related to the C++ interface: it uses direct C-style type cast that remove constness. Since ISO/C++ have the const_cast operator especially for this situation, the compiler generates TONS of warnings (I use to compile my code with -Wall and many other warning activated) and this is really annoying.
The solution to this problem is to replace C-style cast with const_cast operator. For example the MPI::Comm::Send method defined in openmpi/ompi/mpi/cxx/comm_inln.h as follow:
inline void
MPI::Comm::Send(const void *buf, int count,
const MPI::Datatype & datatype, int dest, int tag) const
{
(void)MPI_Send((void *)buf, count, datatype, dest, tag, mpi_comm);
}
becomes:
inline void
MPI::Comm::Send(const void *buf, int count,
const MPI::Datatype & datatype, int dest, int tag) const
{
(void)MPI_Send(const_cast<void *>(buf), count, datatype, dest, tag, mpi_comm);
}
This fix the annoying warning problem because the const_cast operator is the intended method to remove constness.
Martin Audet E: matin.audet@imi.cnrc-nrc.gc.ca
Research Officer T: 450-641-5034
Industrial Material Institute
National Research Council of Canada
75 de Mortagne, Boucherville, QC, J4B 6Y4