diff --git a/insertion_sort.c b/insertion_sort.c index 42d867717853c978fe58487e2e9ebe415a834f64..d88047e3595be648abd27bb34b6b9c32bd1db853 100644 --- a/insertion_sort.c +++ b/insertion_sort.c @@ -2,20 +2,12 @@ /* insertion sort ascending order */ #include <stdio.h> - -int main() +#include "mpi.h" +#include <stdlib.h> + +void insertionSort(int n, int* array) { - int n, array[1000], c, d, t; - - printf("Enter number of elements\n"); - scanf("%d", &n); - - printf("Enter %d integers\n", n); - - for (c = 0; c < n; c++) { - scanf("%d", &array[c]); - } - + int d,t,c; for (c = 1 ; c <= n - 1; c++) { d = c; @@ -27,12 +19,60 @@ int main() d--; } } +} + +int max(int *array, int size) { + int max = array[0]; + int i; + for(i=1; i<size; i++) { + if(array[i]>max) max = array[i]; + } + return max; + +} + +int min(int *array, int size) { + int min = array[0]; + int i; + for(i=1; i<size; i++) { + if(array[i]<min) min = array[i]; + } + return min; +} + + +int main() { + + /*MPI_Init(NULL,NULL); + int rank; + int size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + double time_bucket= 0.0; + double time_insert= 0.0;*/ + + int n, c, d, t; + printf("Enter number of elements\n"); + scanf("%d", &n); - printf("Sorted list in ascending order:\n"); + printf("Enter %d integers\n", n); + int *array = (int*)malloc(sizeof(int)*n); + + for (c = 0; c < n; c++) { + scanf("%d", &array[c]); + } + + //float div = (max(array, n) - min(array, n)/size); + //printf("%f", div); + + insertionSort(n, array); + printf("Sorted list in ascending order:\n"); + for (c = 0; c <= n - 1; c++) { printf("%d\n", array[c]); - } - - return 0; -} \ No newline at end of file + } + +} + diff --git a/mpi_hostfile b/mpi_hostfile new file mode 100644 index 0000000000000000000000000000000000000000..1aab781c29869ebddbe342b46de587fe30d3c24d --- /dev/null +++ b/mpi_hostfile @@ -0,0 +1,7 @@ +#daftar host +localhost +167.205.35.26 +167.205.35.28 +167.205.35.29 +167.205.35.30 +167.205.35.31 diff --git a/sort b/sort new file mode 100755 index 0000000000000000000000000000000000000000..c00e66efe1d5f0bb1e95f15e87054528026b118a Binary files /dev/null and b/sort differ