PA midsem
PA midsem
Unit 1
What is Parallel Computing
It is the simultaneous use of multiple computing resources to solve a
computational problem.
A combination of both.
Parallel Algorithm 1
The computational problem usually demonstrates characteristics such as
the ability to be:
Solved in less time with multiple compute resources than with a single
compute resource.
Saves time and money: many resources working together will reduce the
time and cut potential costs.
Many problems that are interesting to scientists and engineers don't fit on
a PC - they have huge memory requirements
Parallel Algorithm 2
Definition: Speedup is the ratio of the execution time of the sequential
algorithm to the execution time of the parallel algorithm using ppp processors.
Formula
Parallel Algorithm 3
Models of Computation
Parallel programming models exist as an abstraction above hardware and memory
architectures.
3. Threads model
Parallel Algorithm 4
Various mechanisms such as locks / semaphores are used to control access
to the shared memory, resolve contentions and to prevent race conditions and
deadlocks.
Example
The processor may not have a private program or data memory. A common
program and data are stored in the main memory. This is accessed by all
processors.
Each processor is assigned a different part of the program and the data. The
main program creates separate process for each processor.
The process is allocated to the processor along with the required data. These
process are executed independently on different processors.
After the execution, all the processors have to rejoin the main program,
Parallel Algorithm 5
Implementations
Native compilers translates user program variables into addresses, which are
memory "global"
Advantages
Program development becomes simple. As all processes see and have equal
access to shared memory.
Disadvantages
It becomes more difficult to understand and manage data locality: Users will
not understand where his variables use stored.
The message passing model (or Distributed Memory model) is defined as:
Parallel Algorithm 6
Programming with message passing is done by linking with and making calls
to libraries which manage the data exchange between processors.
Implementation:
Disadvantage
Programmers should take care that there is a receive function for every send
function.
If any of the process, quite, others also will stop working, as they are
dependent.
3. Threads Model
Parallel Algorithm 7
Each thread has local data, but they also share common data
Example: A subroutine within the main program (a.out). Any thread can
execute any subroutine at the same time as other threads.
If the threads are executed on same processor, then the processor switches
between the threads in a random fashion.
Implementations:
Parallel Algorithm 8
POSIX Threads
OpenMP
Advantages
Disadvantages
Care must be taken that no two threads update the shared resources
simultaneously.
Focuses on parallel operations on a set (array) of data items i.e Data Set.
The data set is typically organized into a common structure, such as an array
or cube
A set of tasks work collectively on the same data structure, however, each
task works on a different partition of the same data structure.
Tasks perform the same operation on their partition of work, for example, "add
6 to every array element".
Example
Parallel Algorithm 9
Discuss the challenges and techniques involved in achieving synchronization
and communication among parallel processes in distributed-memory parallel
algorithms. Compare and contrast message passing and shared-memory
paradigms for handling synchronization and communication in parallel
computing environments.
Parallel Algorithm 10
Collective Communication: Operations such as broadcast, scatter, and gather
that allow multiple processes to communicate efficiently.
UNIT 3
Query Processing in DBMS
A query processor is one of the major components of a relational database or
an electronic
database in which data is stored in tables of rows and columns.
It complements the storage engine, which writes and reads data to and from
storage media
Parallel Algorithm 11
Parsing and Translation
Initially, the given user queries get translated in high-level database languages
such as SQL.
It gets translated into expressions that can be further used at the physical level
of the file system.
After this, the actual evaluation of the queries and a variety of query -
optimizing transformations and takes place.
The annotations in the evaluation plan may refer to the algorithms to be used
for the particular index or the specific operations.
Parallel Algorithm 12
A query execution engine is responsible for generating the output of the given
query.
It takes the query execution plan, executes it, and finally makes the output for
the user query.
Optimization
The cost of the query evaluation can vary for different types of queries.
Although the system is responsible for constructing the evaluation plan, the
user does need not to write their query efficiently.
For optimizing a query, the query optimizer should have an estimated cost
analysis of each operation. It is because the overall operation cost depends on
the memory allocations to several operations, execution costs, and so on
It is also used in fastening the process of a query execution as more and more
resources like processors and disks are provided.
1. I/O parallelism :
Within, the data inputted is partitioned and then processing is done in parallel
with each partition.
Parallel Algorithm 13
It is also known as data-partitioning
a. Hash partitioning –
b. Range partitioning –
c. Round-robin partitioning –
The ith tuple is sent to the disk number(i % n). So, disks take turns receiving
new rows of data.
This technique ensures the even distribution of tuples across disks and is
ideally suitable for applications that wish to read the entire relation
sequentially for each query.
d. Schema partitioning –
Parallel Algorithm 14
2. Intra-query parallelism :
a. First approach – In this approach, each CPU can execute the duplicate task
against some data portion.
b. Second approach –In this approach, the task can be divided into different
sectors with each CPU executing a distinct subtask.
3. Inter-query parallelism :
We can also use some different methods, like efficient lock management.
4. Intra-operation parallelism :
Parallel Algorithm 15
5. Inter-operation parallelism :
When different operations in a query expression are executed in parallel, then it is
called inter-operation parallelism. They are of two types –
System is broken down into multiple parts (or logical processes), each of
which is responsible for handling events in parallel.
Events can occur at different times and affect various parts of the system.
1. Discrete Events: These are events that happen at a specific point in time, such
as the arrival of a message, a machine breaking down, or a train reaching a
station.
2. Event List: This is a queue that contains all the scheduled events, sorted by
time.
3. Logical Processes (LPs): These are the independent entities responsible for
processing events. Each LP may simulate different parts of the system, such
as different subsystems or components.
Parallel Algorithm 16
4. Synchronization: One of the critical challenges of PDES is synchronizing
events across the different logical processes to ensure a consistent
simulation.
5. Time Management: In PDES, time must be managed in a way that ensures that
events occur in the correct order. This can be challenging when different LPs
may process events at different times, which could cause inconsistencies.
1. Event Scheduling: Each LP schedules events that it will process in the future.
These events are stored in the event list (or priority queue).
2. Event Processing: LPs process the events according to their timestamps, and
then generate new events as required.
Steps to Simulate:
Parallel Algorithm 17
1. Initialization: We create the event list, which contains the start time of each
machine's first event.
2. Event Scheduling: Each machine schedules an event for when it will finish
processing a product.
Image Dithering
What is Dithering?
Ordered Dithering
Floyd-Steinberg Dithering
Atkinson Dithering
Parallel Algorithm 18
Imagine you have an image with many colors, but the display device can only
show a limited number of colors.
Example - If you have a pixel that should be light gray, but your device can
only show either black or white, dithering might place black and white pixels
near each other to simulate gray.
1. Ordered Dithering:
Ordered dithering uses a fixed matrix to decide where to place the dithered colors.
It is a simple and fast method but may not produce the best results in terms of
visual quality.
Steps to Apply Ordered Dithering:
2. Normalize the pixel values: We scale the pixel values to a range of 0 to 15,
assuming we are using a 4-level grayscale. For a more complex image, we
could scale the pixel values accordingly to fit the threshold matrix size.
3. Apply the Bayer matrix: The Bayer matrix is tiled over the image. Each pixel in
the image is compared with the corresponding value in the matrix. If the pixel
value is greater than the matrix value at that position, the pixel is set to light
(white); if it's smaller, it is set to dark (black).
4. Tile the matrix - The Bayer matrix is tiled across the image, so you start again
with the first value of the matrix once you reach the end.
Example: You might use a matrix like the Bayer matrix, which breaks the image
into smaller blocks and applies dithering based on the intensity of each pixel.
2. Floyd-Steinberg Dithering:
Parallel Algorithm 19
This is one of the most widely used dithering techniques. It is a error diffusion
method, where the error (difference between the actual color and the closest
available color) is distributed to neighboring pixels. This gives a more natural
appearance and works well for photographs or images with continuous tones.
Steps:
Start with the top-left pixel and calculate the color difference (error) between
the pixel’s color and the closest available color.
Distribute this error to the neighboring pixels (to the right, bottom-right, and
bottom pixels).
3. Atkinson Dithering:
Printed Graphics: When printing images with limited ink colors, dithering can
help simulate continuous tones and shades.
Parallel Algorithm 20