From 189c8cf3d654e1b1eedcfb4ec419aa6384f47a7e Mon Sep 17 00:00:00 2001 From: 13518104 Kevin Austin Stefano <13518104@std.stei.itb.ac.id> Date: Sat, 6 Mar 2021 00:47:39 +0700 Subject: [PATCH] quick sort with openmpi main done --- src/MST_OpenMPI.c | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/MST_OpenMPI.c b/src/MST_OpenMPI.c index 41ffa09..72ce1f9 100644 --- a/src/MST_OpenMPI.c +++ b/src/MST_OpenMPI.c @@ -43,9 +43,9 @@ void makeStruct(MPI_Datatype *mpi_edge_type) //Connect MPI_Type_create_struct(3, block, offset, types, &(*mpi_edge_type)); MPI_Type_commit(&(*mpi_edge_type)); +} -} // Create new Graph based on V vertices and E edges @@ -296,6 +296,38 @@ int compare_src(const void *a, const void *b) return a1->src > b1->src; } + + +void PreQuickSort (Edge result[], int size, int rank) { + if (rank==0) { + //Implementasi quicksort disini + + } else { + MPI_Datatype mpi_edge_type; + makeStruct(&mpi_edge_type); + + int idxcnt = 0; + Edge arr; + MPI_Status status; + while (rank >= pow(2, idxcnt)) { + idxcnt = idxcnt+1; + } + + int source = MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status); + source = MPI_Get_count(&status, mpi_edge_type, &arr); + int src = status.MPI_SOURCE; + + temp = (Edge *) malloc (sizeof(Edge) *arr); + source = MPI_Recv(temp, arr, mpi_edge_type, src, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + //Impementasiquicksort disini + source = MPI_Send(temp, arr, mpi_adge_type, src, 1, MPI_COMM_WORLD); + free(arr); + } + +} + + + // Minimum Spanning Tree using Kruskal's Algorithm void KruskalMST(Graph *graph, Edge result[], int *e, int size, int rank) { @@ -304,8 +336,10 @@ void KruskalMST(Graph *graph, Edge result[], int *e, int size, int rank) // Step 1: Sort all the edges into correspendent sorted edges // bubbleSort(graph->edge, graph->E, 1); - QuickSortWeight(graph->edge, 0, graph->E, size, rank); - + // QuickSortWeight(graph->edge, 0, graph->E, size, rank); + + + // Step 2: Allocate memory for creating V subsets Subset *subsets = CreateSubset(V); @@ -322,7 +356,7 @@ void KruskalMST(Graph *graph, Edge result[], int *e, int size, int rank) } } - QuickSortSrc(graph->edge, 0, graph->E, size, rank); + // QuickSortSrc(graph->edge, 0, graph->E, size, rank); return; } -- GitLab