- Run the registration tool 'msti_reg' from the Command Prompt on each Node from which you intend to issue CMTM commands (Note: This registration is required only once and need not be repeated with each CMTM job).
Start -> Programs -> Accessories -> Command Prompt
R:\> msti_reg - Start MATLAB
Note: To run a CMTM job on multiple nodes, it is important that the path for multitask toolbox be the same on all the nodes. To find out where the toolbox is installed, say 'path' from the MATLAB prompt. - Change your Current Directory to where your files are saved
Note: When a MM_INIT command is issued all the worker tasks start in directories on their respective machines that are analogous to the directory where the master MATLAB was running (unless the environment variable CMTMdir has been set). Now, if you use 'cd' or 'chdir' to change the working dir, the worker tasks will NOT follow the master to the new dir because they are independent tasks. If you want to change ALL tasks to a new directory, use "MM_Eval('cd newdir;');". - In your current directory create a file called "machines". The machines file includes names of all CRADC nodes where you would like to process your CMTM job. The name of the node you are logged-on, should always be listed on the first line. List the additional nodes on the following lines, one node per line. Here is an example of a machines file (logon node cradc05):
CRADC05
CRADC02
CRADC04 - Use CMTM command 'MM_Init' to Initialize tasks, and 'MM_Finalize' to close these tasks. Given below are two sample programs that create strings at worker tasks and send them to the master task.
- Steps to run a multitask sample program "hello5ps_eval.m".
The program initializes 5 tasks (1 master and 4 workers) and uses MPI routine MPI_COMM_RANK to determine the rank of a task, and MMPI_SEND and MMPI_RECV to send and receive messages between the workers and master.- Initialize the multitask toolbox:
>> MM_Init(5) % 5 tasks: four new and one old
You should see a multitask window as shown here:
- Initialize the multitask toolbox:
- Steps to run a multitask sample program "hello5ps_eval.m".
-
- Your MATLAB command window shows results of your successful initialization, as shown here.
Starting Cornell Multitasking 0.80
Task 1 checked in
Task 2 checked in
Task 3 checked in
Task 4 checked in
0>> Cornell Multitask running on 5 tasks
>> - At the MATLAB prompt (it takes a few seconds to get it back) submit the M-file as the argument to MM_Eval command (if only one argument is presented to mm_eval, it is interpreted as a command to be evaluated on all tasks).
>> MM_Eval('hello5ps_eval')
Note: In your current dir CMTM creates an error file (CMTM.err), a master log file (CMTMlog.0) and a log file for each worker (CMTMlog.1 - 4). -
Use the command MM_Finalize to close all the worker tasks. Any matrices in the workspaces of the workers are lost, but the master retains its data. After this, it is possible to start another round of parallel computation with a call to MM_INIT, possibly with a different number of workers.
>> MM_Finalize % closes all worker tasks
- Your MATLAB command window shows results of your successful initialization, as shown here.
- The M-file "hello5ps.m" is another version of the program hello5ps_eval.m. hello5ps.m includes MM_INIT and MM_FINALIZE as the first command and the last command, respectively. The program uses MM_EVAL command to send processes to the workers and uses MMPI_SEND and MMPI_RECV commands to send and receive messages from workers to master. To submit "hello5ps.m", type hello5ps at the MATLAB command prompt.
>> hello5ps
CMTM Help: http://www.tc.cornell.edu/services/support/forms/cmtm.p2.htm
A listing of the sample M-files:
% Sample CMTM program "hello5ps_eval.m"
% To run this program on CRADC nodes:
% 1. your current dir should include a file called "machines".
% First line in this machines file should have the name of the NODE you are logged on.
% To use the processors from other cradc nodes, list their names beginning 2nd line
% (one node name per line).
%
% 2. Initialize 5 tasks by using the command "MM_Init(5)"
% 3. Run the program by "MM_Eval('hello5ps_eval')"
% 4. When finished issue the command "MM_Finalize"
if (MMPI_Comm_rank ==1)
message = 'Hello, World! from worker 1' ;
MMPI_Send(message, 0, 1);
end
if (MMPI_Comm_rank ==2)
message = 'Hello, World! from worker 2' ;
MMPI_Send(message, 0, 1);
end
if (MMPI_Comm_rank ==3)
message = 'Hello, World! from worker 3' ;
MMPI_Send(message, 0, 1);
end
if (MMPI_Comm_rank ==4)
message = 'Hello, World! from worker 4' ;
MMPI_Send(message, 0, 1);
end
if (MMPI_Comm_rank == 0)
message_rec1 = MMPI_Recv(1,1)
message_rec2 = MMPI_Recv(2,1)
message_rec3 = MMPI_Recv(3,1)
message_rec4 = MMPI_Recv(4,1)
end
% Sample CMTM program "hello5ps.m"
% To run this program on CRADC nodes:
% your current dir should include a file called "machines".
% First line in this machines file should have the name of the NODE you are logged on.
% To use the processors from other cradc nodes, list their names beginning 2nd line
% (one node name per line).
% To submit this program type the filname at the MATLAB prompt
% >> hello5ps
mm_init(5); % TO INITIALIZE 5 TASKS: MASTER(rank=0) AND 4 WORKERs (rank=1 to 4)
% ON WORKER(RANK=1) ISSUE THE COMMANDS INSIDE THE SINGLE QUOTES
mm_eval(1,'message1=''CMTM Worked! from worker 1''.');
% ON WORKER 1, SEND THE MATRIX "MESSAGE1" TO 0:MASTER,
% ASSIGN TAG 1 TO THIS MESSAGE
mm_eval(1,'mmpi_send(message1,0,1).');
% RECEIVE A MESSAGE FROM SENDER 1 WITH MESSAGE TAG 1
mess_rec1 = mmpi_recv(1,1)
% ON WORKER(RANK=2) ISSUE THE COMMANDS INSIDE THE SINGLE QUOTES
mm_eval(2,'message2=''CMTM Worked! from worker 2''.');
% ON WORKER 2, SEND THE MATRIX "MESSAGE2" TO 0:MASTER,
% ASSIGN TAG 1 TO THIS MESSAGE
mm_eval(2,'mmpi_send(message2,0,1).');
% RECEIVE A MESSAGE FROM SENDER 2 WITH MESSAGE TAG 1
mess_rec2 = mmpi_recv(2,1)
% ON WORKER(RANK=3) ISSUE THE COMMANDS INSIDE THE SINGLE QUOTES
mm_eval(3,'message3=''CMTM Worked! from worker 3''.');
% ON WORKER 3, SEND THE MATRIX "MESSAGE3" TO 0:MASTER,
% ASSIGN TAG 1 TO THIS MESSAGE
mm_eval(3,'mmpi_send(message3,0,1).');
% RECEIVE A MESSAGE FROM SENDER 3 WITH MESSAGE TAG 1
mess_rec3 = mmpi_recv(3,1)
% ON WORKER(RANK=4) ISSUE THE COMMANDS INSIDE THE SINGLE QUOTES
mm_eval(4,'message4=''CMTM Worked! from worker 4''.');
% ON WORKER 4, SEND THE MATRIX "MESSAGE4" TO 0:MASTER,
% ASSIGN TAG 1 TO THIS MESSAGE
mm_eval(4,'mmpi_send(message4,0,1).');
% RECEIVE A MESSAGE FROM SENDER 4 WITH MESSAGE TAG 1
mess_rec4 = mmpi_recv(4,1)
mm_finalize % CLOSE ALL WORKER TASKS