0% found this document useful (0 votes)
17 views

pp assignment

The document outlines a parallel algorithm for calculating the sum of integers in an array by dividing the work among multiple processors, allowing for concurrent computation and a reduction process to combine results. It discusses the steps involved in the algorithm, including input division, independent sum computation, and result combination using a reduction tree, along with an analysis of time complexity and scalability. Additionally, it covers the advantages and disadvantages of parallel processing, comparing it to sequential processing and providing guidelines on when to use parallel processing effectively.

Uploaded by

Thar Nge
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

pp assignment

The document outlines a parallel algorithm for calculating the sum of integers in an array by dividing the work among multiple processors, allowing for concurrent computation and a reduction process to combine results. It discusses the steps involved in the algorithm, including input division, independent sum computation, and result combination using a reduction tree, along with an analysis of time complexity and scalability. Additionally, it covers the advantages and disadvantages of parallel processing, comparing it to sequential processing and providing guidelines on when to use parallel processing effectively.

Uploaded by

Thar Nge
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Parallel Algorithm to Find the Sum of Integers in an Array

Concept

The goal is to divide the work among multiple processors so that they concurrently compute
partial sums of the array, and then combine these partial sums to produce the final result. The
process involves divide-and-conquer and reduction.

Steps of the Algorithm

1. Input: An array of integers AA with NN elements.


2. Divide the Work:
o Divide the array into PP equal-sized chunks (one for each
processor).

subarray AiA_i of size approximately ⌈NP⌉\lceil \frac{N}{P} \rceil.


o If PP is the number of processors, each processor ii gets a

3. Concurrent Computation:
o Each processor computes the sum of its assigned subarray
independently.
o This step produces PP partial sums S1,S2,…,SPS_1, S_2, \ldots,
S_P.
4. Combine Results:
o Use a reduction tree to sum up the PP partial sums. This can also
be done in parallel in a logarithmic fashion:
 At level 1, combine pairs of partial sums (S1+S2,S3+S4,…
S_1 + S_2, S_3 + S_4, \ldots).
 At level 2, combine the results of level 1, and so on.
 Continue until a single sum is computed.

Example
Input:

Array: A=[4,8,15,16,23,42]A = [4, 8, 15, 16, 23, 42]


Number of processors: P=3P = 3

Step-by-Step Process:

1. Divide the Array:


o Processor 1: A1=[4,8]A_1 = [4, 8]
o Processor 2: A2=[15,16]A_2 = [15, 16]
o Processor 3: A3=[23,42]A_3 = [23, 42]
2. Concurrent Computation:
o Processor 1 computes S1=4+8=12S_1 = 4 + 8 = 12
o Processor 2 computes S2=15+16=31S_2 = 15 + 16 = 31
o Processor 3 computes S3=23+42=65S_3 = 23 + 42 = 65

3. Combine Results:
o Level 1: Combine S1S_1 and S2S_2: 12+31=4312 + 31 = 43
o Level 2: Combine 4343 and S3S_3: 43+65=10843 + 65 = 108

Final Output:

Sum of the array: 108108

Analysis

1. Time Complexity:
o Division: O(1)O(1), as splitting is a constant operation.
o Parallel Sum Computation: O(NP)O(\frac{N}{P}) since each
processor handles NP\frac{N}{P} elements.
o Reduction Tree: O(log⁡P)O(\log P) as combining results follows a
tree structure.
o Total Time: O(NP+log⁡P)O(\frac{N}{P} + \log P).

2. Scalability:
o As PP increases, computation time per processor decreases.
o Communication overhead in reduction increases, but for large
NN, the algorithm remains efficient.

3. Efficiency:
o Works best when NN is much larger than PP to minimize idle
processors.

Visualization of Reduction Tree

For P=4P = 4 processors:

Level 0: [S1] [S2] [S3] [S4]


Level 1: [S1+S2] [S3+S4]
Level 2: [S1+S2+S3+S4]

This parallel algorithm minimizes computation time by utilizing all processors efficiently and
leveraging parallelism for both computation and reduction.
Parallel Processing

Parallel processing refers to the simultaneous execution of multiple tasks or processes by


dividing a larger computational problem into smaller sub-problems, which can be solved
concurrently. This is typically achieved using multiple processors, cores, or even distributed
systems working together to complete a task more efficiently than sequential processing.

Advantages of Parallel Processing

1. Increased Speed and Performance:


o Tasks are executed simultaneously, leading to faster computation
and reduced time to complete large and complex problems.
o Example: Processing large datasets in a database can be
divided among multiple processors to generate results faster.

2. Efficient Utilization of Resources:


o Maximizes the use of available hardware by distributing tasks
among multiple cores or processors.
o Example: A quad-core processor running four independent tasks
at the same time ensures none of the cores remain idle.

3. Scalability:
o Parallel processing systems can be scaled by adding more
processors or cores, making them suitable for increasingly
complex or large-scale tasks.
o Example: Distributed systems like Hadoop allow for the addition
of nodes to process massive datasets.

4. Improved Reliability and Fault Tolerance:


o If one processor fails, other processors can continue working,
ensuring partial progress or recovery mechanisms.
o Example: In a distributed database system, data replication
ensures queries can still be answered even if one server goes
down.

5. Enables Real-Time Applications:


o Parallel processing is crucial for real-time applications that
require rapid response, such as weather prediction, gaming, and
autonomous vehicles.
o Example: Autonomous cars process sensor data, navigation, and
obstacle detection simultaneously.

Disadvantages of Parallel Processing

1. Complexity in Programming:
o Writing parallel programs is more challenging due to the need for
synchronization, data sharing, and task distribution.
o Example: A bug in synchronization can lead to race conditions,
where tasks produce incorrect or inconsistent results.

2. High Cost of Hardware:


o Systems with multiple processors or specialized hardware like
GPUs are expensive.
o Example: Supercomputers used for scientific research require
significant investment.

3. Overhead in Communication:
o Processors need to communicate to share intermediate results,
which introduces latency and reduces efficiency.
o Example: In distributed systems, frequent network
communication can slow down the overall computation.

4. Uneven Workload Distribution:


o If tasks are not evenly distributed, some processors may remain
idle, reducing efficiency.
o Example: In a sorting algorithm, if one processor handles
significantly more data than others, it becomes a bottleneck.

5. Dependency Issues:
o Parallelization is difficult for problems where tasks are dependent
on each other or require sequential execution.
o Example: Fibonacci sequence computation cannot be easily
parallelized because each number depends on the previous two.
Example: Parallel Matrix Multiplication
Sequential Approach:

 Multiply two N×NN \times N matrices using a single processor.


 Time Complexity: O(N3)O(N^3).

Parallel Approach:

 Divide the matrices into smaller submatrices and assign each to a


processor.
 Each processor computes the product of its assigned submatrices
independently.
 Combine results to produce the final matrix.
 Time Complexity: O(N3P)+overhead for communication O(\frac{N^3}
{P}) + \text{overhead for communication}, where PP is the number of
processors.

Comparison of Sequential vs Parallel Processing


Aspect Sequential Processing Parallel Processing

Slower for large Faster due to simultaneous


Speed
problems execution

Resource Uses a single core or


Utilizes multiple cores or processors
Usage processor

Complexity Simpler to implement More complex due to task division

Cost Less expensive Can be expensive for large systems

Large-scale, computationally
Best For Small-scale tasks
intensive tasks

When to Use Parallel Processing

 When tasks are independent and can be divided.


 For large-scale computations, e.g., weather simulations, data mining,
or video rendering.
 In real-time applications requiring quick response times, e.g., robotics
or gaming.

Conclusion

Parallel processing is a powerful tool that enhances computation efficiency and speed but comes
with trade-offs in complexity and cost. It is best utilized in scenarios where large-scale
computations or time-critical tasks are involved.

You might also like