%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Basic Matlab MPI script that % sends a matrix to another processor and also % uses the MPI_Probe command. % % To run, start Matlab and type: % % eval( MPI_Run('probe',2,{}) ); % % Or, to run a different machine type: % % eval( MPI_Run('probe',2,{'machine1' 'machine2'}) ); % % Output will be piped into two files: % % MatMPI/probe.0.out % MatMPI/probe.1.out % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % MatlabMPI % Dr. Jeremy Kepner % MIT Lincoln Laboratory % kepner@ll.mit.edu %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Initialize MPI. MPI_Init; % Create communicator. comm = MPI_COMM_WORLD; % Modify common directory from default for better performance. % comm = MatMPI_Comm_dir(comm,'/tmp'); % Uncomment if you want to save the messages that were sent. % comm = MatMPI_Save_messages(comm,1); % Get size and rank. comm_size = MPI_Comm_size(comm); my_rank = MPI_Comm_rank(comm); % Print rank. disp(['my_rank: ',num2str(my_rank)]); % Set who is source and who is destination. source = 1; dest = 0; % Create a unique tag id for this message (very important in Matlab MPI!). tag = 100045; % Check to make sure that we have exactly two processors. if(comm_size == 2) % Source. if (my_rank == source) % Create data. data = 1:10; % Send it. MPI_Send( dest, tag, comm, data, data ); end % Destination. if (my_rank == dest) % Check to see if we have any mesages. keep_waiting = 1; while(keep_waiting) keep_waiting = keep_waiting + 1; disp(num2str(keep_waiting)); [message_rank message_tag] = MPI_Probe( '*', '*', comm ); pause(0.1); if (length(message_rank) > 0) keep_waiting = 0; end end % Receive data. [data data1] = MPI_Recv( source, tag, comm ); % Check data. if(any((data - (1:10)) ~= 0)) disp('ERROR: incorrect data sent.'); exit; end end end % Finalize Matlab MPI. MPI_Finalize; disp('SUCCESS'); % Don't exist if we are the host. if (my_rank ~= MatMPI_Host_rank(comm)) exit; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Copyright 2002 Massachusetts Institute of Technology % % Permission is herby granted, without payment, to copy, modify, display % and distribute this software and its documentation, if any, for any % purpose, provided that the above copyright notices and the following % three paragraphs appear in all copies of this software. Use of this % software constitutes acceptance of these terms and conditions. % % IN NO EVENT SHALL MIT BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, % SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF % THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF MIT HAS BEEN ADVISED OF THE % POSSIBILITY OF SUCH DAMAGE. % % MIT SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING, % BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS % FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. % % THIS SOFTWARE IS PROVIDED "AS IS," MIT HAS NO OBLIGATION TO PROVIDE % MAINTENANCE, SUPPORT, UPDATE, ENHANCEMENTS, OR MODIFICATIONS.