I’m trying to parallelise the Floyd-Warshall algorithm using OpenMP (basically editing a 2D array in-place), but I doubt that I’m going about it in the best way, here is what I’ve got so far:
#pragma omp parallel for private(i, j, k) shared(g)
for ( i = 0; i < n; i++ ) {
for ( j = 0; j < n; j++ ) {
for ( k = 0; k < n; k++ ) {
g->A[j][k] = imin( g->A[j][k], g->A[j][i] + g->A[i][k] );
}
}
}
Any Ideas how I can utilise OpenMP better? At the moment that just halves runtime, surely that can be improved.
Also if anyone as any suggestions for other technologies to be used for the parallelisation, I’m all ears. I thought about MPI, but I’d have to make my whole main function parallel right?
Thanks.
EDIT
The code above does not work, the answers below show why.
Parallelizing the algorithm is not straightforward. See the notes here
http://www.mcs.anl.gov/~itf/dbpp/text/node35.html
for information on running it in parallel. If you have a small number of processors (dual-, quad-, oct- core machine) then Parallel Floyd 1 is probably right for you. If you have a huge number of processors (really awesome GPU, mesh computer) then Parallel Floyd 2 might be better.