Skip to content

pythonizing simple example

Jeff Squyres edited this page Nov 24, 2019 · 3 revisions

Pythonizing: Simple Example

The Pythonization process is best shown through an example. Here's is a snipit of the point-to-point .tex file -- with a little surrounding LaTeX, just for context:

The syntax of the blocking send operation is given below.

\cdeclmainindex{MPI\_Comm}
\begin{mpi-binding}
    function_name('MPI_Send')

    parameter('buf', 'BUFFER', desc='initial address of send buffer', constant=True)
    parameter('count', 'POLYXFER_NUM_ELEM', desc='number of elements in send buffer')
    parameter('datatype', 'DATATYPE', desc='datatype of each send buffer element')
    parameter('dest', 'RANK', desc='rank of destination')
    parameter('tag', 'TAG', desc='message tag')
    parameter('comm', 'COMMUNICATOR')
\end{mpi-binding}

The blocking semantics of this call are described in Section~\ref{sec:pt2pt-modes}.

Notice the new {mpi-binding} section. This section wholly replaces the hard-coded LIS/C/F90/F08 LaTeX bindings. Ultimately, it renders into the familiar bindings for MPI_Send:

Rendering for MPI_Send

The {mpi-binding} section is actually Python code (i.e., when you invoke make, a Python interpreter runs the contents of each {mpi-binding} section to render the bindings in LaTeX). The intent is that you call Python functions to define an MPI routine, such as:

  • function_name(NAME): define the name of this function. This function is straightforward.
  • parameter(NAME, TYPE, ...): define a parameter and attributes about this parameter. Several examples of calling parameter(...) are shown above; many examples of the use of parameter() can be found throughout the LaTeX source, and a detailed reference is available that explains the parameters that this function accepts.

With just these two Python functions, LaTeX for the LIS, C, F90, and F08 can be generated for the vast majority of MPI procedures. This rendering is equivalent to what was used in the MPI-3.1 version of the standard.

Although the above definition of MPI_Send is a relatively straightforward example, it is actually a good representation of how the vast majority of MPI functions are now written.

Of course, there are more complicated cases that require a few more Python functions and several more parameters to the parameter() function; those are also described in the reference guide (an easy example to cite is MPI_WTICK, which has to return a double precision value, not an integer).

But for the most part, the Pythonized version of the MPI routines is as simple as is pictured above.

Clone this wiki locally