Optimizing BFS Algorithm on Undirected Graph represented in Adjacency Matrix using Core-Affine Threads
It is a powerful technique of systematically traversing the edges of a given graph, simultaneously, such every edge is traversed once and also each vertex is visited atleast once.
BFS employs the following rules:
- Visit the adjacent unvisited vertex. Mark it as visited. Insert it in a queue.
- If no adjacent vertex is found, remove the first vertex from the queue.
- Repeat Rule 1 and Rule 2 until queue is empty.
- One queue for the graph.
- Apply BFS algorithm.
- One global main queue for the graph.
- One local queue each processor.
- Apply BFS algorithm.
javac *.java java Main
- (e.g.) java Main 5000 4
- (e.g.) java Main 5000 8
- Parallel BFS with a graph of 5000 nodes and 4 processors: ~ 5.687 seconds
- Serial BFS with a graph of 5000 nodes and 4 processors: ~ 8.046 seconds
- Parallel BFS with a graph of 5000 nodes and 8 processors: ~ 4.672 seconds
- Serial BFS with a graph of 5000 nodes and 8 processors: ~ 8.327 seconds
- Finding the shortest path between two nodes u and v, with path length measured by number of edges (an advantage over depth-first search).
- Finding the solution of a lights-out game problem.
- Many more!