Experiment 1a
Experiment 1a
5 5 5 5 20
Group A
Title of the Assignment: Design and implement Parallel Breadth First Search based on existing
algorithms using OpenMP. Use a Tree or an undirected graph for BFS
Objective of the Assignment: Students should be able to perform Parallel Breadth First Search
based on existing algorithms using OpenMP
Prerequisite:
1. Basic of programming language
2. Concept of BFS
3. Concept of Parallelism
---------------------------------------------------------------------------------------------------------------
Contents for Theory:
1. What is BFS?
2. Example of BFS
3. Concept of OpenMP
4. How Parallel BFS Work
5. Code Explanation with Output
---------------------------------------------------------------------------------------------------------------
SITRC,Nashik 1
Department of Computer Engineering Course : Laboratory Practice V
What is BFS?
BFS stands for Breadth-First Search. It is a graph traversal algorithm used to explore all the nodes of a
graph or tree systematically, starting from the root node or a specified starting point, and visiting all the
neighboring nodes at the current depth level before moving on to the next depth level.
The algorithm uses a queue data structure to keep track of the nodes that need to be visited, and marks
each visited node to avoid processing it again. The basic idea of the BFS algorithm is to visit all the
nodes at a given level before moving on to the next level, which ensures that all the nodes are visited in
breadth-first order.
BFS is commonly used in many applications, such as finding the shortest path between two nodes,
solving puzzles, and searching through a tree or graph.
Example of BFS
Now let’s take a look at the steps involved in traversing a graph by using Breadth-First Search:
Step 2: Select a starting node (visiting a node) and insert it into the Queue.
Step 3: Provided that the Queue is not empty, extract the node from the Queue and insert its child nodes
(exploring a node) into the Queue.
SITRC,Nashik 2
Department of Computer Engineering Course : Laboratory Practice V
Concept of OpenMP
● Parallel BFS (Breadth-First Search) is an algorithm used to explore all the nodes of a graph or tree
SITRC,Nashik 3
Department of Computer Engineering Course : Laboratory Practice V
systematically in parallel. It is a popular parallel algorithm used for graph traversal in distributed
computing, shared-memory systems, and parallel clusters.
● The parallel BFS algorithm starts by selecting a root node or a specified starting point, and then
assigning it to a thread or processor in the system. Each thread maintains a local queue of nodes to be
visited and marks each visited node to avoid processing it again.
● The algorithm then proceeds in levels, where each level represents a set of nodes that are at a certain
distance from the root node. Each thread processes the nodes in its local queue at the current level,
and then exchanges the nodes that are adjacent to the current level with other threads or processors.
This is done to ensure that the nodes at the next level are visited by the next iteration of the
algorithm.
● The parallel BFS algorithm uses two phases: the computation phase and the communication phase. In
the computation phase, each thread processes the nodes in its local queue, while in the
communication phase, the threads exchange the nodes that are adjacent to the current level with other
threads or processors.
● The parallel BFS algorithm terminates when all nodes have been visited or when a specified node has
been found. The result of the algorithm is the set of visited nodes or the shortest path from the root
node to the target node.
● Parallel BFS can be implemented using different parallel programming models, such as OpenMP,
MPI, CUDA, and others. The performance of the algorithm depends on the number of threads or
processors used, the size of the graph, and the communication overhead between the threads or
processors.
Assignment Question
1. What if BFS?
2. What is OpenMP?What is its significance in parallel programming?
3. Write down applications of Parallel BFS
4. How can BFS be parallelized using OpenMP? Describe the parallel BFS algorithm
using OpenMP.
5. Write Down Commands used in OpenMP?
Reference link
● https://www.edureka.co/blog/breadth-first-search-algorithm/
SITRC,Nashik 4