MPIRuby
MPI Ruby is a wrapper for the Message Passing Interface originally written in C. It is a high performance computing library written for parallel programming.
Installation
If you are running OS X 10.5 and have xcode tools installed, then you already have a working version of openMPI installed. If not, you need to install openMPI on your machine as a prerequisite to installing mpi_ruby. Once you have completed installation simply download mpi_ruby and run the following:
> ./configure > make > make install
You can download the library with:
> git clone git://github.com/abedra/mpi-ruby.git
This should complete your installation. To test your install you can use the following code:
PI25DT = 3.141592653589793238462643
NINTERVALS = 10000
rank = MPI::Comm::WORLD.rank()
size = MPI::Comm::WORLD.size()
startwtime = MPI.wtime()
h = 1.0 / NINTERVALS
sum = 0.0
(rank + 1).step(NINTERVALS, size) do |i|
x = h * (i - 0.5)
sum += (4.0 / (1.0 + x**2))
end
mypi = h * sum
pi = MPI::Comm::WORLD.reduce(mypi, MPI::Op::SUM, 0)
if rank == 0 then
printf "pi is ~= %.16f, error = %.16f\n", pi, (pi - PI25DT).abs
endwtime = MPI.wtime()
puts "wallclock time = #{endwtime-startwtime}"
end
Once you have saved that file you can test it all out by running:
> mpirun -np 2 mpi_ruby pitest.rb
Or whatever you named your file. When it completes you should see an output similar to this:
> pi is ~= 3.1415926544231318, error = 0.0000000008333383 > wallclock time = 0.0113170146942139
