What is multiprocessing?
Multiprocessing is the utilization of two or more central processing units (CPUs) in a single computer system. Its definition can vary depending on the context, but generally it refers to a system's ability to support multiple CPUs and its capacity to distribute work among them.
Multicore processors of today are easily capable of having 12, 24 or even more microprocessor cores on the same motherboard, enabling the effective and concurrent processing of numerous tasks.
What are processes?
A collection of instructions being carried out by the computer processor is referred to as a process or a running process.
A process's execution must proceed in a sequential manner. For example, a computer program is written in a text file, but once executed, it turns into a process and performs all the tasks mentioned in the program sequentially.
A normal computer runs a number of processes continuously to help manage the operating system (OS), the hardware and the applications installed on the machine. This can range from a simple background task like a spell-checker or system event handler to a full-fledged application like Microsoft Word.
In Microsoft Windows, each process running on a computer can be observed by opening the Processes tab in the Task Manager. The processes are typically the background programs that one normally doesn't see while using the computer.
The following are a few examples of processes that can be observed through the Task Manager:
- Winlogon.exe. This process belongs to the Windows login manager and is responsible for security handling, such as loading user profiles and locking computer screens while a screensaver is running.
- Wininit.exe. This important process runs continuously and helps in setting up the system at the initial login. Its primary role is serving as a launchpad for the majority of background programs and processes that start with Windows.
- Csrss.exe. In the past, csrss.exe process was used to manage Windows graphical components, but these days, its two most important functions are shutting down Windows and starting the conhost.exe process, which starts the Command Prompt.
- Printer programs. Any printer program is a process that runs in the background monitoring the ink levels and other settings while a computer is running.
Types of multiprocessing systems
Multiprocessor or parallel processing systems are commonplace now. These systems make use of shared memory and distribute the computer clock, memory, bus and peripherals among several concurrent processors. Multiprocessing is divided into the following three types:
- Symmetric multiprocessing (SMP). In symmetric (or "tightly coupled") multiprocessing, the processors share memory and the I/O bus or data path. A single copy of the OS manages all the processors. SMP, also known as a "shared everything" system, does not usually exceed 16 processors.
- Asymmetric multiprocessing (AMP). Prior to the development of symmetric multiprocessors, only asymmetric multiprocessors were available. Each processor in an asymmetric system is given a predetermined task. A primary-secondary relationship exists in an asymmetric multiprocessor system, where all the processors receive instructions from a primary processor. AMP is a cheaper option than SMP.
- Massively parallel processing (MPP). In MPP (or "loosely coupled") processing, up to 200 or more processors can work on the same application. Each processor has its own operating system and memory, but an "interconnect" arrangement of data paths allows messages to be sent between processors. Typically, the setup for MPP is more complicated, requiring thought about how to partition a common database among processors and how to assign work among the processors. An MPP system is also known as a "shared nothing" system.
Process vs. thread
There's a common misconception that processes and threads are the same when, in fact, they are separate execution sequences.
The following are the common differences between a process and a thread:
- A process is a section of a running program, whereas a thread is a portion of a process.
- Threads are lightweight compared to processes.
- When a process ends, it does so more slowly than when a thread does.
- The creation of a process requires more time than the creation of a thread.
- Processes require more time for context switching, whereas threads need less time.
- Unlike threads, which share memory, a process is largely segregated.
- Data is not shared across processes, but it's shared between threads.
Besides the process versus thread misconception, multiprocessing is sometimes confused with multiprogramming, or the interleaved execution of two or more programs by a processor. Today, the term is rarely used because all but the most specialized computer operating systems support multiprogramming.
Multiprocessing can also be confused with multitasking or time sharing, the management of programs and the system services they request as tasks that can be interleaved, and with multithreading, the management of multiple execution paths through the computer or of multiple users sharing the same copy of a program.
While multiprocessing improves system performance and reliability, it does come with a few challenges as well:
- Expensive. Systems with multiple processors might be pricey. Having just one processor is less expensive than having two or more. It's advisable to only invest in several processers if they will pay off in the long run because, in addition to the upfront expense, maintaining them is expensive.
- Deadlocks. In systems with multiple processors, a deadlock can occur if one processor attempts to access an input/output (I/O) device while another processor is trying to use it.
- Extra memory requirements. Due to their improved computing capability, multiprocessor computers are widely used. However, they do come with increased memory requirements. In multiprocessing architectures, memory is shared across all processes and each processor requires memory space. All processors work together and simultaneously access the main memory directly, which causes an increase in memory consumption.
- Complex operating system. In multiprocessing operating systems, each CPU has its own operating system, which assigns each processor with several minor tasks and the load is distributed among the processors. However, the use of multiple processors makes it more complex for the operating system to function.
Multiprocessing environments are widely adopted and offer a wide range of advantages such as increased speed, throughput and reliability. Common benefits of multiprocessing include the following:
- Reliability. If one processor fails in a multiprocessor system, the other processors can pick up the slack and continue to function. While the shutting down of one processor might cause a gradual slowdown, the system can still function smoothly. This makes multiprocessing systems highly reliable.
- Increased throughput. Throughput is the number of processes executed at a given time. Given that multiprocessor systems use many CPUs to handle data, increased performance is expected when the system takes use of parallel processing. This means more tasks can be accomplished in a shorter amount of time as they are divided between different processors.
- Cost saving. Multiprocessing systems are more economical compared to multiple single processor systems. This is due to the fact that multiple processors within a single system share the same memory, disk space, buses and peripherals.
Symmetric multiprocessing, asymmetric multiprocessing and massively parallel processing are some of the several types of multiprocessing. Learn how these modes differ from one another and become familiar with each one's unique use cases.