Skip to content
Snippets Groups Projects
Commit 1468f7f4 authored by Yasya Rusyda's avatar Yasya Rusyda
Browse files

add parallel

parent 5629e0bf
No related merge requests found
No preview for this file type
......@@ -47,16 +47,31 @@ void countSort(int arr[], int n, int exp)
// The main function to that sorts arr[] of size n using
// Radix Sort
void radixsort(int arr[], int n)
void radixsort(int *arr, int n)
{
int *d_arr;
// 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
// allocate device memory
cudaMalloc((void**)&d_arr,sizeof(int)*n);
cudaMemcpy(d_arr, arr, sizeof(int)*n,cudaMemcpyHostToDevie);
for (int exp = 1; m/exp > 0; exp *= 10)
countSort<<1,32>>(arr, n, exp);
countSort<<<1,32>>>(d_arr, n, exp);
//transfer data back to host memory
cudaMemcpy(arr, d_arr, sizeof(int)*n, cudaMemcpyDeviceToHost);
//deallocate device memory
cudaFree(d_arr);
}
// A utility function to print an array
......@@ -89,13 +104,12 @@ timespec diff(timespec start, timespec end)
}
// Driver program to test above functions
int main()
int main(int argc, char *argv[])
{
timespec start, stop;
int n;
cout<<"Masukkan nilai N\n";
cin>>n;
n= atoi(argv[1]);
int arr[n];
rng(arr,n);
clock_gettime(CLOCK_REALTIME, &start);
......@@ -107,5 +121,7 @@ int main()
long time = duration.tv_sec * 1000000 + duration.tv_nsec/1000;
printf("\n%d.%09d s\n", duration.tv_sec, duration.tv_nsec);
//deallocate host memory
free(arr);
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