Question
Implement Floyd-Warshall (FW) All-Pairs-Shortest-Path algorithm in a multi-threaded fashion along with enforcing the readers-writers problem in C program. Multi threaded Implementation: In the multi threaded
Implement Floyd-Warshall (FW) All-Pairs-Shortest-Path algorithm in a multi-threaded fashion along with enforcing the readers-writers problem in C program.
Multi threaded Implementation: In the multi threaded implementation of FW, the k loop remains same. Instead of the i loop, we create n threads that represent each iteration of the i loop. Each thread runs the j loop from 1 to n. There is a global matrix Graph that stores the adjacency matrix for the graph. All the threads can read it simultaneously. There is another global matrix dist that is used for updating the minimum distances between the vertices. Only 1 copy of dist will suffice. At the start of every iteration inside the k loop, you need to create n threads. Each thread will run its own j loop. You have to enforce readers-writers problem in the manner of how the dist matrix is accessed by the different threads. Any number of threads can read from the dist matrix provided that no other thread is writing to it. Only 1 thread can write to the dist matrix at a time. If you observe closely, line 4 has only read statements and line 5 is the only write statement present in the algorithm. Hence, these two lines need appropriate synchronization. At the end of every iteration of the k loop, you need to wait for all the threads to finish. Then only can you start another iteration of the k loop. You have to join the threads at the end of every iteration of the k loop. Analysis: Implement the single threaded and multi-threaded versions of Floyd-Warshall algorithm. Run the algorithm for graphs of different sizes, e.g., 10, 100, 1000, 10000 and observe the speed up improvement. Do you find any limit on the number of threads that can be created on your system? Compute the speed up (time taken by single threaded version/time taken by multi threaded version) obtained through multi threading and include the graph plot in your final report with relevant inferences. Note that the to get the real speed up, you have to perform this experiment on a multi core system. Most of the modern computers are multi-core today and can actually run several threads concurrently. Report the system architecture on which you performed the experiment, e.g., processor type and clock rate, # cores, RAM etc... Input Format: Graph structure: The first line contains 2 integers N and M. N is the number of nodes. M is the number of undirected edges. Then each entry contains the link information (M entries). Line i+1 contains 3 integers ui, vi and wi which represents an undirected edge between nodes ui, vi and wi is the weight of that edge. Use positive edge weights. Your program should inform the user if he/she unknowingly provide a negative edge weight. Output Format: Print the final dist matrix. In case node j is not reachable from node i, then print INF as the distance between i and j.
Sample input and output: Input 4 4 1 2 1 2 3 1 3 4 1 4 1 1 Output: 0 1 2 1 1 0 1 2 2 1 0 1 1 2 1 0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started