diff --git a/output_mp/test_5 b/output_mp/test_5 deleted file mode 100644 index 2734eef50f4aaad6b790f549ad5e2b729c8cdcdc..0000000000000000000000000000000000000000 --- a/output_mp/test_5 +++ /dev/null @@ -1,4 +0,0 @@ -5 -0-1 -1-3 -2-4 diff --git a/src/MST_OpenMPI b/src/MST_OpenMPI index b8d21e740d2d76f6fb897fba1617500d62afcc5c..9b36ae4f53fc8cb0ec5d40c676a0c760c6c3a556 100755 Binary files a/src/MST_OpenMPI and b/src/MST_OpenMPI differ diff --git a/src/MST_OpenMPI.c b/src/MST_OpenMPI.c index 389281e780cd850f40e0fffda4ee8b1b2fc1f286..747b792243f30e8f37893a9a59ab949c61289664 100644 --- a/src/MST_OpenMPI.c +++ b/src/MST_OpenMPI.c @@ -131,11 +131,12 @@ void QuickSort(Edge T[], int i, int j, int rank, int max_rank, int rank_index){ makeStruct(&mpi_edge_type); int distributed_process = rank + pow2(rank_index); - rank_index++; + // rank_index++; // If the rank of distributed process is higher than max rank if (distributed_process >= max_rank) { SequentialQuickSort(T, i, j); + // MPI_Send(&T, j - i+1, mpi_edge_type, distributed_process, 1, MPI_COMM_WORLD); } else { int pivot; @@ -252,7 +253,12 @@ int compare_src(const void *a, const void *b) Edge *b1 = (Edge *)b; return a1->src > b1->src; } - +int compare_dest(const void *a, const void *b) +{ + Edge *a1 = (Edge *)a; + Edge *b1 = (Edge *)b; + return a1->dest > b1->dest; +} // Minimum Spanning Tree using Kruskal's Algorithm void KruskalMST(Graph *graph, Edge result[], int *e, int size, int rank) @@ -283,6 +289,8 @@ void KruskalMST(Graph *graph, Edge result[], int *e, int size, int rank) // QuickSortSrc(graph->edge, 0, graph->E, size, rank); // QuickSortSrc(result, 1, (*e)); qsort(result, *e, sizeof(result[0]), compare_src); + qsort(result, *e, sizeof(result[0]), compare_dest); + qsort(result, *e, sizeof(result[0]), compare_src); return; } @@ -347,16 +355,17 @@ int main() // Declare the array buffer to receive data from the source process Edge* temp = (Edge *) malloc (sizeof(Edge) *arrLength); + source = MPI_Recv(temp, arrLength, mpi_edge_type, src, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - printf("Process %d\n", rank); + // printf("Process %d\n", rank); // Sort the received buffer with QuickSort QuickSort(temp, 1, arrLength, rank, size, idxcnt); - printf("Process %d\n", rank); + // printf("Process %d\n", rank); // Send the sorted array back to the source process source = MPI_Send(temp, arrLength, mpi_edge_type, src, 1, MPI_COMM_WORLD); // source = MPI_Send(temp, arrLength, mpi_edge_type, src, 1, MPI_COMM_WORLD); - printf("Process %d\n", rank); + // printf("Process %d\n", rank); free(temp); } MPI_Finalize();