diff --git a/a b/a deleted file mode 100755 index 051132f2e423803a08736493c09679c59d6ef85e..0000000000000000000000000000000000000000 Binary files a/a and /dev/null differ diff --git a/bucket.c b/bucket.c deleted file mode 100644 index e5448eba86dacfe67bfe490fe046af54fbce42b0..0000000000000000000000000000000000000000 --- a/bucket.c +++ /dev/null @@ -1,162 +0,0 @@ -/* Copyrights http://www.programmingsimplified.com/c/source-code/c-program-insertion-sort */ -/* insertion sort ascending order */ - -#include <stdio.h> -// Copyright 2012 www.mpitutorial.com - -// Program yang menghitung rataÂrata dari array secara paralel menggunakan Scatter dan Gather. -#include <stdio.h> -#include <stdlib.h> -#include <time.h> -#include <mpi.h> -#include <assert.h> - -float *create_rand_nums(int num_elements) { - float *rand_nums = (float *)malloc(sizeof(float) * num_elements); - assert(rand_nums != NULL); - int i; - for (i = 0; i < num_elements; i++) { - rand_nums[i] = (rand() / (float)RAND_MAX); - } - return rand_nums; -} - -float compute_avg(float *array, int num_elements) { - float sum = 0.f; - int i; - for (i = 0; i < num_elements; i++) { - sum += array[i]; - } - return sum / num_elements; -} - -int* bucketSort(int array[], int n, int argc) { - int i, j; - int data[1000][1000]; - int size[1000]; - for (i=0;i<n;i++) { - size[i] = 0; - } - for (i=0;i<n;i++) { - if (array[i] < 10) - data[0][size[i]] = array[i]; - size[i]++; - } - - MPI_Init(NULL, NULL); - - int world_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); - int world_size; - MPI_Comm_size(MPI_COMM_WORLD, &world_size); - - MPI_Scatter(data, num_elements_per_proc, MPI_FLOAT, sub_rand_nums, - num_elements_per_proc, MPI_FLOAT, 0, MPI_COMM_WORLD); - - MPI_Gather(&sub_avg, 1, MPI_FLOAT, sub_avgs, 1, MPI_FLOAT, 0, - MPI_COMM_WORLD); - - if (world_rank == 0) { - float avg = compute_avg(sub_avgs, world_size); - printf("Avg of all elements is %f\n", avg); - } - - if (world_rank == 0) { - free(rand_nums); - free(sub_avgs); - } - free(sub_rand_nums); - - MPI_Barrier(MPI_COMM_WORLD); - MPI_Finalize(); - - - int num_elements_per_proc = atoi(argv[1]); - srand(time(NULL)); - - MPI_Init(NULL, NULL); - - int world_rank; - MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); - int world_size; - MPI_Comm_size(MPI_COMM_WORLD, &world_size); - - float *rand_nums = NULL; - if (world_rank == 0) { - rand_nums = create_rand_nums(num_elements_per_proc * world_size); - } - - float *sub_rand_nums = (float *)malloc(sizeof(float) * - num_elements_per_proc); - assert(sub_rand_nums != NULL); - - MPI_Scatter(rand_nums, num_elements_per_proc, MPI_FLOAT, sub_rand_nums, - num_elements_per_proc, MPI_FLOAT, 0, MPI_COMM_WORLD); - - float sub_avg = compute_avg(sub_rand_nums, num_elements_per_proc); - - float *sub_avgs = NULL; - if (world_rank == 0) { - sub_avgs = (float *)malloc(sizeof(float) * world_size); - assert(sub_avgs != NULL); - } - MPI_Gather(&sub_avg, 1, MPI_FLOAT, sub_avgs, 1, MPI_FLOAT, 0, - MPI_COMM_WORLD); - - if (world_rank == 0) { - float avg = compute_avg(sub_avgs, world_size); - printf("Avg of all elements is %f\n", avg); - } - - if (world_rank == 0) { - free(rand_nums); - free(sub_avgs); - } - free(sub_rand_nums); - - MPI_Barrier(MPI_COMM_WORLD); - MPI_Finalize(); -} - - -int main(int argc, char** argv) -{ - - int n, array[1000], c, d, t; - int array1[1000]; - - if (argc != 2) { - fprintf(stderr, "Usage: avg num_elements_per_proc\n"); - exit(1); - } - - 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]); - } - array1 = bucketSort(array[1000], n, argc); - /* - 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", array1[c]); - } - - return 0; -} diff --git a/insertion_sort.c b/insertion_sort.c deleted file mode 100644 index 42d867717853c978fe58487e2e9ebe415a834f64..0000000000000000000000000000000000000000 --- a/insertion_sort.c +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyrights http://www.programmingsimplified.com/c/source-code/c-program-insertion-sort */ -/* insertion sort ascending order */ - -#include <stdio.h> - -int main() -{ - 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]); - } - - 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]); - } - - return 0; -} \ No newline at end of file diff --git a/laporan.txt b/laporan.txt new file mode 100644 index 0000000000000000000000000000000000000000..39a8a8d35af1e41eae9c6a726dabf10274e9b296 --- /dev/null +++ b/laporan.txt @@ -0,0 +1,50 @@ +N = Element array +M = Banyak proses + +1) N = 50.000 +______________________ +| M | Waktu (seconds)| +|____|________________| +| 1 | 6.856739 | +| 4 | 0.672057 | +| 8 | 0.185040 | +| 16 | 0.391889 | +| 32 | 0.390784 | +|____|________________| + + +2) N = 100.000 +______________________ +| M | Waktu (seconds)| +|____|________________| +| 1 | 14.909016 | +| 4 | 2.744831 | +| 8 | 0.440783 | +| 16 | 0.294712 | +| 32 | 0.686711 | +|____|________________| + + +3) N = 200.000 +______________________ +| M | Waktu (seconds)| +|____|________________| +| 1 | 54.440212 | +| 4 | 6.701494 | +| 8 | 1.613141 | +| 16 | 0.631648 | +| 32 | 2.975302 | +|____|________________| + + +4) N = 400.000 +______________________ +| M | Waktu (seconds)| +|____|________________| +| 1 | 219.474459 | +| 4 | 25.008242 | +| 8 | 7.521053 | +| 16 | 3.224539 | +| 32 | 3.344244 | +|____|________________| + diff --git a/scattergather.c b/scattergather.c deleted file mode 100644 index 533d2215b819def46e7aa666b2531f42e1dfd7ae..0000000000000000000000000000000000000000 --- a/scattergather.c +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2012 www.mpitutorial.com - -#include <stdio.h> -#include <stdlib.h> -#include <time.h> -#include <mpi.h> -#include <assert.h> - -float *create_rand_nums(int num_elements) { -float *rand_nums = (float *)malloc(sizeof(float) * num_elements); -assert(rand_nums != NULL); -int i; -for (i = 0; i < num_elements; i++) { -rand_nums[i] = (rand() / (float)RAND_MAX); -} -return rand_nums; -} - -float compute_avg(float *array, int num_elements) { -float sum = 0.f; -int i; -for (i = 0; i < num_elements; i++) { -sum += array[i]; -} -return sum / num_elements; -} - -int main(int argc, char** argv) { -if (argc != 2) { -fprintf(stderr, "Usage: avg num_elements_per_proc\n"); -exit(1); -} - -int num_elements_per_proc = atoi(argv[1]); -srand(time(NULL)); - -MPI_Init(NULL, NULL); - -int world_rank; -MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); -int world_size; -MPI_Comm_size(MPI_COMM_WORLD, &world_size); - -float *rand_nums = NULL; -if (world_rank == 0) { -rand_nums = create_rand_nums(num_elements_per_proc * world_size); -} - -float *sub_rand_nums = (float *)malloc(sizeof(float) * -num_elements_per_proc); -assert(sub_rand_nums != NULL); - -MPI_Scatter(rand_nums, num_elements_per_proc, MPI_FLOAT, sub_rand_nums, -num_elements_per_proc, MPI_FLOAT, 0, MPI_COMM_WORLD); - -float sub_avg = compute_avg(sub_rand_nums, num_elements_per_proc); - -float *sub_avgs = NULL; -if (world_rank == 0) { -sub_avgs = (float *)malloc(sizeof(float) * world_size); -assert(sub_avgs != NULL); -} -MPI_Gather(&sub_avg, 1, MPI_FLOAT, sub_avgs, 1, MPI_FLOAT, 0, -MPI_COMM_WORLD); - -if (world_rank == 0) { -float avg = compute_avg(sub_avgs, world_size); -printf("Avg of all elements is %f\n", avg); -} - -if (world_rank == 0) { -free(rand_nums); -free(sub_avgs); -} -free(sub_rand_nums); - -MPI_Barrier(MPI_COMM_WORLD); -MPI_Finalize(); -} -