Decomposition

So far, we have discussed the basic usage of multiprocessing / multithreading and basic methodologies (IPC).

However, without knowing when to use and how to use, the methodiology is useless.

In this section, we discuss popular programming patterns in concurrent applications. In other words, we discuss how we can decompose an application to effectively apply the concurrent programming paradigm from two perspectives: by process and by data.

Table of contents

Dependency Analysis

Decomposing a problem into concurrent tasks is the first and foremost step.

Without knowing the dependencies between tasks, concurrent programming might result in serious resource problems or unexpected outputs. Therefore, it is highly recommended to first draw a concurrent programming flowchart or sequence diagram and then apply the diagram to your code. Such a diagram is called a dependency graph.

Types of decompositions

There are two base decomposition strategies - task decomposition and data decomposition.

  1. Task Decomposition
  2. Data Decomposition

Modern programs in real world, of course, usually use both strategies : deeplearning models, video games, web services, data engineering and LLM services.

If we think of manufacturing, task decomposition means using different type of workers, and data decomposition means co-working between the same typed workers. Let us suppose that we runs a Fashion company that makes a hand-made bag. Instead of hiring some workers that can have ability of planning, manufacturing and managing, we might hire a designer, manufacturers, and a manager.

By separating the tasks as designing, manufacturing, and managing, we also effectively uses the resources and time, in the example, we might hire more manufacturers because manufacturing is time consuming compared to designing or managing.

This concept might also be applied on your program, your program might have some steps, and some of the steps would take a long time than others. If we decompose the steps, and put more resources on the time-consuming steps, we could reduce the execution time and use resources efficiently.