http:^^www.cs.cornell.edu^info^people^lnt^multimatlab.html
来自「This data set contains WWW-pages collect」· HTML 代码 · 共 1,159 行 · 第 1/5 页
HTML
1,159 行
<BLOCKQUOTE><CODE>Start(5)</CODE></BLOCKQUOTE>MATLAB is then started on five additional processors taken froma predetermined list.Or perhaps the second author is a sitting at a machine connectedto Cornell's Computer Science Department network. Hetypes<BLOCKQUOTE><CODE>Start(['gemini'; 'orion'; 'rigel'; 'castor'; 'pollux'])</CODE></BLOCKQUOTE>Now MATLAB is started on the five processors with the namesindicated. (Some names could be repeated, in which case multipleMATLAB processes would be started on a single processor.)In either case, when all the processes are started the message is returned,<BLOCKQUOTE><CODE>6 MultiMATLAB processes running.</CODE></BLOCKQUOTE>This total number of processors can subsequentlybe accessed by the MultiMATLAB command <CODE>Nproc</CODE>.<P>The standard MultiMATLAB command for executing commands onone or more processors is <CODE>Eval</CODE>.If the user now types<BLOCKQUOTE><CODE>Eval( 'sqrt(2)' )</CODE></BLOCKQUOTE>then the MATLAB command <CODE>sqrt(2)</CODE> is executedon all six processors.The result is six repetitions of <CODE>1.4142</CODE>,which is not very interesting.On the other hand the command<BLOCKQUOTE><CODE>Eval( 'ID' )</CODE></BLOCKQUOTE>calls the MultiMATLAB command <CODE>ID</CODE>on each of the processors running. This commandreturns the number of the current process, an integerfrom 0 to <CODE>Nproc</CODE>-1. Running it on allnodes might give the result<BLOCKQUOTE><CODE>ans = 0<BR>ans = 1<BR>ans = 5<BR>ans = 2<BR>ans = 3<BR>ans = 4</CODE></BLOCKQUOTE>The ordering of these numbers is arbitrary,since the processors are not synchronized and outputis sent to the master process as soon as it is ready.(It is a good idea totype <CODE>Eval('format compact')</CODE> at the beginningto keep theoutput from the various processes as condensed as possible.)The command<BLOCKQUOTE><CODE>Eval( 'ID^ID' )</CODE></BLOCKQUOTE>might produce<BLOCKQUOTE><CODE>ans = 1<BR>ans = 1<BR>ans = 256<BR>ans = 3125<BR>ans = 27<BR>ans = 4</CODE></BLOCKQUOTE><P>In the above examples, in keeping with our orientation towardSPMD programming, each command passed to <CODE>Eval</CODE> wasexecuted on all MATLAB processes. Alternatively, one canselect a subset of the processes by passing two arguments tothe <CODE>Eval</CODE> command, the first beinga vector of process IDs. Thus<BLOCKQUOTE><CODE>Eval( [4 5] , 'cond(hilb(ID))' )</CODE></BLOCKQUOTE>might return<BLOCKQUOTE><CODE>ans = 1.5514e+04<BR>ans = 4.7661e+05</CODE>,</BLOCKQUOTE>the condition numbers of the Hilbert matrices of dimensions4 and 5, and<BLOCKQUOTE><CODE>Eval( 0:2:4 , 'quad(''exp'',ID,ID+1)' )</CODE></BLOCKQUOTE><P>might return<BLOCKQUOTE><CODE>ans = 1.7183<BR>ans = 93.8151<BR>ans = 12.6965</CODE></BLOCKQUOTE>the integrals of <VAR>e</VAR><SUP><VAR>x</VAR></SUP> from <VAR>n</VAR> to<VAR>n</VAR>+1 for <VAR>n</VAR> = 0, 2, and 4.Note how the double quote is used to obtain a stringwithin a string. This calling of the MATLAB command<CODE>quad</CODE> gives a hint of the high-level poweravailable that is so characteristic of MATLAB. In thiscase, adaptive numerical quadrature has been carried outto compute the desired integral. MATLAB users areaccustomed to treating problems like integration, zerofinding,minimization, and computation of eigenvalues as routinematters to be handled silently by appropriate single-word commands.<P>None of these examples were costly enough for the use ofmultiple processors to serve much purpose, but it iseasy to devise such examples. Suppose we want tofind the spectral radii (maximum of the absolute values of theeigenvalues) of sixmatrices of dimension 400. The command<BLOCKQUOTE><CODE>Eval( 'max(abs(eig(randn(400))))' )</CODE></BLOCKQUOTE><P>does not do the trick; we get six copies of the number<CODE>20.8508</CODE>, since the random number generators deliveridentical results on all processors. Preceding the eigenvaluecomputation by<BLOCKQUOTE><CODE>Eval( 'randn(''seed'',ID)' )</CODE>,</BLOCKQUOTE><P>however, leads to the result desired:<BLOCKQUOTE><CODE>ans = 20.9729<BR>ans = 20.8508<BR>ans = 21.0364<BR>ans = 21.0312<BR>ans = 21.6540<BR>ans = 20.4072</CODE></BLOCKQUOTE>(The spectral radius of an <VAR>n</VAR> by <VAR>n</VAR>random matrix is approximately the square root of <VAR>n</VAR>,for large <VAR>n</VAR>.) In a typical experimentthis example might run in 23 seconds on six thinnodes of our SP2; the elapsed time would be six times greaterif one used a <CODE>for</CODE> loop on a single machine.Of course, Monte Carlo experiments like this one arealways the easiest examples of embarrassingly parallel computations.<P>For simplicity, the examples above call <CODE>Eval</CODE>with an explicit MATLAB command as an argument string.For most applications, however, a user will want to execute a program(an m-file) rather than a single line of text. A command such as<BLOCKQUOTE><CODE>Eval( 'filename' )</CODE></BLOCKQUOTE>achieves this effect.<H3>2.2. Put, Get</H3>So far, we have not communicated between processes exceptto send screen output to the master process. Of course, a nontrivialMultiMATLAB system depends on such communication.<P>One form of communication we have implemented is puts and gets,executable solely by the master MATLAB process. For example,the command<BLOCKQUOTE><CODE>Put(1:4,'A')</CODE>,</BLOCKQUOTE>sends the matrix <CODE>A</CODE> from the master process 0to processes 1 through 4; anoptional argument permits the name of <CODE>A</CODE> tobe changed at the destination. The command<BLOCKQUOTE><CODE>Get(3,'B')</CODE>,</BLOCKQUOTE>gets the matrix <CODE>B</CODE> back from process 3 to the master.<P><H3>2.3. Send, Recv, Probe, Barrier</H3>More general point-to-point communication is accomplished by send and receivecommands, which can be executed on any of the MATLAB processes.For example, the sequence<BLOCKQUOTE><CODE>x = [pi pi^2];<BR>Send(3,x)<BR>Eval(3, 'Recv' )<BR></CODE></BLOCKQUOTE>passes a message containing a 2-vector from the masterprocess to process 3, leading to the output<BLOCKQUOTE><CODE>3.1416 9.8696</CODE></BLOCKQUOTE>An optional argument can be added in <CODE>Recv</CODE>to specify the source. Another optional argument may be addedin both <CODE>Send</CODE> and <CODE>Recv</CODE> tospecify a message tag so as to ensure thatsends and receives are properly matched and to aid in errorchecking.The command<BLOCKQUOTE><CODE>Probe</CODE>,</BLOCKQUOTE>run on any process, again with optional source processnumber and message tag, returns 1 (true) if a message
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?