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

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
主站蜘蛛池模板: 平潭县| 西贡区| 托克逊县| 建昌县| 堆龙德庆县| 永靖县| 和静县| 金沙县| 龙门县| 铁岭县| 大化| 阿克苏市| 南岸区| 彭泽县| 宜川县| 广州市| 三门县| 泽库县| 罗田县| 万盛区| 清河县| 即墨市| 长顺县| 四平市| 安乡县| 思茅市| 陵水| 文安县| 惠安县| 冷水江市| 宜兰县| 永年县| 满洲里市| 安远县| 平泉县| 杭锦后旗| 抚宁县| 靖州| 沙雅县| 蓝田县| 郴州市|