Introduction
Hello! Welcome to the next lesson in our module on the Principles of Parallel Algorithm Analysis.
In our previous lesson, we examined how to distribute data across multiple processors using block, cyclic, and block-cyclic strategies. We saw that this choice involves a critical trade-off between load balance and data locality. Now that we understand how data can be laid out, we need a formal way to think about and analyze the algorithms that operate on this distributed data.
Today's learning outcome is to analyze a simple parallel algorithm using the PRAM model (e.g., EREW, CREW). The Parallel Random-Access Machine (PRAM) is an idealized, theoretical model of a shared-memory computer. Much like a Turing machine provides a foundational model for sequential computation, the PRAM model allows us to reason about the fundamental limits and possibilities of parallel algorithms by abstracting away real-world hardware complexities like network latency and memory access contention.
We will learn what the PRAM model is, explore its different "flavors" based on how they handle simultaneous memory access, and apply this knowledge to analyze the performance of a simple parallel algorithm.
1. The PRAM (Parallel Random-Access Machine) Model
The PRAM model consists of a collection of processors that all connect to a single, shared memory space.

The model operates on a few key assumptions:
- There are multiple processors, each with its own local memory (registers).
- All processors can access any location in the shared memory in unit time. This is a powerful and important idealization.
- The processors operate in lock-step, meaning they execute instructions synchronously. In each step, every processor executes its instruction for that step.
This model is useful because it simplifies the world. By assuming uniform memory access time and perfect synchronization, it lets us focus purely on the structure of the computation and identify the maximum possible parallelism, without getting bogged down by the details of a specific machine's architecture.
To get a more formal definition of the PRAM model, please review the following slides.
[PDF] Parallel Random-Access Machines
These slides, from a course at the University of Western Ontario, provide a concise and formal definition of the PRAM model, its architecture, and its execution cycle.
Please read from the beginning up to the section titled 'Handling Shared Memory Access Conflicts'. Focus on the definitions of the architecture (processors, memory) and the 3-phase execution cycle (Read, Compute, Write).
2. Memory Access Conflicts and PRAM Sub-models
The assumption that any processor can access any memory cell in unit time raises a crucial question: what happens if multiple processors try to access the same memory cell in the same synchronous step?
The rules for handling these read and write conflicts define different sub-models of the PRAM. These models form a hierarchy based on how restrictive they are.
- EREW (Exclusive Read, Exclusive Write): The most restrictive model. In any given step, each memory location can be read by at most one processor and written to by at most one processor.
- CREW (Concurrent Read, Exclusive Write): This model relaxes the reading constraint. Multiple processors can read from the same memory location simultaneously, but writes must still be exclusive. This is a very common and practical model.
- CRCW (Concurrent Read, Concurrent Write): The most powerful and least restrictive model. It allows simultaneous reads and writes to the same memory location. Since a concurrent write is ambiguous, several variants exist to define the outcome:
- COMMON: The write succeeds only if all processors are trying to write the exact same value.
- ARBITRARY: An arbitrary processor among those attempting to write succeeds. The algorithm must work correctly no matter which one is chosen.
- PRIORITY: The processor with the highest priority (e.g., the lowest index) succeeds.
The following video and text provide a clear overview of these distinctions.
A&DS S04E14. Parallel Algorithms
This video provides a great verbal explanation of the PRAM model and its different memory access conventions.
Watch from 03:35 to 08:46. The speaker explains the PRAM architecture and then details the differences between EREW, CREW, and CRCW models.
For a textual reference, the document we looked at earlier also defines these sub-models precisely.
[PDF] Parallel Random-Access Machines
These slides formally define the EREW, CREW, and various CRCW models.
Please read the two slides titled 'Handling Shared Memory Access Conflicts'. This will solidify your understanding of the EREW, CREW, and the PRIORITY, ARBITRARY, and COMMON CRCW sub-models.
An algorithm designed for EREW will run on a CREW machine, and a CREW algorithm will run on a CRCW machine. The reverse is not always true. Therefore, the hierarchy of computational power is: CRCW ≥ CREW ≥ EREW.
3. Analyzing a PRAM Algorithm: Parallel Reduction
Now let's use the PRAM model to analyze a simple but fundamental parallel algorithm: reduction. A reduction operation takes a collection of values and "reduces" them to a single value using an associative operator like sum, product, max, or min.
Problem: Given an array of n numbers, find their sum.
-
Sequential Algorithm: A simple loop that iterates through the array. Time complexity:
O(n). -
Parallel Algorithm: We can perform the additions in parallel using a tree-like structure. Let's assume we have
nnumbers andn/2processors.

Let's trace the steps for n=8 numbers in an array A:
- Step 1: Use 4 processors.
- P0 computes
A[0] = A[0] + A[1] - P1 computes
A[2] = A[2] + A[3] - P2 computes
A[4] = A[4] + A[5] - P3 computes
A[6] = A[6] + A[7]
- P0 computes
- Step 2: Use 2 processors.
- P0 computes
A[0] = A[0] + A[2] - P1 computes
A[4] = A[4] + A[6]
- P0 computes
- Step 3: Use 1 processor.
- P0 computes
A[0] = A[0] + A[4]
- P0 computes
The final sum is in A[0].
Performance Analysis
- Parallel Time (T_p): The algorithm takes 3 steps for
n=8. In general, it takeslog₂(n)steps. So, the parallel time complexity isO(log n). This is a significant improvement over the sequentialO(n). - Total Work (W): This is the total number of operations performed by all processors.
- Step 1: 4 additions
- Step 2: 2 additions
- Step 3: 1 addition
- Total work = 4 + 2 + 1 = 7, which is
n-1. The work complexity isO(n).
- Work-Efficiency: A parallel algorithm is called "work-efficient" if its work complexity is asymptotically the same as the time complexity of the best known sequential algorithm. In this case, our parallel algorithm does
O(n)work, and the sequential algorithm takesO(n)time. So, this algorithm is work-efficient.
PRAM Model Suitability
Which PRAM model does this algorithm require? In our description, Processor 0 reads A[0] and A[2] in Step 2. These values were written by Processor 0 and Processor 1 in Step 1. No two processors read or write the same location in the same step. This algorithm can be implemented on an EREW PRAM with careful indexing.
Let's analyze a slightly more formal algorithm for finding the maximum value, designed specifically for the EREW model.
[PDF] Parallel Random-Access Machines
The following slides provide a pseudo-code for an EREW PRAM algorithm that computes the maximum of 2n numbers using n processors. This is another example of a reduction.
Please read the slides titled 'Example 6: statement' and 'Example 6: solution'. Try to trace the algorithm for n=4 (8 input numbers) and p=4 processors. Pay attention to how the jump variable changes and how the if (id mod jump = 0) condition ensures that writes are exclusive.
In this example, at each step k, the jump distance is 2^k. A processor id (where id is a multiple of jump) reads its own value M[2*id] and a value from a neighbor M[2*id - jump]. Because of how id and jump are structured, no two processors will read or write to the same memory location simultaneously. This demonstrates the constraints of designing for the EREW model. The time complexity is again O(log n) because the loop runs log n times.
4. The Work-Depth Model
A more general and powerful way to analyze PRAM algorithms is the Work-Depth model (also called the Work-Time or Work-Span model).
- Work (W or T₁): The total number of operations, as we just calculated. It's equivalent to the time it would take to run on a single processor.
- Depth (D or T∞): The length of the longest chain of dependent operations (the "critical path"). This is equivalent to the time it would take to run on an infinite number of processors. For our reduction example, the depth is
O(log n).
These two parameters are often all you need to characterize a parallel algorithm's performance. The time T_p on p processors can be estimated by the simple and powerful relationship:
This formula captures two fundamental bounds:
- The
W/pterm represents the "parallelism bound": you haveWtotal work to do, andpprocessors can at best do it inW/ptime. - The
Dterm represents the "dependency bound": no matter how many processors you have, you can't go faster than the longest dependency chain.
For our reduction algorithm, W = O(n) and D = O(log n). Therefore, the time on p processors is T_p = O(n/p + log n). This single formula tells us how the algorithm scales with both problem size n and processor count p. This framework is very useful for your background in algorithms and mathematics.
A&DS S04E14. Parallel Algorithms
The same video from earlier has an excellent section that introduces the Work-Depth model and derives this complexity formula.
Watch from 09:29 to 21:20. The speaker explains the concepts of work and depth using a dependency graph and shows how they combine to predict the runtime on p processors.
Conclusion
In this lesson, we introduced the PRAM, a theoretical model for parallel computation that allows us to analyze algorithms by abstracting away hardware specifics.
Key Takeaways:
- The PRAM model consists of multiple synchronous processors connected to a single shared memory with uniform access time.
- PRAM sub-models—EREW, CREW, and CRCW—are defined by their rules for handling concurrent memory access, forming a hierarchy of computational power.
- We can analyze parallel algorithms using two key metrics:
- Parallel Time (T_p): The number of steps on
pprocessors. - Work (W): The total number of operations performed.
- Parallel Time (T_p): The number of steps on
- A work-efficient algorithm has a work complexity asymptotically equal to the time of the best sequential algorithm.
- The Work-Depth model (
WandD) provides a powerful formula,T_p = O(W/p + D), to estimate an algorithm's runtime on any number of processors.
Preview of the Next Lesson
We've now seen how to analyze a simple reduction algorithm. In the next lesson, we will build on this foundation to tackle a more complex and widely used parallel primitive: the prefix sum, also known as scan. We will use the PRAM model to design and analyze a parallel prefix sum algorithm. This will challenge us to think more deeply about data movement and dependencies in parallel execution.