官术网_书友最值得收藏!

Communicating in parallel programming

In parallel programming, the workers that are sent to perform a task often need to establish communication so that there can be cooperation in tackling a problem. In most cases, this communication is established in such a way that data can be exchanged amongst workers. There are two forms of communication that are more widely known when it comes to parallel programming: shared state and message passing. In the following sections, a brief description of both will be presented.

Understanding shared state

One the most well-known forms of communication amongst workers is shared state. Shared state seems straightforward to use but has many pitfalls because an invalid operation made to the shared resource by one of the processes will affect all of the others, thereby producing bad results. It also makes it impossible for the program to be distributed between multiple machines for obvious reasons.

Illustrating this, we will make use of a real-world case. Suppose you are a customer of a specific bank, and this bank has only one cashier. When you go to the bank, you must head to a queue and wait for your chance. Once in the queue, you notice that only one customer can make use of the cashier at a time, and it would be impossible for the cashier to attend two customers simultaneously without potentially making errors. Computing provides means to access data in a controlled way, and there are several techniques, such as mutex.

Mutex can be understood as a special process variable that indicates the level of availability to access data. That is, in our real-life example, the customer has a number, and at a specific moment, this number will be activated and the cashier will be available for this customer exclusively. At the end of the process, this customer will free the cashier for the next customer, and so on.

Note

There are cases in which data has a constant value in a variable while the program is running, and the data is shared only for reading purposes. So, access control is not necessary because it will never present integrity problems.

Understanding message passing

Message passing is used when we aim to avoid data access control and synchronizing problems originating from shared state. Message passing consists of a mechanism for message exchange in running processes. It is very commonly used whenever we are developing programs with distributed architecture, where the message exchanges within the network they are placed are necessary. Languages such as Erlang, for instance, use this model to implement communication in its parallel architecture. Once data is copied at each message exchange, it is impossible that problems occur in terms of concurrence of access. Although memory use seems to be higher than in shared memory state, there are advantages to the use of this model. They are as follows:

  • Absence of data access concurrence
  • Messages can be exchange locally (various processes) or in distributed environments
  • This makes it less likely that scalability issues occur and enables interoperability of different systems
  • In general, it is easy to maintain according to programmers
主站蜘蛛池模板: 江陵县| 冷水江市| 玉田县| 额尔古纳市| 江门市| 方正县| 尤溪县| 迭部县| 和顺县| 景泰县| 页游| 烟台市| 扶余县| 聂拉木县| 千阳县| 田阳县| 高邮市| 公安县| 富蕴县| 农安县| 汾阳市| 静乐县| 都昌县| 建瓯市| 五华县| 象州县| 清丰县| 丹阳市| 凉山| 扎鲁特旗| 竹溪县| 弥渡县| 宜昌市| 颍上县| 谷城县| 田阳县| 集安市| 丽水市| 余庆县| 安顺市| 微博|