GOMPI

NAME
POINTERS, SLICES, AND ARRAYS
COMPILING AND RUNNING MPI PROGRAMS
BUGS

NAME

gompi −− Init(), Send_float64, Recv_float64, Isend_float64, Irecv_float64, Wait, Finalize, Ferror : Go language wrappers for a subset of the C language MPI interface

This set of routines constitutes a small but functional subset of Go language wrappers for C language calls to the OpenMPI (Message Passing Interface), the standard tool for implementing parallel processing. It can easily be extended to include more of the interface, e.g., for data types other than float64. Multi-core systems as well as separate computers connected by Ethernet or other communication system are handled.

This library works only on the "gccgo" compiler, not on the "go" compiler.

comm, nprocs, rank := Init()

This function initializes the MPI system and must be called before any other MPI function. "comm" is an opaque data type describing all of the processors available for use. "nprocs" is the number of processes accessed and "rank" is an integer in the range [0,nprocs - 1] that identifies each process.

Send_float64(buff []float64, dest int, comm MPI_Comm)

This function sends a slice of float64 values to the process with rank "dest". "comm" is provided by the call to "Init". "buff" is a slice of float64 elements. This function blocks, i.e., it only returns when the transfer is complete.

Recv_float64(buff []float64, dest int, comm MPI_Comm)

This function receives a slice of float64 values from the process with rank "dest". "comm" is provided by the call to "Init". "buff" is a slice of float64 elements. This function blocks, i.e., it only returns when the transfer is complete. For every "Send" there must be a corresponding "Recv".

request := Isend_float64(buff []float64, dest int, comm MPI_Comm)

This function sends a slice of float64 values to the process with rank "dest". "comm" is provided by the call to "Init". "buff" is a slice of float64 elements. This function does not block, i.e., it returns immediately after the transfer is started, allowing other work to be done while the transfer takes place. The returned "request" is an opaque data type that must be presented to the "Wait" function (see below).

request := Irecv_float64(buff []float64, dest int, comm MPI_Comm)

This function receives a slice of float64 values from the process with rank "dest". "comm" is provided by the call to "Init". "buff" is a slice of float64 elements. This function does not block, i.e., it returns immediately after the transfer is started, allowing other work to be done while the transfer takes place. The returned "request" is an opaque data type that must be presented to the "Wait" function (see below). For every "Isend" there must be a corresponding "Irecv".

Wait(request *MPI_Request)

This function blocks when called, and only returns when the "Isend" or "Irecv" issuing the "request" finishes its transfer. This function should be called separately for the requests issued by the send and the receive. The purpose of "Isend/Irecv/Wait" is to allow other work to be done in parallel with the inter-process data transfer.

Finalize()

This function must be called at the end of the program on all ranks to close out MPI cleanly.

Ferror(message string, rank int)

This is a helper function that prints an error message string "message" to the standard output on the rank = 0 process and then calls "Finalize" on all processes.

POINTERS, SLICES, AND ARRAYS

Generally in Go, one desires to send and receive data represented by slices. However, the slice itself is a structure containing pointers to the segment of an underlying array. In order to access this array segment, pass the send or receive function a pointer to the first element of the slice. For instance, if a slice is named "sbuff", then the segment of the underlying array associated with the slice may be accessed by setting the "buff" argument to "&sbuff[0]".

The sizes of the send and receive buffers should be equal and exactly equal to the size of the data transferred by them. Violation of these criteria can lead to unpredictable results or even crash your program.

COMPILING AND RUNNING MPI PROGRAMS

To compile your program, do something like the following:

gccgo -O2 -o myprogram myprogram.go -I /usr/local/lib -lgompi -L /usr/lib/openmpi -lmpi

This assumes that the "gompi" package is installed as the library "libgompi.a" in "/usr/local/lib" and that the C language MPI library is installed in "/usr/lib/openmpi". Different systems may put these packages in different places.

To run your program, invoke

mpirun -np xxx [--hostname myhostfile] myprogram [arguments]

where "xxx" is the number of processes and "myhostfile" is the optional host file representing the desired machines and the number of available processors on each machine. See "man mpirun" for more information.

BUGS

"Gompi" ignores error returns, which means that errors result in termination with an error message.

Only a very small selection of MPI routines implemented.