Skip to content

Parallel and distributed computing

Python for AP CS Principles Lesson 13 2:11 English narration · English + 中文 subtitles burned in

space play · ←/→ 5s · j/l 10s · f fullscreen · ,/. speed

Chapters

Transcript
Most simple programs are sequential: step one finishes before step two starts. 大多数简单程序是顺序执行的: 第一步跑完了,第二步才开始。
Easy to follow, but slow for a big job — look at how far that top row runs. 好懂,但对大活儿来说慢——看上面那一行拖得多长。
Parallel computing splits the work so several parts run at the same time. 并行计算把工作拆开,让好几部分同时进行。
A modern chip has several cores, so four workers can each take one task. 现代芯片有好几个核心, 所以四个"工人"可以一人领一个任务。
Total time drops from all four added together to about the longest single task. 总时间就从四个加起来, 降到大约只等于最长的那一个任务。
Speedup asks how many times faster the parallel version is, and it is just one division: sequential time divided by parallel time. 加速比问的是:并行版本快了多少倍。 而它就是一个除法:顺序时间除以并行时间。
A job that takes eight seconds in order but two seconds split up gives eight over two — a speedup of four times. 一个活儿按顺序做要 8 秒,拆开做只要 2 秒, 那就是 8 除以 2——加速 4 倍。
But more processors does not mean N times faster, and this is what the exam is really asking. 但处理器多了,并不等于快 N 倍, 而这正是考试真正在问的。
Some parts of a job cannot be split — they have to happen in order. 一个活儿里有些部分是"拆不开"的——它们必须按顺序发生。
Watch the two rows: the main work shrinks by four, but the setup block stays the same length. 看这两行:主体工作缩短到四分之一, 但那块"准备"始终是原来的长度。
Add a hundred workers and it still stays the same length. 再加一百个工人,它还是那么长。
Plus, splitting the work and joining the results back up costs something too. 另外,把工作拆开、再把结果合起来,本身也要花时间。
Distributed computing takes the same idea further: instead of several cores in one machine, many separate computers cooperate over a network. 分布式计算把同样的想法推得更远: 不是一台机器里的几个核心, 而是许多台各自独立的计算机通过网络协作。
They might be in different rooms, or different countries — the web itself works this way, and so do big science projects. 它们可能在不同的房间,甚至不同的国家—— 万维网本身就是这么运作的,大型科研项目也是。
The trade is the same one, only sharper: much faster and able to handle huge jobs, but harder to write, and the network adds delay. 代价还是同一个,只是更明显: 快得多,也扛得住巨大的活儿, 但代码更难写,而且网络还会带来延迟。
Four things to take with you. 带走四点。
One: parallel computing runs parts at the same time. 第一:并行计算让各部分同时进行。
Two: speedup is sequential time divided by parallel time. 第二:加速比是顺序时间除以并行时间。
Three: the part that cannot be split caps the speedup. 第三:拆不开的那部分给加速比设了上限。
Four: distributed computing spreads a job over machines. 第四:分布式计算把一个活儿铺到多台机器上。
Now compute some speedups in the tasks below. 现在去下面的题里算几个加速比。

Log in or create account

IGCSE, A-Level & AP