An Introduction to Parallel Programming with Matlabjfernand/investigacion/papers/astimo...• Matlab...
Transcript of An Introduction to Parallel Programming with Matlabjfernand/investigacion/papers/astimo...• Matlab...
(RS)2I – Retrieval System for Remotely Sensed Imagery Liu Bo
(RS)2I
An Introduction to Parallel Programming with Matlab
Liu Bo
(RS)2I – Retrieval System for Remotely Sensed Imagery Liu Bo
(RS)2I
Overview
• Matlab is the dominant programming language for implementing numerical computations and is widely used for algorithm development, simulation, data reduction, testing and system evaluation.
• In the world of parallel computing the Message Passing Interface (MPI) is the de facto standard for implementing programs on multiple processors.
(RS)2I – Retrieval System for Remotely Sensed Imagery Liu Bo
(RS)2I
Implementations of Parallel Matlab
• MPITB http://atc.ugr.es/javier-bin/mpitb_eng• MatlabMPI http://www.ll.mit.edu/MatlabMPI/• Grid Matlab http://www.globus.org
(RS)2I – Retrieval System for Remotely Sensed Imagery Liu Bo
(RS)2I
Design Details of MPITB
• LAM-MPI must be installed on every node as dynamic link library
• To run MPITB LAM must be run first
• Processes from different nodes exchange information via API provided by LAM
(RS)2I – Retrieval System for Remotely Sensed Imagery Liu Bo
(RS)2I
Design Details of MatlabMPI
• A common directory must be mounted from a NFS server on every node
• Processes from different nodes exchange information via Network File System
(RS)2I – Retrieval System for Remotely Sensed Imagery Liu Bo
(RS)2I
Installation of MatlabMPI
1. Ensure the current directory is your home directory2. Get MatlabMPI with the following command [xxx]$ wget http://www.ll.mit.edu/MatlabMPI/MatlabMPI_v0.95.tar.gz3. Unexpress[xxx]$ tar vxzf MatlabMPI_v0.95.tar.gz4. Edit the startup.m and add this line addpath([ getenv('HOME') '/MatlabMPI/src' ])
(RS)2I – Retrieval System for Remotely Sensed Imagery Liu Bo
(RS)2I
Running MatlabMPI
1. Ensure the current directory is your home directory2. Run matlab first[xxx]$ matlab3. List the functions of MatlabMPI[xxx]>> help MatlabMPI;4. Assign the machine list[xxx]>> Machines={‘c0-0’,’c0-1’, ‘c0-2’};5. Run program[xxx]>> eval( MPI_Run(‘test', 2,machines) );
(RS)2I – Retrieval System for Remotely Sensed Imagery Liu Bo
(RS)2I
Functions of MatlabMPI
• MPI_Run Runs a matlab script in parallel.• MPI_Init Inititializes at the beginning.• MPI_Comm_size Gets number of processors in a
communicator.• MPI_Comm_rank Gets rank of current processor within
a communicator.• MPI_Send Sends a message to a processor.• MPI_Recv Receives message from a
processor.• MPI_Finalize Cleans up at the end.• MPI_Abort kills all matlab jobs started • MPI_Bcast Broadcast a message.• MPI_Probe Returns a list of all incoming
messages.
(RS)2I – Retrieval System for Remotely Sensed Imagery Liu Bo
(RS)2I
Example: Task
• Send a vector from one machine to another machine.
1.02.03.0...
10.0
Process 2Process 1
Vector 1 Vector 2
(RS)2I – Retrieval System for Remotely Sensed Imagery Liu Bo
(RS)2I
Example: Source Code (1/2)
1. MPI_Init;2. comm = MPI_COMM_WORLD;3. comm_size = MPI_Comm_size(comm);4. my_rank = MPI_Comm_rank(comm);5. if (my_rank == 0)6. data = 1:10;7. MPI_Send( dest, tag, comm, data, data );8. disp(‘I am ‘, my_rank, ‘data = ‘, data);9. end10. if (my_rank == 1)
(RS)2I – Retrieval System for Remotely Sensed Imagery Liu Bo
(RS)2I
Example: Source Code (2/2)
11. [data data1] = MPI_Recv( source, tag, comm );12. disp(‘I am ‘, myrand, ‘data =‘, data);13. end 14. MPI_Finalize;15. disp('SUCCESS');16. exit;
(RS)2I – Retrieval System for Remotely Sensed Imagery Liu Bo
(RS)2I
Example: Result
>>eval( MPI_Run('xbasic', 2,machines) );I am 0, data = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10I am 1, data = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10SUCCESS>>>>
(RS)2I – Retrieval System for Remotely Sensed Imagery Liu Bo
(RS)2I
References
1. Marc Snir, Steve Otto, Steven Huss-Lederman, David Walker, and Jack Dongarra. MPI: The Complete Reference. The MIT Press, 1996.
2. http://www.ll.mit.edu/MatlabMPI/3. http://atc.ugr.es/javier-bin/mpitb_eng4. http://www-unix.mcs.anl.gov/mpi/mpich/5. http://www.lam-mpi.org/
(RS)2I – Retrieval System for Remotely Sensed Imagery Liu Bo
(RS)2I
That’s all, thank you!
☺