消息传递和共享内存并发模型之间的区别是什么?

时间:2021-03-06 02:18:34

Correct me if I'm wrong, but I'm surprised this hasn't been asked before on here ...

如果我说错了,请纠正我,但我很惊讶在这之前没有人问过这个问题……

7 个解决方案

#1


76  

It's a pretty simple difference. In a shared memory model, multiple workers all operate on the same data. This opens up a lot of the concurrency issues that are common in parallel programming.

这是一个很简单的区别。在共享内存模型中,多个工作人员都使用相同的数据。这打开了并行编程中常见的许多并发问题。

Message passing systems make workers communicate through a messaging system. Messages keep everyone seperated, so that workers cannot modify each other's data.

消息传递系统使工作者通过消息传递系统进行通信。消息让每个人都分开,这样员工就不能修改彼此的数据。

By analogy, lets say we are working with a team on a project together. In one model, we are all crowded around a table, with all of our papers and data layed out. We can only communicate by changing things on the table. We have to be careful not to all try to operate on the same piece of data at once, or it will get confusing and things will get mixed up.

通过类推,让我们说我们正在和一个团队一起合作一个项目。在一个模型中,我们都挤在一张桌子周围,所有的文件和数据都被放出来了。我们只能通过改变桌子上的东西来交流。我们必须小心,不要试图同时对同一块数据进行操作,否则会混淆,事情会搞混。

In a message passing model, we all sit at our desks, with our own set of papers. When we want to, we can pass a paper to someone else as a "message", and that worker can now do what they want with it. We only ever have access to whatever we have in front of us, so we never have to worry that someone is going to reach over and change one of the numbers while we are in the middle of summing them up.

在一个传递信息的模型中,我们都坐在自己的办公桌前,用我们自己的一套文件。当我们想要的时候,我们可以把一份文件传递给别人,作为“信息”,而那个工人现在可以用它来做他们想做的事情。我们只能够接触到我们面前的任何东西,所以我们不必担心有人会在我们正在总结的过程中改变其中一个数字。

Ok, silly analogy!

好吧,愚蠢的比喻!

#2


12  

  1. In shared memory model, memory is shared by cooperating processes, which can exchange information by reading and writing data but in message passing communication takes place by means of messages exchanged between the cooperating processes.
  2. 在共享内存模型中,通过协作进程共享内存,通过读取和写入数据交换信息,但通过在协作过程之间交换的消息来进行消息传递。
  3. Shared memory helps run processes concurrently but message passing cannot.
  4. 共享内存有助于同时运行进程,但消息传递不能。
  5. Message passing facility has two operations: send (message) and receive (message). The process of which has fixed or variable size.
  6. 消息传递工具有两个操作:发送(消息)和接收(消息)。具有固定或可变尺寸的过程。
  7. Message passing is useful for exchanging smaller amounts of data, because no conflicts need be avoided. Message passing is also easier to implement than is shared memory for interprocess communication.
  8. 消息传递对于交换较小数量的数据非常有用,因为不需要避免冲突。消息传递也比用于进程间通信的共享内存更容易实现。
  9. In shared-memory systems, system calls are required only to establish shared-memory regions. Once shared memory is established, all accesses are treated as routine memory accesses, and no assistance from the kernel is required.
  10. 在共享内存系统中,系统调用只需要建立共享内存区域。一旦建立了共享内存,所有访问都被视为常规内存访问,不需要内核的帮助。

Faster

Shared memory allows maximum speed and convenience of communication, as it can be done at memory speeds when within a computer. Shared memory is faster than message passing, as message-passing systems are typically implemented using system calls and thus require the more time-consuming task of kernel intervention.

共享内存允许最大速度和通信方便,因为它可以在计算机内以内存速度进行。共享内存比消息传递快,因为消息传递系统通常是使用系统调用实现的,因此需要更耗时的内核干预任务。

#3


8  

Message passing models (Erlang, for example) do not have any shared state; all synchronization and communication is done by exchanging messages. Shared memory models communicate by reading/writing to shared memory blocks, which are protected by semaphores or similar.

消息传递模型(例如Erlang)没有任何共享状态;所有的同步和通信都是通过交换消息完成的。共享内存模型通过读取/写入到共享内存块进行通信,共享内存块受到信号量或类似的保护。

#4


3  

message passing are good method to justify data but it has slow response time for faster communication.But in shared memory model data are extracted from one memory and a working group can do different work over same data

消息传递是一种很好的方法来证明数据的合理性,但是它的响应时间较慢,以进行更快的通信。但是,在共享内存模型数据中,从一个内存中提取数据,一个工作组可以在相同的数据上做不同的工作。

#5


2  

The throughput of the message passing system may be too low for some applications that require fast responses time, but if you need higher speed or real time processing, then you can use a shared memory system.

对于一些需要快速响应时间的应用程序来说,消息传递系统的吞吐量可能太低了,但是如果您需要更高的速度或实时处理,那么您就可以使用共享内存系统。

#6


2  

Though you are asking for the differences between message-passing model and shared memory model and have already got good answers concerning about their performances, ways of exchanging information, and concurrency issues, I would like to point out that:

尽管您在询问消息传递模型和共享内存模型之间的差异,并且已经得到了关于它们的性能、交换信息和并发问题的良好答案,但我想指出:

There can be no fundamental differences between them regarding their computability (under certain conditions).

他们的可计算性(在某些条件下)之间没有根本的区别。

You can simulate a shared memory over the underlying message-passing system. This makes it possible to view the shared memory model as a higher-level language for designing algorithms in asynchronous distributed message-passing systems.

您可以在底层消息传递系统上模拟共享内存。这使得可以将共享内存模型看作是在异步分布式消息传递系统中设计算法的高级语言。

In particular, this paper ABD@JACM'95 shows that

特别地,这篇文章ABD@JACM'95显示了这一点。

Any wait-free algorithm based on atomic, single-writer (and multi-writer) multi-reader registers can be automatically emulated in message-passing systems, provided that at least a majority of the processors are not faulty and remain connected. The overhead introduced by these emulations is polynomial in the number of processors in the system.

任何基于原子、单作者(和多作者)多读者寄存器的无等待算法都可以在消息传递系统中自动模拟,前提是至少大多数处理器没有错误并保持连接。这些仿真所引入的开销是系统中处理器数量的多项式。

#7


0  

To differentiate between Message passing and shared memory consider five things:

要区分消息传递和共享内存,请考虑以下五件事:

  1. communication:- In the case of message passing, communication is dependent on Programmer like to which process to which it will communicate. but in the case of shared memory communication is done automatically.
  2. 通信:-在消息传递的情况下,通信依赖于程序员,例如它将与哪个进程通信。但是在共享内存通信的情况下是自动完成的。
  3. data distribution:-m.p(Manually) s.m(Automatic)
  4. 数据分布:国会*(手动)s.m(自动)
  5. H/W support:- m.p(simple) s.m(Extensive because it have to be intelligent to detect the interprocess automatically)
  6. H / W支持:-国会*(简单的)。m(广泛的,因为它必须是智能的自动检测进程)
  7. correctness:-m.p(difficult) s.m(less difficult)
  8. 正确性:国会*(困难)。(困难)
  9. performance:-m.p(difficult) s.m(very difficult)`
  10. 性能:国会*(困难)。(很难)”

#1


76  

It's a pretty simple difference. In a shared memory model, multiple workers all operate on the same data. This opens up a lot of the concurrency issues that are common in parallel programming.

这是一个很简单的区别。在共享内存模型中,多个工作人员都使用相同的数据。这打开了并行编程中常见的许多并发问题。

Message passing systems make workers communicate through a messaging system. Messages keep everyone seperated, so that workers cannot modify each other's data.

消息传递系统使工作者通过消息传递系统进行通信。消息让每个人都分开,这样员工就不能修改彼此的数据。

By analogy, lets say we are working with a team on a project together. In one model, we are all crowded around a table, with all of our papers and data layed out. We can only communicate by changing things on the table. We have to be careful not to all try to operate on the same piece of data at once, or it will get confusing and things will get mixed up.

通过类推,让我们说我们正在和一个团队一起合作一个项目。在一个模型中,我们都挤在一张桌子周围,所有的文件和数据都被放出来了。我们只能通过改变桌子上的东西来交流。我们必须小心,不要试图同时对同一块数据进行操作,否则会混淆,事情会搞混。

In a message passing model, we all sit at our desks, with our own set of papers. When we want to, we can pass a paper to someone else as a "message", and that worker can now do what they want with it. We only ever have access to whatever we have in front of us, so we never have to worry that someone is going to reach over and change one of the numbers while we are in the middle of summing them up.

在一个传递信息的模型中,我们都坐在自己的办公桌前,用我们自己的一套文件。当我们想要的时候,我们可以把一份文件传递给别人,作为“信息”,而那个工人现在可以用它来做他们想做的事情。我们只能够接触到我们面前的任何东西,所以我们不必担心有人会在我们正在总结的过程中改变其中一个数字。

Ok, silly analogy!

好吧,愚蠢的比喻!

#2


12  

  1. In shared memory model, memory is shared by cooperating processes, which can exchange information by reading and writing data but in message passing communication takes place by means of messages exchanged between the cooperating processes.
  2. 在共享内存模型中,通过协作进程共享内存,通过读取和写入数据交换信息,但通过在协作过程之间交换的消息来进行消息传递。
  3. Shared memory helps run processes concurrently but message passing cannot.
  4. 共享内存有助于同时运行进程,但消息传递不能。
  5. Message passing facility has two operations: send (message) and receive (message). The process of which has fixed or variable size.
  6. 消息传递工具有两个操作:发送(消息)和接收(消息)。具有固定或可变尺寸的过程。
  7. Message passing is useful for exchanging smaller amounts of data, because no conflicts need be avoided. Message passing is also easier to implement than is shared memory for interprocess communication.
  8. 消息传递对于交换较小数量的数据非常有用,因为不需要避免冲突。消息传递也比用于进程间通信的共享内存更容易实现。
  9. In shared-memory systems, system calls are required only to establish shared-memory regions. Once shared memory is established, all accesses are treated as routine memory accesses, and no assistance from the kernel is required.
  10. 在共享内存系统中,系统调用只需要建立共享内存区域。一旦建立了共享内存,所有访问都被视为常规内存访问,不需要内核的帮助。

Faster

Shared memory allows maximum speed and convenience of communication, as it can be done at memory speeds when within a computer. Shared memory is faster than message passing, as message-passing systems are typically implemented using system calls and thus require the more time-consuming task of kernel intervention.

共享内存允许最大速度和通信方便,因为它可以在计算机内以内存速度进行。共享内存比消息传递快,因为消息传递系统通常是使用系统调用实现的,因此需要更耗时的内核干预任务。

#3


8  

Message passing models (Erlang, for example) do not have any shared state; all synchronization and communication is done by exchanging messages. Shared memory models communicate by reading/writing to shared memory blocks, which are protected by semaphores or similar.

消息传递模型(例如Erlang)没有任何共享状态;所有的同步和通信都是通过交换消息完成的。共享内存模型通过读取/写入到共享内存块进行通信,共享内存块受到信号量或类似的保护。

#4


3  

message passing are good method to justify data but it has slow response time for faster communication.But in shared memory model data are extracted from one memory and a working group can do different work over same data

消息传递是一种很好的方法来证明数据的合理性,但是它的响应时间较慢,以进行更快的通信。但是,在共享内存模型数据中,从一个内存中提取数据,一个工作组可以在相同的数据上做不同的工作。

#5


2  

The throughput of the message passing system may be too low for some applications that require fast responses time, but if you need higher speed or real time processing, then you can use a shared memory system.

对于一些需要快速响应时间的应用程序来说,消息传递系统的吞吐量可能太低了,但是如果您需要更高的速度或实时处理,那么您就可以使用共享内存系统。

#6


2  

Though you are asking for the differences between message-passing model and shared memory model and have already got good answers concerning about their performances, ways of exchanging information, and concurrency issues, I would like to point out that:

尽管您在询问消息传递模型和共享内存模型之间的差异,并且已经得到了关于它们的性能、交换信息和并发问题的良好答案,但我想指出:

There can be no fundamental differences between them regarding their computability (under certain conditions).

他们的可计算性(在某些条件下)之间没有根本的区别。

You can simulate a shared memory over the underlying message-passing system. This makes it possible to view the shared memory model as a higher-level language for designing algorithms in asynchronous distributed message-passing systems.

您可以在底层消息传递系统上模拟共享内存。这使得可以将共享内存模型看作是在异步分布式消息传递系统中设计算法的高级语言。

In particular, this paper ABD@JACM'95 shows that

特别地,这篇文章ABD@JACM'95显示了这一点。

Any wait-free algorithm based on atomic, single-writer (and multi-writer) multi-reader registers can be automatically emulated in message-passing systems, provided that at least a majority of the processors are not faulty and remain connected. The overhead introduced by these emulations is polynomial in the number of processors in the system.

任何基于原子、单作者(和多作者)多读者寄存器的无等待算法都可以在消息传递系统中自动模拟,前提是至少大多数处理器没有错误并保持连接。这些仿真所引入的开销是系统中处理器数量的多项式。

#7


0  

To differentiate between Message passing and shared memory consider five things:

要区分消息传递和共享内存,请考虑以下五件事:

  1. communication:- In the case of message passing, communication is dependent on Programmer like to which process to which it will communicate. but in the case of shared memory communication is done automatically.
  2. 通信:-在消息传递的情况下,通信依赖于程序员,例如它将与哪个进程通信。但是在共享内存通信的情况下是自动完成的。
  3. data distribution:-m.p(Manually) s.m(Automatic)
  4. 数据分布:国会*(手动)s.m(自动)
  5. H/W support:- m.p(simple) s.m(Extensive because it have to be intelligent to detect the interprocess automatically)
  6. H / W支持:-国会*(简单的)。m(广泛的,因为它必须是智能的自动检测进程)
  7. correctness:-m.p(difficult) s.m(less difficult)
  8. 正确性:国会*(困难)。(困难)
  9. performance:-m.p(difficult) s.m(very difficult)`
  10. 性能:国会*(困难)。(很难)”