An open API service indexing awesome lists of open source software.

https://github.com/ocramnaig94/parallel-all-pairs-shortest-path

A cost-optimal parallel algorithm based on Floyd-Warshall Algorithm in order to resolve the APSP problem
https://github.com/ocramnaig94/parallel-all-pairs-shortest-path

all-shortest-path apsp c floyd-warshall-algorithm mpi mpich parallel-programming

Last synced: 8 months ago
JSON representation

A cost-optimal parallel algorithm based on Floyd-Warshall Algorithm in order to resolve the APSP problem

Awesome Lists containing this project

README

          

# Parallel All-Pairs Shortest Path (APSP) algorithm
A cost-optimal parallel algorithm based on Floyd-Warshall Algorithm in order to resolve the APSP problem

The sequential version of the Floyd’s algorithm takes in input the adjacency matrix of size 𝑛 Γ— 𝑛, whose entries (𝑖, 𝑗) represent the positive weights that refer to the distance between vertex 𝑖 and vertex 𝑗, for 𝑖, 𝑗 = 1, ... , 𝑛. The same matrix in output will contain the updated weights representing the shortest paths for each pair of nodes. The development of the parallel version was done according to Foster’s PCAM methodology.

## Prerequisites

Install [MPICH](https://www.mpich.org/), a high performance implementation of the Message Passing Interface (MPI) standard.

Build the executables by using `Makefile`

```
make all
```

## How to Run
* Generate first the input square matrix through `gen_adj_matrix`, by providing the number or rows/columns and the name of the binary output file `.bin`. Optionally, a user-defined maximum weight can be set instead of the default one
```
./gen_adj_matrix optional:
```
* Alternatively, as the input square matrix a predefined one inside the homonymous folder `matrices` can be used.

* Run the APSP algorithm by providing the number of processors, which must be a [perfect square](https://en.wikipedia.org/wiki/Square_number), and the binary file containing the adjacency matrix
```
mpiexec -n ./allshortestpair
```

## Benchmark
The benchmark was performed on a virtual machine on a single CPU machine with 4 physical cores, and 8 logical ones due to hyper-threading.

| Matrix size | Time on 1 processor | Time on 4 processors | Speedup | Efficiency |
| ----- | :---: | :---: | :---: | :---: |
| 1000 Γ— 1000 | 1,7 seconds | 0,55 seconds | 3 | 0,75 |
| 3000 Γ— 3000 | 38 seconds | 12 seconds | 3,16 | 0,79 |
| 5000 Γ— 5000 | 174 seconds | 55 seconds | 3,16 | 0,79 |