Skip to content
Snippets Groups Projects
Commit 52996e54 authored by Adin Baskoro's avatar Adin Baskoro
Browse files

time fix

parent f03ca917
No related merge requests found
No preview for this file type
......@@ -56,15 +56,29 @@ int main(int argc, char *argv[]) {
void insertion_sort(int* sorted_array, int size, int element_num)
{
int n, array[size], c, d, t;
int n, c, d, t;
int interval;
int my_rank = omp_get_thread_num();
int thread_count = omp_get_num_threads();
n = thread_count+1;
interval = size;
// if there is remainder of thread then the last thread hold all the element
if ((element_num - thread_count * size) != 0){
if(my_rank == thread_count-1){
// printf("%d\n", my_rank );
size = element_num % thread_count + size;
// printf("%d\n", size);
}
}
int array[size];
for (c = 0; c < size; c++) {
array[c] = rand() % (size) + (my_rank)*size;
// printf("%d ", array[c]);
}
// Sorting
......@@ -80,13 +94,13 @@ void insertion_sort(int* sorted_array, int size, int element_num)
}
}
// printf("Rank : %d\n", my_rank);
// for (c=0;c<size;c++){
// printf("%d",array[c]);
// printf("%d ",array[c]);
//
// }
// printf("\nSize : %d\n", size);
memcpy(sorted_array+(my_rank * size), &array, size*sizeof(int));
memcpy(sorted_array+(my_rank * interval), &array, size*sizeof(int));
}
void bucket_sort(int* sorted_array, int element_num) {
......
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