📄 distm_demo_1.m
字号:
close all; clear all;problemsize=100; %if your tcpip comms are slow change this to 10ps=problemsize;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SLIDE 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clcdisp(' ')disp(' ')disp(' PARALLEL MATLAB Toolbox. Version Beta 1.77 2001-09 ')disp(' ')disp(' by Lucio Andrde ')disp(' ')disp(' ')disp(' ')disp('This toolbox distributes processes over matlab workers available')disp('over the intranet/internet. These workers must be runing a ')disp('deamon to be accessed. ')disp(' ')disp('This tool is very useful for corsely granular parallelization ')disp('problems and in the presence of a distributed enviroment. It is ')disp('easy to implement a MPMD (Multiple Program-Multiple Data) as ')disp('well as a SPMD (Single Program-Multiple Data) parallel model. ')disp(' ')disp('This demo (first of two) show the basics of this toolbox so you ')disp('can understand it and start implementing both types of parallel ')disp('models. ')disp(' ')disp(' ')disp(' PAUSE')pause%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SLIDE 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clcdisp(' ')disp(' 1. BASIC CONCEPTS ')disp(' ')disp('The master session of matlab (runs in this computer) is the one ')disp('that controls all communications and determines the different ')disp('threads, as well as decides who will process them. All comunica-')disp('tions are through tcp-ip connections between workers and the ')disp('master session (or majordomo). No communications are performed ')disp('between workers. (at least in this version) ')disp(' ')disp('Two non-blocking tcpip ports are used for communications, one ')disp('is used to establish communications when we want to send a task ')disp('and the other is to receive completed tasks. ')disp(' ')disp('To initialize these communication ports use: ')disp(' ')disp('>> [ss,rs]=initmajordomo ')disp(' ^ ^ ')disp(' | |____ rs: is the task receiving port handler ')disp(' |_______ ss: is the task sending port handler ') disp(' ')disp(' PAUSE')pause[ss,rs]=initmajordomo;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SLIDE 3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clcdisp(' ')disp(' 2. SENDING A SIMPLE TASK TO A WORKER ')disp(' ')disp('Now we are ready to start distributing tasks to workers, our ')disp('very first example will be to compute a simple inverse of a 2x2 ')disp('matrix: ')a = [1 2 ; 3 4 ]disp('Normally to compute this inverse we would write: b = inv(a) ')disp('to send this computation to a remote machine we will use: ')disp(' ')disp('>> [con,hostname]=sendtask(ss,''inv'',1,1,a) ')disp(' ^ ^ ^ ^ ^ ')disp(' Port handler _________| | | | |____ Input variable ')disp(' Function _________________| | | ')disp(' # of input args ______________| |______ # of output args ')disp(' ')disp('b is not returned inmediately, its value will be returned ')disp('through the -rs- port when the remote machine finishes the work,')disp('in the meantime the control of the majordomo is returned to us ')disp('to send other tasks or to do other computations. ')disp(' ') disp('OK lets try it ! ')disp(' PAUSE')pause%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SLIDE 4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clcdisp(' ')disp(' 2. SENDING A SIMPLE TASK TO A WORKER (cont) ')disp(' ')[con,hostname]=sendtask(ss,'inv',1,1,a) disp('the negative value of -con- is because we have not launched any ')disp('worker, the function could not detect any worker available and ')disp('the task was not sent. ')disp(' ')disp('Let''s launch a worker, login into other computer (in any ')disp('internet site and with any plataform), run matlab and run the ')disp('matlab function: ')disp(' ')disp([' worker(''' getmyip ''') <-- the actual ip of this machine'])disp(' ')disp('(assuming that you installed this toolbox in the remote computer)')disp('continue when you are ready, ')disp(' ')disp(' I will send again the task... ')disp(' ')disp('OK lets try it ! ')disp(' PAUSE')pause%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SLIDE 5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clcdisp(' ')disp(' 2. SENDING A SIMPLE TASK TO A WORKER (cont) ')disp(' ')[con,hostname]=sendtask(ss,'inv',1,1,a) disp('-con- should now be positive, it has a handler to the socket ')disp(' that was used to communicate to the remote computer and ')disp('-hostname- has the identification of theremote computer. You can')disp(' use this info to administrate the parallel instances in the ')disp(' majordomo ')disp(' ')disp('If -con- was negative again, there is a problem, check that the ')disp('toolbox is installed and compiled properly in both machines. ')disp('Contact me describing your problem: landrade@ece.neu.edu ')disp(' ')disp(' PAUSE')pause%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SLIDE 6 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clcdisp(' ')disp(' 3. RECEIVING A FINISHED TASK ')disp(' ')disp('When a remote computer finishes a task, it will contact the -rs-')disp('port and hang until majordomo attends it. When majordomo is ')disp('ready (and available) to go and check it can retraive the value ')disp('of the variable b, it is up to majordomo to keep track which ')disp('remote machine is doing what and organize the returning values, ')disp(' ')disp('to receive the data we simple use: ')disp(' ')disp('>> [con,hostname,b]=receivetask(rs,1) ')disp(' ') disp('again, if -con- is negative that means that there is not any ')disp('retuning parameters ready from any of the remote tasks. ')disp('OK lets try it ! ')disp(' PAUSE')pause%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SLIDE 7 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clcdisp(' ')disp(' 3. RECEIVING A FINISHED TASK (cont) ')[con,hostname,b]=receivetask(rs,1) disp('If you are implementing a MPMD program you are responsible of ')disp('keeping track of the tasks, the reception of the output ')disp('arguments for different tasks most probably will not occur in ')disp('the same order that the tasks were sent. ')disp(' ')disp('The remote computer will no become available in the -ss- port ')disp('for a new task until the majordomo reads back the returning data')disp('and aknowlges it. ')disp(' ')disp('If an error occurs in the remote computer you will have the ')disp('chance to debug the remote workspace without suspending the work')disp('of other workers neither the majordomo, I have implemented a ')disp('trap error block that will help you to continue long computa- ')disp('tions with the other workers (help receivetask for more info) ')disp(' ')disp(' PAUSE')pause%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SLIDE 8 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clcdisp(' ')disp(' 4. RECYCLING DATA ')disp(' ')disp('There is the possibility of re-use data which we already sent ')disp('to a worker, by sending an empty variable the worker will use ')disp('the variable which already is in its own workspace, for example ')disp('lets compute the transpose of matrix a ')disp(' ')disp('>> [con,hostname]=sendtask(ss,''transpose'',1,1,[]); ')disp('>> [con,hostname,c]=receivetask(rs,1); ')disp(' ')[con,hostname]=sendtask(ss,'transpose',1,1,[]);pause(2);[con,hostname,c]=receivetask(rs,1); c disp(' ')disp(' ')disp(' PAUSE')pause%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SLIDE 9 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clcdisp(' ')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -