Skip to content

mpi #

Message Passing Interface for parallel computing

The mpi package is a simplified wrapper to the OpenMPI C library designed to support algorithms for parallel computing.

This library allows a program to support parallel computations over the network. This is otherwise known as a single-program multiple-data (SPMD) architecture.

Requirements

  • On ubuntu, you can install the OpenMPI library with:
sudo apt install libopenmpi-dev
  • On Arch Linux, you can install the OpenMPI library with:
sudo pacman -S openmpi
  • On macOS, you can install the OpenMPI library with:
brew install openmpi
  • On Windows, you can install the OpenMPI following the instructionshere.

  • On FreeBSD, you can install the OpenMPI library with:

pkg install openmpi

Features

The mpi routines supported include:

  • initialize()
  • finalize()
  • world_rank() int
  • world_size() int
  • is_on() bool
  • new_communicator(ranks []int) ?&Communicator

The methods for the Communicator support i32, u32, i64, u64, f32 and f64 data types. These allow exchange of arrays of data between processors or broadcast from the first processor (the root node with rank == 0).

A program must issue a send (on one rank) and matching receive on another rank or all ranks, depending on the nature of the method. Use barrier() to ensure all ranks are synchronized at that point.

Support is provided for Linux and the BSDs.

Once you have created a Communicator, you can use these methods, where the <type> is one of the above i32, u32, i64, u64, f32 or f64:

MethodResult
comm.rank()Rank of the processor within the World or group
comm.size()Size of the list of processors
comm.abort()Abort the MPI program
comm.barrier()Resynchronize all processors to this point
comm.send_i32( vals []i32, to_rank int)Send an array to one rank
comm.recv_i32( vals []i32, from_rank int)Receive array from one rank
comm.send_u32( ... )As above for unsigned 32-bit integers
comm.send_i64( ... )As above for signed 64-bit integers
comm.send_u64( ... )As above for unsigned 64-bit integers
comm.send_f32( ... )As above for 32-bit floats
comm.send_f64( ... )As above for 64-bit floats
comm.send_one_<type>( val <type>, to_rank int)Send one value to one rank
comm.recv_one_<type>( from_rank int) <type>Returns one value from one rank
comm.bcast_from_root_<type>(vals []<type>)Copy the values to all processors
comm.reduce_sum_<type>(mut dest []<type>, orig []<type>)Sum orig array elements to dest on rank 0
comm.all_reduce_sum_<type>(mut dest []<type>, orig []<type>)Sum orig array elements to dest on all ranks
comm.reduce_min_<type>(mut dest []<type>, orig []<type>)Minimize orig array elements to dest on rank 0
comm.all_reduce_min_<type>(mut dest []<type>, orig []<type>)Minimize orig array elements to dest on all ranks
comm.reduce_max_<type>(mut dest []<type>, orig []<type>)Maximize orig array elements to dest on rank 0
comm.all_reduce_max_<type>(mut dest []<type>, orig []<type>)Maximize orig array elements to dest on all ranks

fn finalize #

fn finalize()

finalize MPI

fn initialise #

fn initialise() !

initialise readies MPI for use

fn initialize #

fn initialize() !

initialize readies MPI for use

fn is_on #

fn is_on() bool

is_on tells whether MPI is on or not

Note: this returns true even after finish

fn start_thread_safe #

fn start_thread_safe() !

start_thread_safe initialises MPI in a thread safe way

fn world_rank #

fn world_rank() int

world_rank returns the processor rank within the World Communicator

fn world_size #

fn world_size() int

world_size returns the number of processors in the World Communicator

fn Communicator.new #

fn Communicator.new(ranks []int) !&Communicator

Communicator.new creates a new communicator or returns the World Communicator ranks -- World indices of processors in this Communicator. use nil or empty to get the World Communicator Note there is currently no means to use groups.

struct Communicator #

struct Communicator {
mut:
	comm  MPI_Comm
	group MPI_Group
}

Communicator holds the World Communicator or a subset Communicator

fn (Communicator) rank #

fn (o &Communicator) rank() int

rank returns the processor rank

fn (Communicator) size #

fn (o &Communicator) size() int

size returns the number of processors

fn (Communicator) abort #

fn (o &Communicator) abort()

abort aborts MPI

fn (Communicator) barrier #

fn (o &Communicator) barrier()

barrier forces synchronisation

fn (Communicator) send_i32 #

fn (o &Communicator) send_i32(vals []i32, to_rank int)

send_i32 sends values to processor to_rank

fn (Communicator) recv_i32 #

fn (o &Communicator) recv_i32(vals []i32, from_rank int)

recv_i32 receives values from processor from_rank

fn (Communicator) send_u32 #

fn (o &Communicator) send_u32(vals []u32, to_rank int)

send_u32 sends values to processor to_rank

fn (Communicator) recv_u32 #

fn (o &Communicator) recv_u32(vals []u32, from_rank int)

recv_u32 receives values from processor from_rank

fn (Communicator) send_i64 #

fn (o &Communicator) send_i64(vals []i64, to_rank int)

send_i64 sends values to processor to_rank

fn (Communicator) recv_i64 #

fn (o &Communicator) recv_i64(vals []i64, from_rank int)

recv_i64 receives values from processor from_rank

fn (Communicator) send_u64 #

fn (o &Communicator) send_u64(vals []u64, to_rank int)

send_u64 sends values to processor to_rank

fn (Communicator) recv_u64 #

fn (o &Communicator) recv_u64(vals []u64, from_rank int)

recv_u64 receives values from processor from_rank

fn (Communicator) send_f32 #

fn (o &Communicator) send_f32(vals []f32, to_rank int)

send_f32 sends values to processor to_rank

fn (Communicator) recv_f32 #

fn (o &Communicator) recv_f32(vals []f32, from_rank int)

recv_f32 receives values from processor from_rank

fn (Communicator) send_f64 #

fn (o &Communicator) send_f64(vals []f64, to_rank int)

send_f64 sends values to processor to_rank

fn (Communicator) recv_f64 #

fn (o &Communicator) recv_f64(vals []f64, from_rank int)

recv_f64 receives values from processor from_rank

fn (Communicator) send_one_i32 #

fn (o &Communicator) send_one_i32(val i32, to_rank int)

send_one_i32 sends one value to processor to_rank

fn (Communicator) recv_one_i32 #

fn (o &Communicator) recv_one_i32(from_rank int) i32

recv_one_i32 receives one value from processor from_rank

fn (Communicator) send_one_u32 #

fn (o &Communicator) send_one_u32(val u32, to_rank int)

send_one_u32 sends one value to processor to_rank

fn (Communicator) recv_one_u32 #

fn (o &Communicator) recv_one_u32(from_rank int) u32

recv_one_u32 receives one value from processor from_rank

fn (Communicator) send_one_i64 #

fn (o &Communicator) send_one_i64(val i64, to_rank int)

send_one_i64 sends one value to processor to_rank

fn (Communicator) recv_one_i64 #

fn (o &Communicator) recv_one_i64(from_rank int) i64

recv_one_i64 receives one value from processor from_rank

fn (Communicator) send_one_u64 #

fn (o &Communicator) send_one_u64(val u64, to_rank int)

send_one_u64 sends one value to processor to_rank

fn (Communicator) recv_one_u64 #

fn (o &Communicator) recv_one_u64(from_rank int) u64

recv_one_u64 receives one value from processor from_rank

fn (Communicator) send_one_f32 #

fn (o &Communicator) send_one_f32(val f32, to_rank int)

send_one_f32 sends one value to processor to_rank

fn (Communicator) recv_one_f32 #

fn (o &Communicator) recv_one_f32(from_rank int) f32

recv_one_f32 receives one value from processor from_rank

fn (Communicator) send_one_f64 #

fn (o &Communicator) send_one_f64(val f64, to_rank int)

send_one_f64 sends one value to processor to_rank

fn (Communicator) recv_one_f64 #

fn (o &Communicator) recv_one_f64(from_rank int) f64

recv_one_f64 receives one value from processor from_rank

fn (Communicator) bcast_from_root_i32 #

fn (o &Communicator) bcast_from_root_i32(x []i32)

bcast_from_root_i32 broadcasts slice x from root (Rank == 0) to all other processors

fn (Communicator) bcast_from_root_u32 #

fn (o &Communicator) bcast_from_root_u32(x []u32)

bcast_from_root_u32 broadcasts slice x from root (Rank == 0) to all other processors

fn (Communicator) bcast_from_root_i64 #

fn (o &Communicator) bcast_from_root_i64(x []i64)

bcast_from_root_i64 broadcasts slice x from root (Rank == 0) to all other processors

fn (Communicator) bcast_from_root_u64 #

fn (o &Communicator) bcast_from_root_u64(x []u64)

bcast_from_root_u64 broadcasts slice x from root (Rank == 0) to all other processors

fn (Communicator) bcast_from_root_f32 #

fn (o &Communicator) bcast_from_root_f32(x []f32)

bcast_from_root_f32 broadcasts slice x from root (Rank == 0) to all other processors

fn (Communicator) bcast_from_root_f64 #

fn (o &Communicator) bcast_from_root_f64(x []f64)

bcast_from_root_f64 broadcasts slice x from root (Rank == 0) to all other processors

fn (Communicator) reduce_sum_i32 #

fn (o &Communicator) reduce_sum_i32(mut dest []i32, orig []i32)

reduce_sum_i32 sums all values in 'orig' to 'dest' in root (Rank == 0) processor note (important): orig and dest must be different slices

fn (Communicator) all_reduce_sum_i32 #

fn (o &Communicator) all_reduce_sum_i32(mut dest []i32, orig []i32)

all_reduce_sum_i32 combines all values from orig into dest summing values note (important): orig and dest must be different slices

fn (Communicator) reduce_min_i32 #

fn (o &Communicator) reduce_min_i32(mut dest []i32, orig []i32)

reduce_min_i32 minimizes all values in 'orig' to 'dest' in root (Rank == 0) processor note (important): orig and dest must be different slices

fn (Communicator) all_reduce_min_i32 #

fn (o &Communicator) all_reduce_min_i32(mut dest []i32, orig []i32)

all_reduce_min_i32 minimizes all values from orig into all dest values note (important): orig and dest must be different slices

fn (Communicator) reduce_max_i32 #

fn (o &Communicator) reduce_max_i32(mut dest []i32, orig []i32)

reduce_max_i32 maximizes all values in 'orig' to 'dest' in root (Rank == 0) processor note (important): orig and dest must be different slices

fn (Communicator) all_reduce_max_i32 #

fn (o &Communicator) all_reduce_max_i32(mut dest []i32, orig []i32)

all_reduce_max_i32 maximizes all values from orig into all dest values note (important): orig and dest must be different slices

fn (Communicator) reduce_sum_u32 #

fn (o &Communicator) reduce_sum_u32(mut dest []u32, orig []u32)

reduce_sum_u32 sums all values in 'orig' to 'dest' in root (Rank == 0) processor note (important): orig and dest must be different slices

fn (Communicator) all_reduce_sum_u32 #

fn (o &Communicator) all_reduce_sum_u32(mut dest []u32, orig []u32)

all_reduce_sum_u32 combines all values from orig into dest summing values note (important): orig and dest must be different slices

fn (Communicator) reduce_min_u32 #

fn (o &Communicator) reduce_min_u32(mut dest []u32, orig []u32)

reduce_min_u32 minimizes all values in 'orig' to 'dest' in root (Rank == 0) processor note (important): orig and dest must be different slices

fn (Communicator) all_reduce_min_u32 #

fn (o &Communicator) all_reduce_min_u32(mut dest []u32, orig []u32)

all_reduce_min_u32 minimizes all values from orig into all dest values note (important): orig and dest must be different slices

fn (Communicator) reduce_max_u32 #

fn (o &Communicator) reduce_max_u32(mut dest []u32, orig []u32)

reduce_max_u32 maximizes all values in 'orig' to 'dest' in root (Rank == 0) processor note (important): orig and dest must be different slices

fn (Communicator) all_reduce_max_u32 #

fn (o &Communicator) all_reduce_max_u32(mut dest []u32, orig []u32)

all_reduce_max_u32 maximizes all values from orig into all dest values note (important): orig and dest must be different slices

fn (Communicator) reduce_sum_i64 #

fn (o &Communicator) reduce_sum_i64(mut dest []i64, orig []i64)

reduce_sum_i64 sums all values in 'orig' to 'dest' in root (Rank == 0) processor note (important): orig and dest must be different slices

fn (Communicator) all_reduce_sum_i64 #

fn (o &Communicator) all_reduce_sum_i64(mut dest []i64, orig []i64)

all_reduce_sum_i64 combines all values from orig into dest summing values note (important): orig and dest must be different slices

fn (Communicator) reduce_min_i64 #

fn (o &Communicator) reduce_min_i64(mut dest []i64, orig []i64)

reduce_min_i64 minimizes all values in 'orig' to 'dest' in root (Rank == 0) processor note (important): orig and dest must be different slices

fn (Communicator) all_reduce_min_i64 #

fn (o &Communicator) all_reduce_min_i64(mut dest []i64, orig []i64)

all_reduce_min_i64 minimizes all values from orig into all dest values note (important): orig and dest must be different slices

fn (Communicator) reduce_max_i64 #

fn (o &Communicator) reduce_max_i64(mut dest []i64, orig []i64)

reduce_max_i64 maximizes all values in 'orig' to 'dest' in root (Rank == 0) processor note (important): orig and dest must be different slices

fn (Communicator) all_reduce_max_i64 #

fn (o &Communicator) all_reduce_max_i64(mut dest []i64, orig []i64)

all_reduce_max_i64 maximizes all values from orig into all dest values note (important): orig and dest must be different slices

fn (Communicator) reduce_sum_u64 #

fn (o &Communicator) reduce_sum_u64(mut dest []u64, orig []u64)

reduce_sum_u64 sums all values in 'orig' to 'dest' in root (Rank == 0) processor note (important): orig and dest must be different slices

fn (Communicator) all_reduce_sum_u64 #

fn (o &Communicator) all_reduce_sum_u64(mut dest []u64, orig []u64)

all_reduce_sum_u64 combines all values from orig into dest summing values note (important): orig and dest must be different slices

fn (Communicator) reduce_min_u64 #

fn (o &Communicator) reduce_min_u64(mut dest []u64, orig []u64)

reduce_min_u64 minimizes all values in 'orig' to 'dest' in root (Rank == 0) processor note (important): orig and dest must be different slices

fn (Communicator) all_reduce_min_u64 #

fn (o &Communicator) all_reduce_min_u64(mut dest []u64, orig []u64)

all_reduce_min_u64 minimizes all values from orig into all dest values note (important): orig and dest must be different slices

fn (Communicator) reduce_max_u64 #

fn (o &Communicator) reduce_max_u64(mut dest []u64, orig []u64)

reduce_max_u64 maximizes all values in 'orig' to 'dest' in root (Rank == 0) processor note (important): orig and dest must be different slices

fn (Communicator) all_reduce_max_u64 #

fn (o &Communicator) all_reduce_max_u64(mut dest []u64, orig []u64)

all_reduce_max_u64 maximizes all values from orig into all dest values note (important): orig and dest must be different slices

fn (Communicator) reduce_sum_f32 #

fn (o &Communicator) reduce_sum_f32(mut dest []f32, orig []f32)

reduce_sum_f32 sums all values in 'orig' to 'dest' in root (Rank == 0) processor note (important): orig and dest must be different slices

fn (Communicator) all_reduce_sum_f32 #

fn (o &Communicator) all_reduce_sum_f32(mut dest []f32, orig []f32)

all_reduce_sum_f32 combines all values from orig into dest summing values note (important): orig and dest must be different slices

fn (Communicator) reduce_min_f32 #

fn (o &Communicator) reduce_min_f32(mut dest []f32, orig []f32)

reduce_min_f32 minimizes all values in 'orig' to 'dest' in root (Rank == 0) processor note (important): orig and dest must be different slices

fn (Communicator) all_reduce_min_f32 #

fn (o &Communicator) all_reduce_min_f32(mut dest []f32, orig []f32)

all_reduce_min_f32 minimizes all values from orig into all dest values note (important): orig and dest must be different slices

fn (Communicator) reduce_max_f32 #

fn (o &Communicator) reduce_max_f32(mut dest []f32, orig []f32)

reduce_max_f32 maximizes all values in 'orig' to 'dest' in root (Rank == 0) processor note (important): orig and dest must be different slices

fn (Communicator) all_reduce_max_f32 #

fn (o &Communicator) all_reduce_max_f32(mut dest []f32, orig []f32)

all_reduce_max_f32 maximizes all values from orig into all dest values note (important): orig and dest must be different slices

fn (Communicator) reduce_sum_f64 #

fn (o &Communicator) reduce_sum_f64(mut dest []f64, orig []f64)

reduce_sum_f64 sums all values in 'orig' to 'dest' in root (Rank == 0) processor note (important): orig and dest must be different slices

fn (Communicator) all_reduce_sum_f64 #

fn (o &Communicator) all_reduce_sum_f64(mut dest []f64, orig []f64)

all_reduce_sum_f64 combines all values from orig into dest summing values note (important): orig and dest must be different slices

fn (Communicator) reduce_min_f64 #

fn (o &Communicator) reduce_min_f64(mut dest []f64, orig []f64)

reduce_min_f64 minimizes all values in 'orig' to 'dest' in root (Rank == 0) processor note (important): orig and dest must be different slices

fn (Communicator) all_reduce_min_f64 #

fn (o &Communicator) all_reduce_min_f64(mut dest []f64, orig []f64)

all_reduce_min_f64 minimizes all values from orig into all dest values note (important): orig and dest must be different slices

fn (Communicator) reduce_max_f64 #

fn (o &Communicator) reduce_max_f64(mut dest []f64, orig []f64)

reduce_max_f64 maximizes all values in 'orig' to 'dest' in root (Rank == 0) processor note (important): orig and dest must be different slices

fn (Communicator) all_reduce_max_f64 #

fn (o &Communicator) all_reduce_max_f64(mut dest []f64, orig []f64)

all_reduce_max_f64 maximizes all values from orig into all dest values note (important): orig and dest must be different slices