正在加载图片...
6 Introduction Regardless of the speed at which a CPU runs,serial processing imposes constraints on the kinds of programs you can run,and therefore write,in MATLAB.Suppose,for example. that you want to find the largest value among a set of numbers.Parallel processing is a natural way to solve this problem.If the values are plotted as in Figure 1.3.2.for example. a brief glance at the bars lets you pick the biggest one.The tallest bar seems to jump out at you.Once it does,you can look down to find the associated element (element 3 in this case).or you can look to the left to find the largest value (39 in this case). Figure1.3.2 You might object that parallel evaluation of the heights of all the bars in this case is not actually possible,and even it were for this particular figure,it wouldn't be for all other sets of numbers.such as those whose largest values are similar.You might also say that the method outlined above is not a truly parallel process because distinct stages are associated with looking down the tallest bar or looking sidewise from the top of the tallest bar.These objections are well taken,especially considering that serial processing is inescapable in tep at a time (serially) Knowing this can help you approach the task of programming.(Many recent computers calake ae procorrh mke para om poea f these to speed compl ng tw things at once,using computations e t your programming skills with this book.yey save paralle 1.4 Programming Principles How should you approach the task of programming?We have come to believe in the fol lowing principle .Decide if a program is actually needed and,if so.whether you should write it .Be as clear as possible about what your program should do. 6 Introduction Regardless of the speed at which a CPU runs, serial processing imposes constraints on the kinds of programs you can run, and therefore write, in MATLAB. Suppose, for example, that you want to find the largest value among a set of numbers. Parallel processing is a natural way to solve this problem. If the values are plotted as in Figure 1.3.2 , for example, a brief glance at the bars lets you pick the biggest one. The tallest bar seems to jump out at you. Once it does, you can look down to find the associated element (element 3 in this case), or you can look to the left to find the largest value (39 in this case). Figure 1.3.2 You might object that parallel evaluation of the heights of all the bars in this case is not actually possible, and even it were for this particular figure, it wouldnÊt be for all other sets of numbers, such as those whose largest values are similar. You might also say that the method outlined above is not a truly parallel process because distinct stages are associated with looking down the tallest bar or looking sidewise from the top of the tallest bar. These objections are well taken, especially considering that serial processing is inescapable in MATLAB, at least in a program that uses MATLAB in its usual configuration. To sort val￾ues or do anything else in MATLAB, everything must be done one step at a time (serially). Knowing this can help you approach the task of programming. (Many recent computers have multiple processors, or cores , that make parallel computing possible. Advanced users can take advantage of these to speed complex computations by having two or more cores compute different things at once, using additional tools available from The MathWorks. If you are beginning your programming skills with this book, you can safely save parallel programming for another time.) 1.4 Programming Principles How should you approach the task of programming? We have come to believe in the fol￾lowing principles: Ć Decide if a program is actually needed and, if so, whether you should write it. Ć Be as clear as possible about what your program should do
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有