From 89447a90ae77a7a68ef3dc5a76fbabb79e770cf0 Mon Sep 17 00:00:00 2001 From: 13513031 <13513031@ld5-01.if.itb.ac.id> Date: Fri, 12 Feb 2016 12:42:45 +0700 Subject: [PATCH] Add mpi_hostfile and bucketsort.c still buggy --- bucketsort.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ mpi_hostfile | 8 ++++++ 2 files changed, 80 insertions(+) create mode 100644 bucketsort.c create mode 100644 mpi_hostfile diff --git a/bucketsort.c b/bucketsort.c new file mode 100644 index 0000000..467e610 --- /dev/null +++ b/bucketsort.c @@ -0,0 +1,72 @@ +#include "mpi.h" +#include <stdio.h> + +void insertionSort(int array[]) { + int c, d, t; + + for (c = 1 ; c <= n - 1; c++) { + d = c; + + while ( d > 0 && array[d] < array[d-1]) { + t = array[d]; + array[d] = array[d-1]; + array[d-1] = t; + + d--; + } + } + + printf("Sorted list in ascending order:\n"); + + for (c = 0; c <= n - 1; c++) { + printf("%d\n", array[c]); + } + +} + + + +int main(int argc, char *argv[]) { + long int *bigarray; + long int *local_array; + int n; + int n_bar; + long int number; + int p; + int my_rank; + int i; + double start, stop; + + MPI_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &p); + MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); + + if(my_rank == 0) { + n = atoi(argv[1]); + + + start = MPI_Wtime(); + + bigarray = malloc(n*sizeof(long int)); + MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD); + n_bar = n/p; + + local_array = malloc(n_bar*sizeof(long int)); + + Put_numbers_in_bucket(bigarray,local_array, n, n_bar, p, my_rank); + Sequential_sort(local_array, n_bar); + MPI_Gather(local_array, n_bar, MPI_LONG, bigarray, n_bar, MPI_LONG, 0, MPI_COMM_WORLD); + stop = MPI_Wtime(); + + if(my_rank == 0) { + printf("\nTime to sort using %d processes = %lf msecs\n", p, (stop - start)/0.001); + } + + free(local_array); + if(my_rank == 0) { + free(big_array); + } + MPI_Finalize(); +} + + diff --git a/mpi_hostfile b/mpi_hostfile new file mode 100644 index 0000000..b6f0ed5 --- /dev/null +++ b/mpi_hostfile @@ -0,0 +1,8 @@ +#daftar host +#localhost +167.205.35.25 +167.205.35.28 +167.205.35.29 +167.205.35.30 +167.205.35.31 + -- GitLab