Here is a demonstration of basic communication with MPI Ruby.
1
2
3
4
5
6
7
8
9
10
11
12
13

myrank = MPI::Comm::WORLD.rank()
csize = MPI::Comm::WORLD.size()

if myrank % 2 == 0 then
  if myrank + 1 != csize then
    hello = "Hello, I'm #{myrank}, you must be #{myrank+1}"
    MPI::Comm::WORLD.send(hello, myrank + 1, 0)
  end
else
  msg, status = MPI::Comm::WORLD.recv(myrank - 1, 0)
  puts "I'm #{myrank} and this message came from #{status.source} with tag #{status.tag}: '#{msg}'"
end
This script sets up interprocess communication, sends / receives basic 'hello' messages and determines who the message came from and what status the message was. This is a simple starter example of how to send and receive between processes with MPI. Let's try running it:

$ mpirun -np 16 mpi_ruby basic.rb
We get an output similar to this:

I'm 13 and this message came from 12 with tag 0: 'Hello, I'm 12, you must be 13'
I'm 1 and this message came from 0 with tag 0: 'Hello, I'm 0, you must be 1'
I'm 3 and this message came from 2 with tag 0: 'Hello, I'm 2, you must be 3'
I'm 5 and this message came from 4 with tag 0: 'Hello, I'm 4, you must be 5'
I'm 7 and this message came from 6 with tag 0: 'Hello, I'm 6, you must be 7'
I'm 9 and this message came from 8 with tag 0: 'Hello, I'm 8, you must be 9'
I'm 11 and this message came from 10 with tag 0: 'Hello, I'm 10, you must be 11'
I'm 15 and this message came from 14 with tag 0: 'Hello, I'm 14, you must be 15'

Your Response