README.md

May 30, 2026 · View on GitHub

CI

GoMPI: Message Passing Interface for Parallel Computing

The gompi package is a lightweight wrapper to the OpenMPI C library designed to develop algorithms for parallel computing.

GoMPI is a fork of the gosl MPI library with additional methods.

Usage

package main

import (
	"fmt"
	"log"

	mpi "github.com/sbromberger/gompi"
)

func main() {
	m, err := mpi.Start()
	if err != nil {
		log.Fatal(err)
	}
	defer m.Stop()

	rank := m.WorldRank()
	size := m.WorldSize()

	comm := m.NewCommunicator(nil)

	if rank == 0 {
		// Rank 0 sends a slice of float64 to rank 1.
		vals := []float64{1.0, 2.0, 3.0}
		comm.Send(vals, 1, 0)
		fmt.Printf("rank 0 of %d: sent %v\n", size, vals)
	} else if rank == 1 {
		// Rank 1 receives from rank 0.
		vals, _ := comm.Recv[float64](0, 0)
		fmt.Printf("rank 1 of %d: received %v\n", size, vals)
	}
}

Run with:

mpirun -n 2 go run main.go

Dependencies

This package will not work on Windows systems.

GoMPI requires the OpenMPI libraries, header files, and binaries to be installed on your system.

Testing

Testing requires four MPI ranks and is launched via mpirun:

mpirun -n 4 --oversubscribe go test .

Performance

Note: latency benchmarks updated May 2026.

Single-Node Benchmarks

OSU MPI Latency Test (v7.5.1) benchmarks run using mpirun -n 2 ./osu_latency -i 1000 -x 200 with datatype = MPI_Char. GoMPI benchmarks run using mpirun -n 2 go run latency.go.

Benchmarks were run on a single node. Small-message overhead reflects CGo call latency and converges to parity as message size increases.

message size (bytes)GoMPI (µs)OSU MPI (µs)difference
10.130.101.3x
20.130.101.3x
40.140.101.4x
80.130.101.3x
160.130.101.3x
320.140.101.4x
640.150.111.4x
1280.170.111.5x
2560.170.141.2x
5120.250.201.2x
10240.280.231.2x
20480.310.291.1x
40960.660.681.0x
81920.880.911.0x
163841.081.150.9x
327681.541.591.0x
655362.922.271.3x
1310724.174.101.0x
2621447.456.831.1x
52428814.0013.221.1x
104857626.6324.711.1x
209715252.0350.451.0x
4194304100.70102.491.0x

Benchmark code may be found in cmd/latency/latency.go.

Inter-node Benchmarks (OmniPath/PSM2)

OSU MPI Latency Test (v5.9) benchmarks run using srun -N 2 -n 2 --ntasks-per-node=1 ./osu_latency -i 1000 -x 200 with datatype = MPI_Char. GoMPI benchmarks run using srun -N 2 -n 2 --ntasks-per-node=1 go run main.go.

Benchmarks were run across two nodes over OmniPath (PSM2 transport). Small-message overhead reflects CGo call latency and converges to parity as message size increases.

message size (bytes)GoMPI (µs)OSU MPI (µs)difference
11.141.011.1x
21.161.001.2x
41.180.991.2x
81.130.991.1x
161.261.091.2x
321.271.101.2x
641.281.101.2x
1281.301.131.2x
2561.331.171.1x
5121.441.251.2x
10241.491.371.1x
20481.721.591.1x
40962.152.041.1x
81922.532.391.1x
163847.157.031.0x
3276812.326.771.8x¹
6553611.6511.571.0x
13107215.8015.811.0x
26214423.2323.321.0x
52428836.5336.221.0x
104857664.2764.591.0x
2097152119.08118.281.0x
4194304211.46212.021.0x

¹ Anomalous result reflecting fabric instability at this message size; not representative of CGo overhead.