Concurrency != Parallelism

保罗 克里 (1879 - 1940 ):Why Does He Run

前段时间在合作社叫大家大快朵颐GO语言的一部分特性,然后说到了出现概念,大家表示挺糊涂,然后分享进程中我将来了Rob
Pike大神的Slides 《Concurrency is not
Parallelism》,反而为的望族再模糊了,看来大家抛弃了许多先的基本知识。后来本身就管Pike大神的slide和网上的有牛人关于Cocurrency和Parallelism的意见做了整,最终写了本文。

过剩人口觉得好的还是高等级的艺术作品一定包涵了深刻的沉思。艺术生思为?艺术是表达思想的家伙也?要回应是题材,首先要清理“艺术”和“思想”的概念。

在Rob Pike的《Concurrency is not
Parallelism》(http://talks.golang.org/2012/waza.slide)中说到,我们的世界是Parallelism,比如网络,比如大量独立的个人。但是需要协作的。所以就有了并发。很多人认为并发很COOL,认为并发就是并行。但是这种观念在ROB
PIKE看来是谬误的。比如事先发生个人写了一个质数筛选的先后,然后这个运行在4核查的平台上,但是运行结果十分缓慢。这个程序员错误的觉得GO提供的起就是并行计算。

自家好对法之定义,在“生命的款型”一平和被有相对详细的论述。简单地游说不怕是:艺术是故来发表我们的感觉存在的介绍人。而针对想,我之概念是:思想是人思想的过程与结果的总称。过程包括对外以世界(包括人口我)的观,综合,逻辑推演等等,结果就是是意见,观念等等。

于Rob的此slide中推了一个地鼠烧书的事例,在自己跟侣们共看之时段表示未绝了解,所以开了有的学业来理解。

看来,艺术与思想是全人类精神活动之少数万分接近,一个分包“感性活动”,一个象征“理性活动”,一个传达感情,一个传达概念。这两者都生和好的一枝独秀代表:代表纯理性类的有哲学,逻辑学,以及科学等等,代表纯感性类的来音乐,非主题性绘画与雕塑,意象诗歌(以及任何众多现代诗歌流派)。

以还爱的整治懂Rob提的产出不是互为的概念,就用整治明白并作和互动到底有啊分别。

针对章程和思索之模糊,我发现首先是觉得很多人错误地将人之全方位精神活动都看成“思想”,而无看到思想才是食指之动感活动的一个种类。好多人数理解中之“思想”,其实该让称之为“精神活动”(intellectual
activity)。“精神活动”是一个总归概念,包括了人类在也釜底抽薪在问题之主干工作之外的有所智慧活动,比如对,政治,文学,艺术,宗教,等等。所以措施及思想和于属于及精神活动是总概念,且彼此独立。

于Rob看来,Concurrency是同样种植把有单独的执行进程组合起来的次设计艺术。

附带,对章程和揣摩之混肴还来自好多丁误把艺术家的灵感和撰写目的都当做思想的习惯。尽管不少人数理解方法是形象化的,但要看当形象化的外表下埋伏着思想。这大概是坐多数丁于普通的历史观所屏障,看不到一样栽在理性思考之外的纯感性存在。这个“纯感性”的在,就是平等栽生命的直照射(或者好说凡是“直觉”),一种超了逻辑观念,主义的感性形式。这个跟思完全无关的纯感性,才是音乐家和过剩“纯艺术”家的灵感内涵。对这种纯感性的直白把,可以说凡是乐至始至终的习俗,也是现代打与诗篇的重中之重追求。

设若Parallelism是还要推行有恐怕相关(结果相关而休是负耦合关系之连带)或者独立计算过程。

主意和思维,也不是绝对立的。在人类精神活动之很多领域,思想及措施都得以以与。比如文学。由于文字既是思考之传媒,也是感情的媒体,所以文学是做方式的含有能力最为特别,可以表达思想,也可以表达感情,甚至足以发表“纯艺术”

Rob总结到:

  • 本诗歌。另外,电影,戏剧,行为艺术等,都是思考和情感并存的法门形式。

Concurrency is about dealing with lots of things at one.

重复确切地说,艺术之定义应该来狭义的以及广义的底分。狭义的艺术就是不过包括对生之神志部分的复发方式,如音乐,(纯艺术)绘画等;广义的饶概括了文学,戏剧和影片之类这种既会发表情感,又能够涵盖思想的点子形式。

Parallelism is about doing lots of things at one. Not the same, but
related.

总而言之,在措施和思辨之涉上,最要害的,就是法并非思想之载体。艺术又要的凡感性生命之传递媒介。

Concurrency is about structure, parallelism is about execution.

04/20/2011

Concurrency provides a way to structure a solution to solve a problem
that may(but not necessarily) be parallelizable.


Rob还提到:

Concurrency is a way to structure a program by breaking it into pieces
that can be executed independently.

Communication is the means to coordinate the independent executions.

This is the GO model and it's based on CSP.

图片 1

面的特发一样才地鼠推着小车将同堆积语言手册运送至焚烧炉中烧掉。如果手册很多,运送距离颇远,那么周经过将花很多日。

图片 2

然后搭一只有地鼠来一同帮忙做这业务,但是简单独人口来举行,只发一致部小推车是不够的,所以需要再多之车子

图片 3

虽说车子增加了,但是出或手册不敷少了,或者炉子不足够用了,而且简单但地鼠需要做工作的下协商搬书到车里,或者协商谁先用炉子。工作效率也无是极端胜。

图片 4

用我们把它确实的独门开。它们之间就无欲商谈了,也都起足的手册可以烧了。

则上面两一味地鼠都分开独立的运作了,但是它们之间时有发生起成分(Concurrent
composition)存在。

假要于一个单位时间外,只出同样止地鼠在干活,它们就是不是互(Parallel),它们或出现的。

以此企划无是为着有意并行而设计,但是可自地转向为而相互的(The design
is not automatically parallel. However, it's automatically
parallelizable)。

又这起成分还暗示了生其他的模子。

图片 5

此地三只有地鼠活动,可能有点延迟。每个地鼠都是一个单身的实践进程。它们协作交流。

图片 6

这边新添了平独地鼠用于推送空车子到装书处。每只地鼠都只有做同桩业务。这个起的粒度比原先的再度周密小了。

假若我们拿全路是的配备好(虽然可能使得人怀疑,但是不要无可能),这个规划会较最开始的那么无异单独地鼠的效率要及早4倍。

俺们于初的设计里搭了一个涌出的实施进程提升了性。

Different concurrent designs enable different ways to parallelize.

这种出现的计划好充分爱的使这个流程并行的行。比如下面这样:8光地鼠繁忙的干活。

图片 7

待牢记的凡,即使在单位时外只发生相同特地鼠在走,此时虽未是互的,但是这个计划或一个不错的起的化解方案。

再有另外一种结构来团片只是地鼠的并发因素.即当点滴单纯地鼠中间再次追加一堆积手册。

图片 8
然后我们得以呢不行易之并行执行:

图片 9

还有一个集团措施:

图片 10

然后重新并行它:

图片 11

今日发生16就地鼠在做事了!

发生众多法得以讲一个过程。这个说的过程尽管出现的筹划。一旦我们做好解释,并行化和是就会见变换的善。
There are many ways to break the processing down. That's concurrent
design. Once we have the breakdown, parallelization can fall out and
correctness is easy.

一个扑朔迷离的问题可分解为多单可以简单容易亮的有些,然后将她并发地(concurrently)组合在一起。最后获得一个简易好掌握,高效之,可伸缩的而是的宏图。甚至足以相互。

并发是非常有力的,虽然未是相互,但是可以就相互,而且得好之做到互相,甚至是可伸缩性或者其它任何的东西。

管方地鼠的例证转换到我们计算机中,书堆就好比网页内容,地鼠好于CPU,小推车好于序列化器或者渲染过程,或者网络,而火炉就是最终之主顾,比如浏览器。

身为浏览器发起呼吁,地鼠开始工作,把用之网页内容渲染好,然后通过网再发作回浏览器。这为即成了一个对可伸缩的WEB服务做的面世的计划性。

于Golang中,Goroutine就是一个跟另外goroutine在一如既往地址空间不过是单身执行的函数。Goroutine不是线程,虽然有些像,但是于线程更轻量。

Goroutine会被多路复用到得之网线程中。当一个goroutine阻塞了,其连带的线程也死了,但是任何的goroutine没有死(注:这种阻塞是靠有网调用,而例如网络操作,CHANNEL操作之类的,goroutine会被放入等待队列中,等运行规范建立,比如网络操作了,或者打CHANNEL中处理好收发,那么即使见面被切换至运行班中运作)

Golang还提供了Channel用于goroutine之间的共同数据交换。Select语句看似于switch,只是是用于判断哪个channel可以通信。 

Golang是确实支持并发,一个Golang可以创建充分多之goroutine,比如一个测试程序创建了130W单goroutine,而且每个goroutine的库开始之早晚还较粗,但是会待扩大或收缩。但是Goroutine不是免费的,但是是轻量的。


总结

用以区分Concurrency和Parallelism的无限好之事例是哲学家进餐问题。经典哲学家进餐问题遭,如果刀要叉不够的早晚,每个哲学家就待商谈来管总有一个人口能吃到饭。而如餐具足够了,那么就是用商谈了,大家好挺嗨皮的各级吃各的了。

Concurrency同Parallelism最可怜的分别是只要满足Concurrency,每个独立的执行体之间必须发合作,协作工具比如锁还是信号量,或者队列。

设若Parallelism虽然为发好多独的执行体,但是它们不是急需合作的,只待好运行,计算产生结果,最后为集中起来就吓了。

Concurrency是平种植问题解释和团章程,而Parallelism一栽实施方式。两者不同,但是来自然之关联。

咱大部分的题材还好切割成密切小之问题,每个问题看作一个独自的执行体执行,相互间发生合作,它们就是Concurrency。

这种计划方并无是为着Parallelism,但是这种规划好自然而然的转折为而互相的。而且这种计划方法尚能确保对。

Concurrency不管是单核机器还是多核机器,还是网络或者其它平台,都独具更好的紧缩性;

假设Parallelism在单核机器上就做不顶真的Parallelism。但是Concurrency在多核机器上反有或自然而然的迈入为Parallelism。

Concurrency的网的结果是匪确定的(indeterminate),为了保证确定性,需要用锁或者其他方缓解。而Parallelism的结果是确定的。

Golang是支持并发的,可以成功相互的行Goroutine(即通过runtime.GOMAXPROC设置P的数量)。基于CSP提供了Goroutine,channel和select语句,提倡大家通过Message-Passing进行合作,而未是透过锁等工具。这种合作方法可以带动重新好之而扩展性。


于维基百科中,至于Concurrent的概念如下:

Concurrent computing is a form of
computing in which several
computations are executing
during overlapping time periods –
concurrently)
– instead of sequentially (one completing before the next starts).
This is a property of a system – this may be an individual
program, a
computer, or a
network – and there is
a separate execution point or "thread of control" for each computation
("process"). A concurrent system is one where a computation can make
progress without waiting for all other computations to complete – where
more than one computation can make progress at "the same time" 

Concurrent computing is related to but distinct from parallel
computing, though
these concepts are frequently confused, and both can be described as
"multiple processes executing at the same time". In parallel
computing, execution literally occurs at the same instant, for example
on separate
processors of a
multi-processor machine
– parallel computing is impossible on a
(single-core) single
processor, as only one computation can occur at any instant (during any
single clock cycle).(This is discounting parallelism internal to a
processor core, such as pipelining or vectorized instructions. A
single-core, single-processor machine may be capable of some
parallelism, such as with a
coprocessor, but the
processor itself is not.) By contrast, concurrent computing consists of
process lifetimes overlapping, but execution need not happen at the
same instant.

For example, concurrent processes can be executed on a single core by
interleaving the execution steps of each process via time slices: only
one process runs at a time, and if it does not complete during its time
slice, it is paused, another process begins or resumes, and then later
the original process is resumed. In this way multiple processes are
part-way through execution at a single instant, but only one process is
being executed at that instant.

Concurrent computations may be executed in parallel, for example by
assigning each process to a separate processor or processor core, or
distributing a
computation across a network. This is known as task
parallelism, and this
type of parallel computing is a form of concurrent computing.

The exact timing of when tasks in a concurrent system are executed
depend on the scheduling, and tasks need not always be executed
concurrently. For example, given two tasks, T1 and T2:

  • T1 may be executed and finished before T2
  • T2 may be executed and finished before T1
  • T1 and T2 may be executed alternatively (time-slicing)
  • T1 and T2 may be executed simultaneously at the same instant of time
    (parallelism)

The word "sequential" is used as an antonym for both "concurrent" and
"parallel"; when these are explicitly distinguished,
concurrent/sequential and parallel/serial are used as opposing pairs

Concurrency的定义如下:

In computer science,
concurrency is a property of systems in which several
computations are
executing)
simultaneously, and potentially interacting with each other. 

The computations may be executing on multiple
cores in the same
chip, preemptively
time-shared)
threads) on the
same processor, or executed on physically separated processors. 

A number of mathematical models have been developed for general
concurrent computation including Petri
nets,process
calculi, the Parallel
Random Access
Machine
model, the Actor model and
the Reo Coordination
Language.

Because computations in a concurrent system can interact with each other
while they are executing, the number of possible execution paths in the
system can be extremely large, and the resulting outcome can be
indeterminate.
Concurrent use of shared
resources)
can be a source of indeterminacy leading to issues such as
deadlock, and
starvation.

The design of concurrent systems often entails finding reliable
techniques for coordinating their execution, data exchange, memory
allocation, and execution scheduling to minimize response time and
maximize throughput.

有关Parallelism的概念如下:

Parallel computing is a form of computation in which many calculations
are carried out simultaneously

operating on the principle that large problems can often be divided into
smaller ones, which are then solved concurrently (“in parallel”).

By contrast, parallel computing by data
parallelism may or may
not be concurrent computing – a single process may control all
computations, in which case it is not concurrent, or the computations
may be spread across several processes, in which case this is
concurrent. For example, SIMD
(single instruction, multiple data) processing is (data) parallel but
not concurrent – multiple computations are happening at the same instant
(in parallel), but there is only a single process. Examples of this
include vector
processors and graphics
processing units
(GPUs). By contrast, MIMD (multiple
instruction, multiple data) processing is both data parallel and task
parallel, and is concurrent; this is commonly implemented as
SPMD (single program, multiple
data), where multiple programs execute concurrently and in parallel on
different data.

Concurrency有Parallelism所不具的性状:interacting。并发的次序中,每个执行体之间还是好相互作用的。

相关文章

Comment ()
评论是一种美德,说点什么吧,否则我会恨你的。。。