Skip to content
Snippets Groups Projects
Commit e3483f9a authored by jasonwiguna's avatar jasonwiguna
Browse files

add makefile and readme

parent e79f852c
Branches
No related merge requests found
Pipeline #12337 canceled with stages
README.md 0 → 100644
# PARALLEL OPEN MPI
##### Jason Wiguna / 13516024
##### Eric Jonathan / 13516117
## Cara menjalankan program
## Untuk radix cuda
make radix
./<executable-name> <array-size>
./radix 5000
## Untuk radix serial
make serial_radix
./<executable-name> <array-size>
./radix 5000
## Pendahuluan
> Radix Sort adalah metode/algoritma pengurutan dengan cara Non-Camparation (pengurutan tanpa perbandingan). Prosesnya dengan cara melakukan perhitungan count jumlah digit terhadap suatu digit dari least significant digit ke most significant digit.
> Secara harfiah Radix dapat diartikan sebagai posisi dalam angka, karena cara ini pertama kalinya mengurutkan nilai-nilai yang dimasukan (input) berdasarkan radix pertamanya, lalu pengurutan dilakukan berdasarkan radix keduanya, dan begitu seterusnya. Pada sistem desimal, radix adalah digit dalam angka desimal. Kelebihan yang dimiliki Radix Sort antara lain adalah merupakan algoritma pengurutan yang cepat, mudah, dan sangat efektif. Namun penggunaannya terbatas pada kasus-kasus tertentu dan memerlukan memori tambahan dalam prosesnya.
## Deskripsi Solusi
> Parallel Radix Sort diimplementasikan dengan Cuda.
Langkah-langkah algoritma Radix Sort:
1. Untuk setiap elemen pada array, kita mulai dengan membandingkan digit ke i dimulai dari Least Significant Digit (LSD) hingga Most Significant Digit (MSD)
2. Urutkan setiap elemen array dengan counting sort dengan mengacu pada digit ke i
3. Pada counting sort, penentuan digit yang sedang diamati diparalelkan
3. Lanjutkan untuk digit i+1 sampai MSD
### Hasil pengukuran kinerja
##### Serial Radix Sort:
N = 5000
- 509.822 ms
- 468.84 ms
- 494.61 ms
N = 50000
- 1708.74 ms
- 2475.64 ms
- 2425.741 ms
N = 100000
- 3013.129 ms
- 2960.172 ms
- 3004.044 ms
N = 200000
- 5808.667 ms
- 4967.901 ms
- 5794.948 ms
N = 400000
- 11725.552 ms
- 11623.837 ms
- 11588.134 ms
##### Parallel Radix Sort
N = 5000
- 4027.95 ms
- 4201.77 ms
- 3960.7 ms
N = 50000
- 37660.1 ms
- 37788.6 ms
- 26199.7 ms
N = 100000
- 68535.9 ms
- 52493.6 ms
- 74647 ms
N = 200000
- 123225 ms
- 130053 ms
- 103735 ms
N = 400000
- 224817 ms
- 541991 ms
- 281540 ms
### Analisis Hasil
>Pada algoritma Radix Sort, dapat diimplementasikan secara serial maupun parallel.
Dari hasil pengukuran kinerja yang sudah dilakukan dapat disimpulkan bahwa pemilihan solusi secara serial atau paralel memiliki kelebihan dan kekurangannya masing-masing.
>Berdasarkan hasil percobaan dapat dilihat bahwa algoritma serial menghasilkan hasil yang lebih cepat dibanding paralel. Hal ini mungkin terjadi karena kesalahan optimasi bagian yang seharusnya diparalelkan oleh penulis karena komunikasi antar proses yang cukup menyita waktu. Seharusnya ketika ruang persoalan diperbesar, kinerja paralel menjadi semakin baik. Hal ini juga mungkin terjadi karena kesalahan penggunaan jumlah thread yang dilakukan.
## Jumlah Thread
> Pada pengetesan penulis menggunakan thread berjumlah 1.
### Pembagian Kerja
Jason Wiguna - 13516024
- Counting Sort logic
- Parallel set up
- Radix Sort Logic
Eric Jonathan - 13516117
- Radix Sort logic
- Makefile
- Testing
- Readme
makefile 0 → 100644
CC = nvcc
CC2 = gcc
FILENAME = radix.cu
FILENAME2 = radix_serial.c
EXECUTABLE = radix
radix: radix.cu
$(CC) $(FILENAME) -o $(EXECUTABLE)
serial_radix: radix_serial.c
$(CC2) $(FILENAME2) -o $(EXECUTABLE)
\ No newline at end of file
This diff is collapsed.
radix 0 → 100755
File added
// C++ implementation of Radix Sort
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
// A utility function to get maximum value in arr[]
int getMax(int arr[], int n)
{
int mx = arr[0];
for (int i = 1; i < n; i++)
if (arr[i] > mx)
mx = arr[i];
return mx;
}
// A function to do counting sort of arr[] according to
// the digit represented by exp.
void countSort(int arr[], int n, int exp)
{
int output[n]; // output array
int i, count[10] = {0};
// Store count of occurrences in count[]
for (i = 0; i < n; i++)
count[ (arr[i]/exp)%10 ]++;
// Change count[i] so that count[i] now contains actual
// position of this digit in output[]
for (i = 1; i < 10; i++)
count[i] += count[i - 1];
// Build the output array
for (i = n - 1; i >= 0; i--)
{
output[count[ (arr[i]/exp)%10 ] - 1] = arr[i];
count[ (arr[i]/exp)%10 ]--;
}
// Copy the output array to arr[], so that arr[] now
// contains sorted numbers according to current digit
for (i = 0; i < n; i++)
arr[i] = output[i];
}
// The main function to that sorts arr[] of size n using
// Radix Sort
void radix_sort(int arr[], int n)
{
// Find the maximum number to know number of digits
int m = getMax(arr, n);
// Do counting sort for every digit. Note that instead
// of passing digit number, exp is passed. exp is 10^i
// where i is current digit number
for (int exp = 1; m/exp > 0; exp *= 10)
countSort(arr, n, exp);
}
// A utility function to print an array
// void print(int arr[], int n)
// {
// for (int i = 0; i < n; i++)
// cout << arr[i] << " ";
// }
void rng(int* arr, int n) {
int seed = 13515024; // Ganti dengan NIM anda sebagai seed.
srand(seed);
for(long i = 0; i < n; i++) {
arr[i] = (int)rand();
}
}
// Driver program to test above functions
int main(int argc, char *argv[])
{
int n = strtol(argv[1], NULL, 10);
struct timeval start, end;
long double cpu_time_used = 0.0;
int arr[400000] = {0};
FILE *o_file;
o_file = fopen("output.txt","w");
rng(arr, n);
gettimeofday(&start, NULL);
radix_sort(arr, n);
gettimeofday(&end, NULL);
// for (int i = 0; i < n; i++) {
// printf("%d ", arr[i]);
// }
for (int i = 0; i < n; i++) {
if (i == n-1)
fprintf(o_file,"%d", arr[i]);
else
fprintf(o_file,"%d, ",arr[i]);
}
fclose(o_file);
cpu_time_used = (end.tv_sec - start.tv_sec)*1e6;
cpu_time_used = (long double) (cpu_time_used + (end.tv_usec - start.tv_usec))*1e-6;
cpu_time_used *= 1000;
printf("Time of execution: %Le microseconds\n", cpu_time_used);
return 0;
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment