Java MPI in MATLAB*P
Download
Report
Transcript Java MPI in MATLAB*P
Java MPI in MATLAB*P
Max Goldman
Da Guo
Overview
Allow nodes to communicate during mm
mode computation
Implement MPI primitives in Java
Interface to these methods in MATLAB*P
Why Java?
MATLAB already runs a JVM
Java well suited to network programming
Results
Basic implementation that works
And some not-so-basic things that work
Performance looks promising
Error handling needs improvement
Some quirks
Basic Architecture
mm mode
Frontend JVM
MATLAB
Node 0
Backend
Node 1
C/C++
JVM
MATLAB
JVM
MATLAB
Node … JVM
MATLAB
Java sockets
Creating the Network
Problem: each node
needs to know every
other IP address
One-time
communication
through frontend
Each node opens a
socket to every other
node
10.0.0.1
10.0.0.2
…
10.0.0.1
10.0.0.1
10.0.0.2
…
10.0.0.2
Passing Data
Java functions operate on double[] buffers
Pass-by-value across the Java-MATLAB
interface, so methods return buffers
Conversion is done automagically
In MPI spec, functions take output pointers
Everything comes back as a column!
Didn’t want to add another wrapper, so users
must use columns or reshape themselves
Making the Call
mmpi(fname, varargin)
Function fname can contain MPI calls
Will be passed directly to mm(…)
Forces MPI to be separated from *p code
Eliminates confusion due to e.g. different indexing
Can use mmpi(…) any number of times
Function does not have to go all the way from
init to fnlz
Making the Call Part II
Inside mmpi
First check network, build if needed
Then
pass
control
to mm
Quirks
function result = simpletest(arg)
import mpi.*;
MPI.init;
if MPI.COMM_WORLD.rank == 0;
data = [42];
MPI.COMM_WORLD.send(data, 1, 1, 13);
result = 0;
elseif MPI.COMM_WORLD.rank == 1
got = MPI.COMM_WORLD.recv(1, 0, 13);
result = got(1);
end
MPI.fnlz;
MPI Functions (Methods)
Class MPI
init and fnlz – “finalize” reserved in Java
Class Comm (MPI.COMM_WORLD)
send – basic send
recv – basic receive
bcast
use a binary tree algorithm
}
reduce
scatter
gather
scan – uses parallel prefix
Tests
Calculate the sum of numbers 1--40000
Tests (cont.)
Find the approximate value of Pi =
Tests (cont.)
Find maximum value in 40000 random
numbers
Tests (cont.)
“Scan” example
Demo