150 likes | 200 Views
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.
E N D
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
mm mode Frontend MATLAB JVM Node 0 MATLAB JVM Backend C/C++ Node 1 MATLAB JVM Node … MATLAB JVM Java sockets Basic Architecture
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 Creating the Network 10.0.0.1 10.0.0.2 … 10.0.0.110.0.0.2 …
Passing Data • Java functions operate on double[] buffers • Conversion is done automagically • Pass-by-value across the Java-MATLAB interface, so methods return buffers • 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 • Thenpasscontrolto mm 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; • Quirks
} use a binary tree algorithm MPI Functions (Methods) • Class MPI • init and fnlz – “finalize” reserved in Java • Class Comm (MPI.COMM_WORLD) • send – basic send • recv – basic receive • bcast • 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