- Parallel Programming with Python
- Jan Palach
- 516字
- 2021-07-16 11:22:19
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.
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
- Access 數據庫應用教程
- Python進階編程:編寫更高效、優雅的Python代碼
- Elastic Stack應用寶典
- Hands-On GPU:Accelerated Computer Vision with OpenCV and CUDA
- 前端HTML+CSS修煉之道(視頻同步+直播)
- Oracle 18c 必須掌握的新特性:管理與實戰
- Red Hat Enterprise Linux Troubleshooting Guide
- Deep Learning with R Cookbook
- 算法秘籍
- AutoCAD基礎教程
- INSTANT Apache Hive Essentials How-to
- 安卓工程師教你玩轉Android
- Mapping with ArcGIS Pro
- Dart:Scalable Application Development
- ANSYS FLUENT 16.0超級學習手冊