add advice to MPI-1 document

Steve Huss-Lederman (lederman@super.org)
Thu, 1 Jun 1995 11:47:39 -0400

I know it is late to be suggesting a change to the document, but what
I am proposing is only advice to users and not any change in the
standard. I welcome comments. If there are not serious objections I
plan to propose it at the meeting next week.

Potential coding mistake:

You have a legacy code that had the length of msgs in bytes. You know
these are actually doubles and convert the code to use MPI_DOUBLE.
You know you have to fix up the length so you do:

len_elements = len_bytes / sizeof(MPI_DOUBLE)

This will likely give you the wrong result. The reason is that
MPI_DOUBLE is actually an opaque object and what you get back is this
size (likely to be the sizeof a pointer), not the size of the
datatype. What makes this more confusing is that you can, and need
to, do sizeof(MPI_Status) and sizeof(MPI_Request) to allocate arrays
to hold status and request. These return exactly what you expect.
This mistake can lead to real bugs in code (I just found such a
mistake yesterday).

To make this clear to the user, I propose the following addition to
the MPI-1 document:

p. 19, line 13 of May 30, 1995 draft (end of section 3.2.2):

\begin{advice}
The basic datatyes in \MPI/ are stored in opaque objects. As a
result, the size of the datatype in C should be determined from the
size of the C datatype and not the \MPI/ datatype. For example,
sizeof(\type{MPI\_DOUBLE}) will likely return the size of the pointer
to the opaque object and not the desired result which is the number of
bytes of storage used by an \type{MPI\_DOUBLE}. The user should use
sizof(double) to get this information. Thus, if you have a legacy
code which used bytes as message lengths (len\_bytes) and want to
convert to the number of elements of double (len\_elements) you should
do:
$${\rm len\_elements = len\_bytes / sizeof(double)}$$
On the other hand, one can do a sizeof for MPI\_Request and
MPI\_Status to allocate arrays of requests and status as discussed
later in this chapter.
\end{advice}

See you next week.

Steve