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 行
has arrived from the indicated source with the indicated tag,otherwise 0 (false).<P>SPMD programs can be built upon<CODE>Send</CODE> and <CODE>Recv</CODE> commands. Typicallythe program contains <CODE>if</CODE> and <CODE>else</CODE> commandsthat specify different actions for different processes.For example, suppose the m-file <CODE>cycle.m</CODE> consists ofthe following program:<BLOCKQUOTE><CODE><PRE>if ID==0 % first process: send a = 1 Send(ID+1,a)elseif ID == Nproc-1 % last process: receive and double a = 2*Recvelse % middle processes: receive, double, and send a = 2*Recv Send(ID+1,a)end;</PRE></CODE></BLOCKQUOTE>Process 0 creates the variable <CODE>a</CODE> with value 1and sends it to process 1. Process 1 receives the message,doubles the value of <CODE>a</CODE>, and sends it along to process2; and so on. If there are six processors the command<CODE>Eval( 'cycle' )</CODE> produces the output<BLOCKQUOTE><CODE>a = 1<BR>a = 2<BR>a = 4<BR>a = 8<BR>a = 16<BR>a = 32<BR></CODE></BLOCKQUOTE>The processes run asynchronously, but since each<CODE>Send</CODE> command is only executed after the corresponding<CODE>Recv</CODE> has completed, the proper sequence of computationsand final value 32 are guaranteed so long as all of thenodes are functioning.<P>Alternatively, a MultiMATLAB command isavailable for explicit synchronization. The command<BLOCKQUOTE><CODE>Barrier</CODE></BLOCKQUOTE>returns only when called on each process.<H3>2.4. Bcast, Min, Max, Sum</H3>Although <CODE>Send</CODE> takes a vector of processorIDs as its destination list, the underlying idea isthat of point-to-point communication. For more efficientcommunication between multiple processes, as well as greaterconvenience for the programmer, MultiMATLAB also has various commandsfor collective communication. These commands must beevaluated simultaneously on all processes.<P>The <CODE>Bcast</CODE> command is used to broadcast a matrix fromone process to all other processes, using a tree-structured algorithm.For example,<BLOCKQUOTE><CODE>Eval( 'Bcast(1,ID)' )</CODE></BLOCKQUOTE>returns the number 1 on all processes. <CODE>Bcast</CODE> is much moreefficient than a corresponding <CODE>Send</CODE> and <CODE>Recv</CODE>.<P>The same kind of a tree algorithm is used for various computationsthat reduce data from many processes to one. For example, the commands <CODE>Min</CODE>, <CODE>Max</CODE>, and <CODE>Sum</CODE>compute vectors obtained by reducing data over the copies of a vector ormatrix located on all processors. Thus the command<BLOCKQUOTE><CODE>Eval( 'Sum(1,[1 ID Nproc])' )</CODE></BLOCKQUOTE>executed on six processes will return the vector<BLOCKQUOTE><CODE>[6 15 36]</CODE></BLOCKQUOTE>to process 1.If the first argument is omitted, the result is returned (broadcast) toall processes.<P><H3>2.5. Higher-level MultiMATLAB Commands</H3>The MultiMATLAB commands described so far representcommunication primitives as they are used in themessage-passing paradigm of programming. One of the aims of thisproject, however, is to provide also an interface at a higher levelby building on these routines, hidingas much of the message passing as possible.<P>We can do thisby taking a data-parallel approach in a simplistic fashion. We havedeveloped a number of routines such as <CODE>Distribute</CODE> and<CODE>Collect</CODE> thatallow a user to distribute a matrix or to collect a set of matricesinto one large matrix. These functions operate using a mask thatindicates which processors hold which portions of the matrix. Thisallows us also to develop routines such as <CODE>Shift</CODE>and <CODE>Copy</CODE> that are useful in data-parallel computing,keeping the communication to a more abstract level.<P>Additional geometry routines such as <CODE>Grid</CODE> and <CODE>Coord</CODE>have also been constructed that allow the user to createa grid of processors in 1,2 or 3 dimensions. Theseprovide a powerful tool for more sophisticated parallel coding. An optionalargument on the communication routines allows communication within agiven set of nodes, for example along a column or row of the grid.We do not give further details, as these facilities are under development.<P><BR><P><H2>3. Multiprocessor Graphics</H2>One of the great strengths of MATLAB is graphics. A primarygoal of the MultiMATLAB project has been to ensure that thisstrength carries over to multiprocessor computations.<P>In many applications, the user will find it most convenient tocompute on multiple processors but produce plots on the master process, after sending data as necessary. Equally often, however,it may be desirable to produce plots in a distributed fashion thatare then sent to the user's screen. This can be particularly usefulwhen one wishes to monitor the progress of computations on severalprocessors graphically.<P>We have found the following simple method of doing this to be very useful.As mentioned above, many calculationswith a geometric flavor divide easily into, say, four or eightsubdomains assigned to a corresponding set of processors. Weset up a MATLAB figure window in each process and arrange them ina grid on the screen. This is easily done using standard MATLABhandle graphics commands, and we expect shortly to developMultiMATLAB commands for this purpose that are integrated withthe grid operations mentioned earlier.<P>The figure below shows an example ofthis kind of computing;in this case we have a 4 by 1 gridof windows. In this particular example, what has beencomputed are the pseudospectra of a 64 by 64 matrix known asthe "Grcar matrix" [<!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><!WA7><A HREF=#ref_trefethen>17</A>]. This is an easy application for MultiMATLABsince the computation requires a very large number of floating pointoperations (1024singular value decompositions of dimension 64 by 64) but minimal communication(just the global minimum and maximumof the data with <CODE>Min</CODE> and <CODE>Max</CODE>,so that all panels can be on the same scale). <CENTER><PRE><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><!WA8><img src="http://www.cs.cornell.edu/Info/People/lnt/pseudospectra.gif"></PRE></CENTER>Another kind of application that might benefit from this kind of graphics would beas follows. Suppose we wish to solve the wave equation by an explicitfinite difference scheme and watch waves bounce around in the computationaldomain. It is a straightforward matter to divide the computation intoa grid of processors as in the figure above, communicating just one rowor column of boundary data to adjacent processors at each step. Wavescan then be seen to propagate from one window to another. This kindof visualization can be very convenient for interactive experimentation, andhigher-quality plots can be produced at selected time steps as necessaryby sending data to a single processor.<P>Our second computed example illustrates the use of multiplefigure windows for monitoring a process of numerical optimization.MATLAB contains powerful programsfor minimization of functions of several variables; one of the original suchprograms is <CODE>fminu</CODE>. Unfortunately, such programs generallyfind local minima, not global ones. If one requires the global minimumit is customary to run the search multiple times from distinct initial points,which in many cases might as well be taken to be random. With sufficientlymany trials leading to a single smallest minimum found over and over again,one acquires confidence that the global minimum has been found, but thecost of this confidence may be considerable computing time.<P>Such a problem is easily parallelizable, and the next figureshows a casein which it has been distributed to four processors. A function<VAR>f(x,y)</VAR> of two variables has been constructed that has many localminima but just one global minimum, the value 0 taken at the origin.On each of four processors, the optimization is carried out from twentyrandom initial points, and the result is displayed in the corresponding figurewindow as a straight line from the initial guess to the converged value.The background curves are contours of the objective function <VAR>f(x,y)</VAR>. Note that in three of the windows, the smallestvalue obtained is <VAR>f(x,y)</VAR>=0.1935, whereas the fourth windowhas found the global minimum <VAR>f(x,y)</VAR>=0. <CENTER><PRE><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><!WA9><img src="http://www.cs.cornell.edu/Info/People/lnt/opt4.gif"></PRE></CENTER>In these examples we have set up a grid of windows, one to each processor.As an alternative it might be desirable sometimes to have multiple MATLAB processesall draw to one common window.This arrangement is possible within XWindows, for example. However,it is not possible within MultiMATLAB at present, because a figure's window IDis a read-only property in the current version of MATLAB, which cannot beset or reset by the user.<P><BR><P><H2>4. Implementation of MultiMATLAB</H2>MultiMATLAB is built upon <!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><!WA10><A HREF=http://www.mcs.anl.gov/mpi/index.html>MPI</A>(Message Passing Interface), ahighly functional and portable message passing standard
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?