Chapter 14
What is a reduction operator? What conditions must be satisfied so that an operator can be a reduction operator?
An operator is a reduction operator if it satisfies the following conditions:
- The operator can reduce an array of elements into one scalar value
- The end result (the scalar value) is obtained through creating and computing partial tasks
What properties do reduction operators have that are equivalent to the required conditions?
The communicative and associative properties are considered to be equivalent to the requirements for a reduction operator.
What is the connection between reduction operators and concurrent programming?
Reduction operators require communicative and associative properties. Consequently, their sub-tasks have to be able to be processed independently, which makes concurrency and parallelism applicable.
What are some of the considerations that must be made when working with multiprocessing programs that facilitate interprocess communication in Python?
Some considerations include implementing the poison-pill technique, so that sub-tasks are distributed across all consumer processes; calling task_done()
on the task queue each time the get()
function is called, to ensure that the join()
function will not block indefinitely; and avoiding using the qsize()
method, which is unreliable and is not implemented on Unix operating systems.
What are some real-life applications of concurrent reduction operators?
Some real-life applications include heavy number-crunching operators and complex programs that utilize logic operators.